diff --git a/l10n_it_delivery_note/README.rst b/l10n_it_delivery_note/README.rst index f75cc4516d2a..eba6c606e2af 100644 --- a/l10n_it_delivery_note/README.rst +++ b/l10n_it_delivery_note/README.rst @@ -7,7 +7,7 @@ ITA - Documento di trasporto !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:48fb8a0d085dce618e7696ef8bdb30aa56d61f48d3db5f895cf477ddf0d3505c + !! source digest: sha256:03411c18bec6b352c5e29adf11136169bc5b144b8e7e55898358671fb8c9d0cf !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/l10n_it_delivery_note/__manifest__.py b/l10n_it_delivery_note/__manifest__.py index 5aca02197b07..4e2d52e42ad7 100644 --- a/l10n_it_delivery_note/__manifest__.py +++ b/l10n_it_delivery_note/__manifest__.py @@ -13,7 +13,7 @@ "author": "Marco Calcagni, Gianmarco Conte, Link IT Europe Srl, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/l10n-italy", - "version": "14.0.2.5.0", + "version": "14.0.2.6.0", "category": "Localization/Italy", "license": "AGPL-3", "maintainers": ["MarcoCalcagni", "aleuffre", "renda-dev"], diff --git a/l10n_it_delivery_note/cli/migrate_l10n_it_ddt.py b/l10n_it_delivery_note/cli/migrate_l10n_it_ddt.py index 4162a9dec8c8..3d92d978841e 100644 --- a/l10n_it_delivery_note/cli/migrate_l10n_it_ddt.py +++ b/l10n_it_delivery_note/cli/migrate_l10n_it_ddt.py @@ -4,7 +4,7 @@ import logging -from odoo import _ +from odoo import _, fields from odoo.exceptions import UserError, ValidationError from .core import EasyCommand @@ -287,7 +287,7 @@ def vals_getter(record): "partner_shipping_id": record.partner_shipping_id.id, "type_id": self._document_types[record.ddt_type_id].id, "date": record.date, - "carrier_id": record.carrier_id.id, + "carrier_id": fields.first(record.picking_ids).carrier_id.id, "delivery_method_id": record.partner_id.property_delivery_carrier_id.id, "transport_datetime": record.date_done, "packages": record.parcels, diff --git a/l10n_it_delivery_note/migrations/14.0.2.6.0/post-migrate.py b/l10n_it_delivery_note/migrations/14.0.2.6.0/post-migrate.py new file mode 100644 index 000000000000..164a970b9a55 --- /dev/null +++ b/l10n_it_delivery_note/migrations/14.0.2.6.0/post-migrate.py @@ -0,0 +1,11 @@ +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + # Sync every picking's carrier to their delivery_note + picking_ids = env["stock.picking"].search( + [("delivery_note_id", "!=", False), ("carrier_id", "!=", False)] + ) + for picking in picking_ids: + picking.delivery_note_id.carrier_id = picking.carrier_id diff --git a/l10n_it_delivery_note/migrations/14.0.2.6.0/pre-migrate.py b/l10n_it_delivery_note/migrations/14.0.2.6.0/pre-migrate.py new file mode 100644 index 000000000000..f7ea2f69a991 --- /dev/null +++ b/l10n_it_delivery_note/migrations/14.0.2.6.0/pre-migrate.py @@ -0,0 +1,75 @@ +from collections import defaultdict + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + # Get every carrier that was a 'res.partner' and create a 'delivery.carrier' + env.cr.execute( + """SELECT id, carrier_id + FROM stock_delivery_note + WHERE carrier_id IS NOT NULL""" + ) + res = env.cr.dictfetchall() + + # Group by carrier_id to not create duplicates + new_res = defaultdict(list) + for i in res: + new_res[i.get("carrier_id")].append(i.get("id")) + + for (carrier_id, delivery_note_ids) in new_res.items(): + partner_carrier_id = env["res.partner"].browse(carrier_id) + + carrier_product = env["product.product"].create( + { + "name": partner_carrier_id.name, + "type": "service", + "sale_ok": False, + "purchase_ok": False, + "list_price": 0.0, + "invoice_policy": "order", + } + ) + + delivery_carrier_id = env["delivery.carrier"].create( + { + "name": partner_carrier_id.name, + "company_id": partner_carrier_id.company_id.id, + "country_ids": [(4, partner_carrier_id.country_id.id)] + if partner_carrier_id.country_id + else [], + "state_ids": [(4, partner_carrier_id.state_id.id)] + if partner_carrier_id.state_id + else [], + "zip_from": partner_carrier_id.zip, + "zip_to": partner_carrier_id.zip, + "product_id": carrier_product.id, + } + ) + + # If it's only one add a duplicate to + # delivery note ids otherwise it would + # be casted to tuple as '(id,)' and that will raise an error + if len(delivery_note_ids) == 1: + delivery_note_ids.append(delivery_note_ids[0]) + + # Update carrier in 'stock.picking' + openupgrade.logged_query( + env.cr, + """UPDATE stock_picking + SET carrier_id={} + WHERE delivery_note_id IN {}""".format( + delivery_carrier_id.id, tuple(delivery_note_ids) + ), + ) + + # Remove carrier from delivery notes + openupgrade.logged_query( + env.cr, + """UPDATE stock_delivery_note + SET carrier_id=NULL + WHERE id IN {}""".format( + tuple(delivery_note_ids) + ), + ) diff --git a/l10n_it_delivery_note/mixins/picking_checker.py b/l10n_it_delivery_note/mixins/picking_checker.py index 49a6c838aae3..421ce4a8ad11 100644 --- a/l10n_it_delivery_note/mixins/picking_checker.py +++ b/l10n_it_delivery_note/mixins/picking_checker.py @@ -74,6 +74,14 @@ def _check_pickings_partners(self, pickings): _("You need to select pickings with all the same recipient.") ) + @api.model + def _check_pickings_carriers(self, pickings): + carrier_ids = pickings.mapped("carrier_id") + if len(carrier_ids) > 1: + raise ValidationError( + _("You need to select pickings with all the same carriers.") + ) + @api.model def _check_pickings_src_locations(self, pickings): src_locations = pickings.mapped("location_id") @@ -130,5 +138,6 @@ def check_compliance(self, pickings): self._check_pickings_state(pickings) self._check_pickings_types(pickings) self._check_pickings_partners(pickings) + self._check_pickings_carriers(pickings) self._check_pickings_src_locations(pickings) self._check_pickings_dest_locations(pickings) diff --git a/l10n_it_delivery_note/models/res_partner.py b/l10n_it_delivery_note/models/res_partner.py index 31a36e66eaf4..928760d2b8de 100644 --- a/l10n_it_delivery_note/models/res_partner.py +++ b/l10n_it_delivery_note/models/res_partner.py @@ -19,4 +19,3 @@ class ResPartner(models.Model): default_transport_method_id = fields.Many2one( "stock.picking.transport.method", string="Method of transport" ) - is_carrier = fields.Boolean("Is Carrier") diff --git a/l10n_it_delivery_note/models/stock_delivery_note.py b/l10n_it_delivery_note/models/stock_delivery_note.py index b99dccecf0b2..917dc41ce74f 100644 --- a/l10n_it_delivery_note/models/stock_delivery_note.py +++ b/l10n_it_delivery_note/models/stock_delivery_note.py @@ -139,7 +139,7 @@ def _domain_weight_uom(self): ) carrier_id = fields.Many2one( - "res.partner", + "delivery.carrier", string="Carrier", states=DONE_READONLY_STATE, tracking=True, diff --git a/l10n_it_delivery_note/models/stock_picking.py b/l10n_it_delivery_note/models/stock_picking.py index 28b527896e54..953b43987e26 100644 --- a/l10n_it_delivery_note/models/stock_picking.py +++ b/l10n_it_delivery_note/models/stock_picking.py @@ -34,7 +34,7 @@ class StockPicking(models.Model): ) delivery_note_carrier_id = fields.Many2one( - "res.partner", string="DN Carrier", related="delivery_note_id.carrier_id" + "delivery.carrier", string="DN Carrier", related="delivery_note_id.carrier_id" ) delivery_method_id = fields.Many2one( "delivery.carrier", related="delivery_note_id.delivery_method_id" @@ -346,6 +346,7 @@ def _create_delivery_note(self): "partner_shipping_id": partners[1].id, "type_id": type_id.id, "date": self.date_done, + "carrier_id": self.carrier_id.id, "delivery_method_id": self.partner_id.property_delivery_carrier_id.id, "transport_condition_id": ( self.sale_id.default_transport_condition_id.id diff --git a/l10n_it_delivery_note/static/description/index.html b/l10n_it_delivery_note/static/description/index.html index 21b5b801a86f..c7a1e3392965 100644 --- a/l10n_it_delivery_note/static/description/index.html +++ b/l10n_it_delivery_note/static/description/index.html @@ -1,3 +1,4 @@ + @@ -366,7 +367,7 @@

