From b61fccd63d17324f06ac005756446c0307ad054d 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 | 52 +++++++++++++++++++ .../wizard/delivery_note_base.py | 8 ++- .../wizard/delivery_note_create.py | 14 ++--- 7 files changed, 83 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..cf8645908815 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.commercial_partner_id + 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..cd508669a127 100644 --- a/l10n_it_delivery_note/tests/test_stock_delivery_note.py +++ b/l10n_it_delivery_note/tests/test_stock_delivery_note.py @@ -9,6 +9,15 @@ class StockDeliveryNote(StockDeliveryNoteCommon): + def setUp(self): + super().setUp() + self.partner_shipping = self.create_partner("Shipping Address") + self.partner_shipping.write( + { + "parent_id": self.recipient.id, + "type": "delivery", + } + ) # ⇒ "Ordine singolo: consegna parziale" def test_partial_delivering_single_so(self): @@ -220,3 +229,46 @@ def test_delivery_action_confirm_without_ref(self): delivery_note_id.partner_ref = "Reference #1234" delivery_note_id.action_confirm() + + # ⇒ "Ordine singolo: consegna a indirizzo diverso" + def test_partner_shipping_delivering_single_so(self): + use_adv_notes_group_id = self.env.ref( + "l10n_it_delivery_note.use_advanced_delivery_notes" + ).id + self.env.user.write({"groups_id": [(3, use_adv_notes_group_id)]}) + + StockPicking = self.env["stock.picking"] + StockBackorderConfirmationWizard = self.env["stock.backorder.confirmation"] + sales_order = self.create_sales_order( + [ + self.large_desk_line, # 1 + self.desk_combination_line, # 1 + ], + ) + 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 + + backorder_wiz_id = picking.button_validate()["res_id"] + backorder_wiz = StockBackorderConfirmationWizard.browse(backorder_wiz_id) + backorder_wiz.process() + self.assertTrue(picking.delivery_note_id) + self.assertEqual(picking.delivery_note_id.partner_id, self.recipient) + self.assertEqual( + picking.delivery_note_id.partner_shipping_id, self.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() + self.assertTrue(picking_backorder.delivery_note_id) + self.assertEqual(picking_backorder.delivery_note_id.partner_id, self.recipient) + self.assertEqual( + picking_backorder.delivery_note_id.partner_shipping_id, + self.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..0e332c5f39dc 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.commercial_partner_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.commercial_partner_id.id + if sale_order_id.partner_invoice_id else self.partner_id.id ), "partner_shipping_id": self.partner_shipping_id.id,