From 414f5abb16a82579ded2ffb035262c82143a7be0 Mon Sep 17 00:00:00 2001 From: sergiocorato Date: Fri, 29 Apr 2022 12:07:02 +0200 Subject: [PATCH] [14.0][FIX] l10n_it_delivery_note shipping address --- l10n_it_delivery_note/README.rst | 3 +- l10n_it_delivery_note/models/stock_picking.py | 16 +++- l10n_it_delivery_note/readme/CONTRIBUTORS.rst | 1 + .../static/description/index.html | 4 +- .../tests/test_stock_delivery_note.py | 90 +++++++++++++++++++ .../wizard/delivery_note_base.py | 8 +- .../wizard/delivery_note_create.py | 14 +-- 7 files changed, 121 insertions(+), 15 deletions(-) diff --git a/l10n_it_delivery_note/README.rst b/l10n_it_delivery_note/README.rst index 76feb1832966..1faec9726881 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:33dc771dcf0ef741591ab0dd1d1d7a84f0a056b2b015567552a1d41b42767429 + !! source digest: sha256:9dd153180635bb1f0eb35f9412390b0da595cfb81cf9d3a26bf65f80244c7318 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -202,6 +202,7 @@ Contributors * `PyTech-SRL `_: * Alessandro Uffreduzzi * Sebastiano Picchi +* Sergio Corato Maintainers ~~~~~~~~~~~ diff --git a/l10n_it_delivery_note/models/stock_picking.py b/l10n_it_delivery_note/models/stock_picking.py index f73f07b220ce..f26afc21f726 100644 --- a/l10n_it_delivery_note/models/stock_picking.py +++ b/l10n_it_delivery_note/models/stock_picking.py @@ -351,9 +351,7 @@ def _create_delivery_note(self): { "company_id": self.company_id.id, "partner_sender_id": partners[0].id, - "partner_id": self.sale_id.partner_id.id - if self.sale_id - else partners[0].id, + "partner_id": partners[2].id if self.sale_id else partners[0].id, "partner_shipping_id": partners[1].id, "type_id": type_id.id, "date": self.date_done, @@ -411,7 +409,17 @@ def _get_partners(self): else partner_id ) - return (src_partner_id, dest_partner_id) + if self.mapped("sale_id"): + partner_ids = self.mapped("sale_id.partner_invoice_id") + if len(partner_ids) > 1: + raise ValueError( + "Multiple partner found for sale order linked to pickings!" + ) + partner_id = partner_ids[0] + else: + partner_id = dest_partner_id.commercial_partner_id + + return (src_partner_id, dest_partner_id, partner_id) def get_partners(self): self._check_delivery_note_consistency() diff --git a/l10n_it_delivery_note/readme/CONTRIBUTORS.rst b/l10n_it_delivery_note/readme/CONTRIBUTORS.rst index 6447f31e0d37..375f4b367a22 100644 --- a/l10n_it_delivery_note/readme/CONTRIBUTORS.rst +++ b/l10n_it_delivery_note/readme/CONTRIBUTORS.rst @@ -14,3 +14,4 @@ * `PyTech-SRL `_: * Alessandro Uffreduzzi * Sebastiano Picchi +* Sergio Corato diff --git a/l10n_it_delivery_note/static/description/index.html b/l10n_it_delivery_note/static/description/index.html index b6248aaaf4c4..932f290a065f 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:33dc771dcf0ef741591ab0dd1d1d7a84f0a056b2b015567552a1d41b42767429 +!! source digest: sha256:9dd153180635bb1f0eb35f9412390b0da595cfb81cf9d3a26bf65f80244c7318 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

English

@@ -539,6 +540,7 @@

Contributors