ITA - Documento di trasporto

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:48fb8a0d085dce618e7696ef8bdb30aa56d61f48d3db5f895cf477ddf0d3505c +!! source digest: sha256:03411c18bec6b352c5e29adf11136169bc5b144b8e7e55898358671fb8c9d0cf !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/l10n-italy Translate me on Weblate Try me on Runboat

English

diff --git a/l10n_it_delivery_note/views/res_partner.xml b/l10n_it_delivery_note/views/res_partner.xml index 965c49b0a1ed..186739fe4475 100644 --- a/l10n_it_delivery_note/views/res_partner.xml +++ b/l10n_it_delivery_note/views/res_partner.xml @@ -12,7 +12,6 @@ - diff --git a/l10n_it_delivery_note/views/stock_delivery_note.xml b/l10n_it_delivery_note/views/stock_delivery_note.xml index af27e90b7318..021173ba4deb 100644 --- a/l10n_it_delivery_note/views/stock_delivery_note.xml +++ b/l10n_it_delivery_note/views/stock_delivery_note.xml @@ -156,10 +156,7 @@ - + diff --git a/l10n_it_delivery_note/views/stock_picking.xml b/l10n_it_delivery_note/views/stock_picking.xml index a1b8432206fc..ad6352b512be 100644 --- a/l10n_it_delivery_note/views/stock_picking.xml +++ b/l10n_it_delivery_note/views/stock_picking.xml @@ -204,7 +204,6 @@