diff --git a/l10n_it_delivery_note/models/stock_picking.py b/l10n_it_delivery_note/models/stock_picking.py index 93da47e0e0e2..574987268d0b 100644 --- a/l10n_it_delivery_note/models/stock_picking.py +++ b/l10n_it_delivery_note/models/stock_picking.py @@ -332,49 +332,50 @@ def button_validate(self): if delivery_note_to_create and not self.delivery_note_id: delivery_note = self._create_delivery_note() self.write({"delivery_note_id": delivery_note.id}) - if self.sale_id: - self.sale_id._assign_delivery_notes_invoices(self.sale_id.invoice_ids) + if self.mapped("sale_id"): + self.mapped("sale_id")._assign_delivery_notes_invoices( + self.mapped("sale_id").invoice_ids + ) return res def _create_delivery_note(self): partners = self._get_partners() type_id = self.env["stock.delivery.note.type"].search( [ - ("code", "=", self.picking_type_code), + ("code", "=", self[0].picking_type_code), ("company_id", "=", self.company_id.id), ], limit=1, ) delivery_method_id = self.mapped("carrier_id")[:1] + sale_id = self[0].sale_id return self.env["stock.delivery.note"].create( { "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[1].id, + "partner_id": sale_id.partner_id.id if sale_id else partners[1].id, "partner_shipping_id": partners[1].id, "type_id": type_id.id, - "date": self.date_done, + "date": self[0].date_done, "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 + sale_id.default_transport_condition_id.id or partners[1].default_transport_condition_id.id or type_id.default_transport_condition_id.id ), "goods_appearance_id": ( - self.sale_id.default_goods_appearance_id.id + sale_id.default_goods_appearance_id.id or partners[1].default_goods_appearance_id.id or type_id.default_goods_appearance_id.id ), "transport_reason_id": ( - self.sale_id.default_transport_reason_id.id + sale_id.default_transport_reason_id.id or partners[1].default_transport_reason_id.id or type_id.default_transport_reason_id.id ), "transport_method_id": ( - self.sale_id.default_transport_method_id.id + sale_id.default_transport_method_id.id or partners[1].default_transport_method_id.id or type_id.default_transport_method_id.id ), 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 0a362a507937..92986370907e 100644 --- a/l10n_it_delivery_note/tests/test_stock_delivery_note.py +++ b/l10n_it_delivery_note/tests/test_stock_delivery_note.py @@ -57,6 +57,42 @@ def test_partial_delivering_single_so(self): picking_backorder.button_validate() self.assertTrue(picking_backorder.delivery_note_id) + # Test validazione di più picking (ad es nel caso di batch picking) + def test_multiple_picking(self): + user = new_test_user( + self.env, + login="test", + groups="stock.group_stock_manager", + ) + # change user in order to automatically create delivery note + # when picking is validated + self.env.user = user + # creo ordine 1 + sale_order1 = self.create_sales_order( + [ + self.desk_combination_line, # 1 + ], + ) + + # creo ordine 2 + sale_order1.action_confirm() + sale_order2 = self.create_sales_order( + [ + self.large_desk_line, # 1 + ], + ) + + sale_order2.action_confirm() + picking_ids = sale_order1.picking_ids | sale_order2.picking_ids + + # verifico creazione di due ricezioni + self.assertEqual(len(picking_ids), 2) + sale_order1.picking_ids.move_ids.quantity_done = 1 + sale_order2.picking_ids.move_ids.quantity_done = 1 + picking_ids.button_validate() + # verifico che la generazione del ddt sia ok + self.assertEqual(len(picking_ids.mapped("delivery_note_id")), 1) + # ⇒ "Consegna senza ordine" def test_delivery_without_so(self): #