+
  • Sergio Corato <https://github.com/sergiocorato>
  • diff --git a/l10n_it_delivery_note/tests/test_stock_delivery_note.py b/l10n_it_delivery_note/tests/test_stock_delivery_note.py index 5caa5ee19bad..58d965e3c6ad 100644 --- a/l10n_it_delivery_note/tests/test_stock_delivery_note.py +++ b/l10n_it_delivery_note/tests/test_stock_delivery_note.py @@ -220,3 +220,93 @@ def test_delivery_action_confirm_without_ref(self): delivery_note_id.partner_ref = "Reference #1234" delivery_note_id.action_confirm() + + def test_partner_shipping_delivering_single_so(self): + # ⇒ "Ordine singolo: consegna a indirizzo diverso" + self._test_partners() + # ⇒ "Ordine singolo: consegna a indirizzo di consegna e fatturazione diversi" + self._test_partners(test_invoice_partner=True) + + def _test_partners(self, test_invoice_partner=False): + user = new_test_user( + self.env, + login=f"test_{'invoice' if test_invoice_partner else 'shipping'}", + groups="stock.group_stock_manager," + "l10n_it_delivery_note.use_advanced_delivery_notes", + ) + self.env.user = user + partner_shipping = self.create_partner( + "Shipping Address Mario Rossi", user.company_id + ) + partner_shipping.write( + { + "parent_id": self.recipient.id, + "type": "delivery", + } + ) + partner_invoicing = self.create_partner("Invoicing Address", user.company_id) + StockPicking = self.env["stock.picking"] + sales_order = self.create_sales_order( + [ + self.large_desk_line, # 1 + self.desk_combination_line, # 1 + ], + ) + if test_invoice_partner: + sales_order.write( + { + "partner_invoice_id": partner_invoicing.id, + } + ) + self.assertEqual(len(sales_order.order_line), 2) + sales_order.action_confirm() + self.assertEqual(len(sales_order.picking_ids), 1) + picking = sales_order.picking_ids + self.assertEqual(len(picking.move_lines), 2) + + # deliver only the first product + picking.move_lines[0].quantity_done = 1 + res_dict = picking.button_validate() + wizard = Form( + self.env[(res_dict.get("res_model"))] + .with_user(user) + .with_context(res_dict["context"]) + ).save() + wizard.process() + res_dict = picking.action_delivery_note_create() + wizard = Form( + self.env[(res_dict.get("res_model"))] + .with_user(user) + .with_context(res_dict["context"]) + ).save() + wizard.confirm() + self.assertTrue(picking.delivery_note_id) + if test_invoice_partner: + self.assertEqual(picking.delivery_note_id.partner_id, partner_invoicing) + else: + self.assertEqual(picking.delivery_note_id.partner_id, self.recipient) + self.assertEqual(picking.delivery_note_id.partner_shipping_id, partner_shipping) + picking_backorder = StockPicking.search([("backorder_id", "=", picking.id)]) + self.assertEqual(len(picking_backorder.move_lines), 1) + picking_backorder.move_lines[0].quantity_done = 1 + picking_backorder.button_validate() + res_dict = picking_backorder.action_delivery_note_create() + wizard = Form( + self.env[(res_dict.get("res_model"))] + .with_user(user) + .with_context(res_dict["context"]) + ).save() + wizard.confirm() + self.assertTrue(picking_backorder.delivery_note_id) + if test_invoice_partner: + self.assertEqual( + picking_backorder.delivery_note_id.partner_id, partner_invoicing + ) + else: + self.assertEqual( + picking_backorder.delivery_note_id.partner_id, self.recipient + ) + self.assertEqual( + picking_backorder.delivery_note_id.partner_shipping_id, + partner_shipping, + ) diff --git a/l10n_it_delivery_note/wizard/delivery_note_base.py b/l10n_it_delivery_note/wizard/delivery_note_base.py index 3073bca0e9db..ae6ed20aa5a9 100644 --- a/l10n_it_delivery_note/wizard/delivery_note_base.py +++ b/l10n_it_delivery_note/wizard/delivery_note_base.py @@ -28,7 +28,9 @@ def _domain_type_id(self): partner_id = fields.Many2one( "res.partner", string="Recipient", compute="_compute_fields" ) - partner_shipping_id = fields.Many2one("res.partner", string="Shipping address") + partner_shipping_id = fields.Many2one( + "res.partner", string="Shipping address", compute="_compute_fields" + ) date = fields.Date(string="Date") type_id = fields.Many2one( @@ -80,6 +82,7 @@ def _compute_fields(self): self.error_message = False self.partner_sender_id = False self.partner_id = False + self.partner_shipping_id = False self.check_compliance(self.selected_picking_ids) except ValidationError: @@ -98,7 +101,8 @@ def _compute_fields(self): 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] + self.partner_shipping_id = partners[1] + self.partner_id = partners[2] def confirm(self): raise NotImplementedError( diff --git a/l10n_it_delivery_note/wizard/delivery_note_create.py b/l10n_it_delivery_note/wizard/delivery_note_create.py index ea090098e54f..4afb99abef1e 100644 --- a/l10n_it_delivery_note/wizard/delivery_note_create.py +++ b/l10n_it_delivery_note/wizard/delivery_note_create.py @@ -31,8 +31,6 @@ def _default_type(self): [("code", "=", "outgoing")], limit=1 ) - partner_shipping_id = fields.Many2one("res.partner", required=True) - date = fields.Date(default=_default_date) type_id = fields.Many2one( "stock.delivery.note.type", default=_default_type, required=True @@ -67,9 +65,11 @@ def _onchange_partner(self): self.check_compliance(self.selected_picking_ids) self.update( { - "partner_shipping_id": self.partner_id, - "partner_id": self.selected_picking_ids.mapped("sale_id.partner_id") - if self.selected_picking_ids.mapped("sale_id.partner_id") + "partner_shipping_id": self.partner_shipping_id, + "partner_id": self.selected_picking_ids.mapped( + "sale_id.partner_invoice_id" + ) + if self.selected_picking_ids.mapped("sale_id.partner_invoice_id") else self.partner_id, } ) @@ -82,8 +82,8 @@ def _prepare_delivery_note_vals(self, sale_order_id): ), "partner_sender_id": self.partner_sender_id.id, "partner_id": ( - self.selected_picking_ids.mapped("sale_id.partner_id").id - if self.selected_picking_ids.mapped("sale_id.partner_id").id + sale_order_id.partner_invoice_id.id + if sale_order_id.partner_invoice_id else self.partner_id.id ), "partner_shipping_id": self.partner_shipping_id.id,