Skip to content

Commit

Permalink
[FIX] l10n_it_delivery_note: fix validate multiple picking with advan…
Browse files Browse the repository at this point in the history
…ced delivery note features disabled
  • Loading branch information
micheledic committed Dec 6, 2024
1 parent e095f39 commit 86d0767
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
23 changes: 12 additions & 11 deletions l10n_it_delivery_note/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
Expand Down
36 changes: 36 additions & 0 deletions l10n_it_delivery_note/tests/test_stock_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
#
Expand Down

0 comments on commit 86d0767

Please sign in to comment.