diff --git a/l10n_it_delivery_note/README.rst b/l10n_it_delivery_note/README.rst index 579c1e87943f..85ffb7ae9416 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:4d827f40aab684341e020ef60c38d39d7d79e99e0bd0a8da9ba844af85654859 + !! source digest: sha256:f9bd2d08712fb141b78c5240867f1c672c3d6f693c345e8b3feabf2d2bcf4ec7 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |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 edf8f0468910..b5feed0ae37c 100644 --- a/l10n_it_delivery_note/__manifest__.py +++ b/l10n_it_delivery_note/__manifest__.py @@ -13,12 +13,12 @@ "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.3", + "version": "14.0.2.6.0", "category": "Localization/Italy", "license": "AGPL-3", "maintainers": ["MarcoCalcagni", "aleuffre", "renda-dev"], "depends": [ - "delivery", + "delivery_carrier_partner", "l10n_it_delivery_note_base", "mail", "sale_stock", @@ -41,10 +41,15 @@ "views/stock_picking.xml", "views/portal_templates.xml", "views/portal_my_delivery_notes.xml", + "wizard/delivery_note_confirm.xml", "wizard/delivery_note_create.xml", "wizard/delivery_note_invoice.xml", "wizard/delivery_note_select.xml", "wizard/delivery_note_template.xml", "wizard/sale_advance_payment_inv.xml", ], + "demo": [ + "demo/res_partner_demo.xml", + "demo/delivery_carrier_demo.xml", + ], } 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..afb84b38eeb2 100644 --- a/l10n_it_delivery_note/cli/migrate_l10n_it_ddt.py +++ b/l10n_it_delivery_note/cli/migrate_l10n_it_ddt.py @@ -288,7 +288,8 @@ def vals_getter(record): "type_id": self._document_types[record.ddt_type_id].id, "date": record.date, "carrier_id": record.carrier_id.id, - "delivery_method_id": record.partner_id.property_delivery_carrier_id.id, + "delivery_method_id": record.picking_ids.mapped("carrier_id")[:1].id + or record.partner_id.property_delivery_carrier_id.id, "transport_datetime": record.date_done, "packages": record.parcels, "volume": record.volume, diff --git a/l10n_it_delivery_note/demo/delivery_carrier_demo.xml b/l10n_it_delivery_note/demo/delivery_carrier_demo.xml new file mode 100644 index 000000000000..32d16e09a36b --- /dev/null +++ b/l10n_it_delivery_note/demo/delivery_carrier_demo.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/l10n_it_delivery_note/demo/res_partner_demo.xml b/l10n_it_delivery_note/demo/res_partner_demo.xml new file mode 100644 index 000000000000..d65375002234 --- /dev/null +++ b/l10n_it_delivery_note/demo/res_partner_demo.xml @@ -0,0 +1,10 @@ + + + + Carrier 1 + + + + Carrier 2 + + 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..a7890e8513bf --- /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): + note_ids = env["stock.delivery.note"].search( + [("carrier_id", "!=", False), ("delivery_method_id", "!=", False)] + ) + + for note_id in note_ids: + note_id.delivery_method_id.write({"partner_id": note_id.carrier_id.id}) 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 d7bd1ca4871c..6375703fce29 100644 --- a/l10n_it_delivery_note/models/stock_delivery_note.py +++ b/l10n_it_delivery_note/models/stock_delivery_note.py @@ -143,7 +143,6 @@ def _domain_weight_uom(self): string="Carrier", states=DONE_READONLY_STATE, tracking=True, - domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", ) delivery_method_id = fields.Many2one( "delivery.carrier", @@ -364,6 +363,10 @@ def _compute_weights(self): def _onchange_picking_ids(self): self._compute_weights() + @api.onchange("delivery_method_id") + def _onchange_delivery_method_id(self): + self.carrier_id = self.delivery_method_id.partner_id + def _inverse_set_pickings(self): for note in self: if note.pickings_picker: @@ -532,7 +535,7 @@ def action_draft(self): self.write({"state": DOMAIN_DELIVERY_NOTE_STATES[0]}) self.line_ids.sync_invoice_status() - def action_confirm(self): + def _action_confirm(self): for note in self: sequence = note.type_id.sequence_id @@ -546,6 +549,41 @@ def action_confirm(self): ).next_by_id() note.sequence_id = sequence + def action_confirm(self): + for note in self: + warning_message = False + carrier_ids = note.mapped("picking_ids.carrier_id") + transporter_ids = carrier_ids.mapped("partner_id") + if len(transporter_ids) > 1: + warning_message = _( + "This delivery note contains pickings related to different transporters. " + "Are you sure you want to proceed? \nTransporters: %(transporters)s", + transporters=", ".join(transporter_ids.mapped("name")), + ) + elif len(carrier_ids) > 1: + warning_message = _( + "This delivery note contains pickings related to different " + "delivery methods from the same transporter. " + "Are you sure you want to proceed? \nDelivery Methods: %(carriers)s", + carriers=", ".join(carrier_ids.mapped("name")), + ) + if warning_message: + return { + "type": "ir.actions.act_window", + "name": _("Warning"), + "res_model": "stock.delivery.note.confirm.wizard", + "view_type": "form", + "target": "new", + "view_mode": "form", + "context": { + "default_delivery_note_id": note.id, + "default_warning_message": warning_message, + **self._context, + }, + } + else: + note._action_confirm() + def _check_delivery_notes_before_invoicing(self): for delivery_note_id in self: if not delivery_note_id.sale_ids: diff --git a/l10n_it_delivery_note/models/stock_picking.py b/l10n_it_delivery_note/models/stock_picking.py index 28b527896e54..bc1fa1ade882 100644 --- a/l10n_it_delivery_note/models/stock_picking.py +++ b/l10n_it_delivery_note/models/stock_picking.py @@ -88,6 +88,8 @@ class StockPicking(models.Model): string="DN Operation Type", related="picking_type_id.code" ) + carrier_partner_id = fields.Many2one("res.partner", related="carrier_id.partner_id") + use_delivery_note = fields.Boolean(compute="_compute_boolean_flags") use_advanced_behaviour = fields.Boolean(compute="_compute_boolean_flags") delivery_note_exists = fields.Boolean(compute="_compute_boolean_flags") @@ -141,6 +143,10 @@ def _compute_boolean_flags(self): ) picking.can_be_invoiced = bool(picking.delivery_note_id.sale_ids) + @api.onchange("delivery_method_id") + def _onchange_delivery_method_id(self): + self.delivery_note_carrier_id = self.delivery_method_id.partner_id + @api.onchange("delivery_note_type_id") def _onchange_delivery_note_type(self): if self.delivery_note_type_id: @@ -336,6 +342,7 @@ def _create_delivery_note(self): ], limit=1, ) + delivery_method_id = self.mapped("carrier_id")[:1] return self.env["stock.delivery.note"].create( { "company_id": self.company_id.id, @@ -346,7 +353,8 @@ def _create_delivery_note(self): "partner_shipping_id": partners[1].id, "type_id": type_id.id, "date": self.date_done, - "delivery_method_id": self.partner_id.property_delivery_carrier_id.id, + "carrier_id": delivery_method_id.partner_id.id, + "delivery_method_id": delivery_method_id.id, "transport_condition_id": ( self.sale_id.default_transport_condition_id.id or partners[1].default_transport_condition_id.id diff --git a/l10n_it_delivery_note/security/ir.model.access.csv b/l10n_it_delivery_note/security/ir.model.access.csv index 725630b093f3..364845cefe86 100644 --- a/l10n_it_delivery_note/security/ir.model.access.csv +++ b/l10n_it_delivery_note/security/ir.model.access.csv @@ -19,7 +19,9 @@ access_stock_delivery_note_line_portal,stock.delivery.note.line.portal,l10n_it_d access_stock_delivery_note_type_user,access_stock_delivery_note_type user,l10n_it_delivery_note_base.model_stock_delivery_note_type,stock.group_stock_user,1,0,0,0 access_stock_delivery_note_type_manager,access_stock_delivery_note_type manager,l10n_it_delivery_note_base.model_stock_delivery_note_type,stock.group_stock_manager,1,1,1,1 access_stock_delivery_note_type_user_account,access_stock_delivery_note_type user_account,l10n_it_delivery_note_base.model_stock_delivery_note_type,account.group_account_invoice,1,0,0,0 +access_stock_delivery_note_confirm_wizard_manager,access_stock_delivery_note_confirm_wizard manager,l10n_it_delivery_note.model_stock_delivery_note_confirm_wizard,,1,1,1,1 access_stock_delivery_note_create_wizard_manager,access_stock_delivery_note_create_wizard manager,l10n_it_delivery_note.model_stock_delivery_note_create_wizard,,1,1,1,1 access_stock_delivery_note_select_wizard_manager,access_stock_delivery_note_select_wizard manager,l10n_it_delivery_note.model_stock_delivery_note_select_wizard,,1,1,1,1 access_stock_delivery_note_base_wizard_manager,access_stock_delivery_note_base_wizard manager,l10n_it_delivery_note.model_stock_delivery_note_base_wizard,,1,1,1,1 access_stock_delivery_note_invoice_wizard_manager,access_stock_delivery_note_invoice_wizard manager,l10n_it_delivery_note.model_stock_delivery_note_invoice_wizard,,1,1,1,1 +access_delivery_carrier_portal,delivery.carrier portal,delivery.model_delivery_carrier,base.group_portal,1,0,0,0 diff --git a/l10n_it_delivery_note/static/description/index.html b/l10n_it_delivery_note/static/description/index.html index f2abb3351dd3..85d7eeb2c822 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:4d827f40aab684341e020ef60c38d39d7d79e99e0bd0a8da9ba844af85654859 +!! source digest: sha256:f9bd2d08712fb141b78c5240867f1c672c3d6f693c345e8b3feabf2d2bcf4ec7 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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 261bbd79927f..cd860186c8d3 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 @@ - + @@ -421,6 +418,8 @@ /> + + diff --git a/l10n_it_delivery_note/views/stock_picking.xml b/l10n_it_delivery_note/views/stock_picking.xml index a1b8432206fc..0c5b47b72f27 100644 --- a/l10n_it_delivery_note/views/stock_picking.xml +++ b/l10n_it_delivery_note/views/stock_picking.xml @@ -204,7 +204,6 @@ + + + diff --git a/l10n_it_delivery_note/wizard/__init__.py b/l10n_it_delivery_note/wizard/__init__.py index 328cc9a9d46b..b42b1dd632a6 100644 --- a/l10n_it_delivery_note/wizard/__init__.py +++ b/l10n_it_delivery_note/wizard/__init__.py @@ -1,4 +1,5 @@ from . import delivery_note_base +from . import delivery_note_confirm from . import delivery_note_create from . import delivery_note_invoice from . import delivery_note_select diff --git a/l10n_it_delivery_note/wizard/delivery_note_base.py b/l10n_it_delivery_note/wizard/delivery_note_base.py index c86064935524..3073bca0e9db 100644 --- a/l10n_it_delivery_note/wizard/delivery_note_base.py +++ b/l10n_it_delivery_note/wizard/delivery_note_base.py @@ -38,6 +38,7 @@ def _domain_type_id(self): ) error_message = fields.Html(compute="_compute_fields") + warning_message = fields.Char("Warning", readonly=True, compute="_compute_fields") def _get_validation_errors(self, pickings): validators = [ @@ -63,6 +64,16 @@ def _get_validation_errors(self, pickings): return errors + def _get_warning_message(self): + """ + This method is used to be inherited and extended + to display whatever message could be used to improve the + user experience when creating a delivery note + + :return: message to be displayed + """ + return False + @api.depends("selected_picking_ids") def _compute_fields(self): try: @@ -84,6 +95,7 @@ def _compute_fields(self): ) else: + self.warning_message = self._get_warning_message() partners = self.selected_picking_ids.get_partners() self.partner_sender_id = partners[0] self.partner_id = partners[1] diff --git a/l10n_it_delivery_note/wizard/delivery_note_confirm.py b/l10n_it_delivery_note/wizard/delivery_note_confirm.py new file mode 100644 index 000000000000..5370b326036d --- /dev/null +++ b/l10n_it_delivery_note/wizard/delivery_note_confirm.py @@ -0,0 +1,17 @@ +# Copyright (c) 2019, Link IT Europe Srl +# @author: Matteo Bilotta + + +from odoo import fields, models + + +class StockDeliveryNoteCreateWizard(models.TransientModel): + _name = "stock.delivery.note.confirm.wizard" + _description = "Delivery Note Confirm" + + delivery_note_id = fields.Many2one("stock.delivery.note", readonly=True) + warning_message = fields.Text("Warning Message", readonly=True) + + def confirm(self): + self.ensure_one() + self.delivery_note_id._action_confirm() diff --git a/l10n_it_delivery_note/wizard/delivery_note_confirm.xml b/l10n_it_delivery_note/wizard/delivery_note_confirm.xml new file mode 100644 index 000000000000..647c867f05c1 --- /dev/null +++ b/l10n_it_delivery_note/wizard/delivery_note_confirm.xml @@ -0,0 +1,21 @@ + + + + stock.delivery.note.confirm.form + stock.delivery.note.confirm.wizard + +
+ +
+
+ +
+
+
diff --git a/l10n_it_delivery_note/wizard/delivery_note_create.py b/l10n_it_delivery_note/wizard/delivery_note_create.py index 27454080199b..ea090098e54f 100644 --- a/l10n_it_delivery_note/wizard/delivery_note_create.py +++ b/l10n_it_delivery_note/wizard/delivery_note_create.py @@ -75,6 +75,7 @@ def _onchange_partner(self): ) def _prepare_delivery_note_vals(self, sale_order_id): + delivery_method_id = self.selected_picking_ids.mapped("carrier_id")[:1] return { "company_id": ( self.selected_picking_ids.mapped("company_id")[:1].id or False @@ -88,7 +89,8 @@ def _prepare_delivery_note_vals(self, sale_order_id): "partner_shipping_id": self.partner_shipping_id.id, "type_id": self.type_id.id, "date": self.date, - "delivery_method_id": self.partner_id.property_delivery_carrier_id.id, + "carrier_id": delivery_method_id.partner_id.id, + "delivery_method_id": delivery_method_id.id, "transport_condition_id": ( sale_order_id and sale_order_id.default_transport_condition_id.id diff --git a/l10n_it_delivery_note/wizard/delivery_note_select.py b/l10n_it_delivery_note/wizard/delivery_note_select.py index f026d9f27746..072503bae6af 100644 --- a/l10n_it_delivery_note/wizard/delivery_note_select.py +++ b/l10n_it_delivery_note/wizard/delivery_note_select.py @@ -1,7 +1,7 @@ # Copyright (c) 2019, Link IT Europe Srl # @author: Matteo Bilotta -from odoo import api, fields, models +from odoo import _, api, fields, models class StockDeliveryNoteSelectWizard(models.TransientModel): @@ -37,6 +37,19 @@ def _compute_fields(self): self.picking_ids += self.selected_picking_ids else: self.picking_ids = self.picking_ids + self.warning_message = self._get_warning_message() + + def _get_warning_message(self): + res = super()._get_warning_message() + carrier_ids = self.picking_ids.mapped("carrier_id") + if len(carrier_ids.mapped("partner_id")) > 1: + res = _( + "The selected pickings have different delivery methods: %(carriers)s", + carriers=", ".join( + '"%s: %s"' % (i.name, i.partner_id.name) for i in carrier_ids + ), + ) + return res def check_compliance(self, pickings): super().check_compliance(pickings) diff --git a/l10n_it_delivery_note/wizard/delivery_note_select.xml b/l10n_it_delivery_note/wizard/delivery_note_select.xml index f14a454dcda0..676448e172ac 100644 --- a/l10n_it_delivery_note/wizard/delivery_note_select.xml +++ b/l10n_it_delivery_note/wizard/delivery_note_select.xml @@ -14,6 +14,14 @@ +