Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] product_packaging_container_deposit update container deposit qauntity with Command #1470

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def update_order_container_deposit_quantity(self):
deposit_container_qties = (
lines_to_comp_deposit._get_order_lines_container_deposit_quantities()
)
values_lst = []
for line in self[self._get_order_line_field()]:
if not line.is_container_deposit:
continue
Expand All @@ -49,21 +50,27 @@ def update_order_container_deposit_quantity(self):
)
if not qty:
if order.state == "draft":
line.unlink()
values_lst.append(Command.delete(line.id))
else:
line.write(
{
line._get_product_qty_field(): 0,
}
values_lst.append(
Command.update(
line.id,
{
line._get_product_qty_field(): 0,
},
)
)

else:
line.write(
{
line._get_product_qty_field(): qty,
line._get_product_qty_delivered_received_field(): qty_dlvd_rcvd,
}
values_lst.append(
Command.update(
line.id,
{
line._get_product_qty_field(): qty,
line._get_product_qty_delivered_received_field(): qty_dlvd_rcvd,
},
)
)
values_lst = []
for product in deposit_container_qties:
if deposit_container_qties[product][0] > 0:
values = order.prepare_deposit_container_line(
Expand Down
1 change: 1 addition & 0 deletions product_packaging_container_deposit/tests/fake_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ContainerDepositOrderTest(models.Model):
name = fields.Char()
partner_id = fields.Many2one("res.partner")
company_id = fields.Many2one("res.company")
state = fields.Char()
order_line = fields.One2many(
"container.deposit.order.line.test", inverse_name="order_id"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def setUp(self):
{
"company_id": self.env.company.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"state": "draft",
}
)

Expand Down Expand Up @@ -236,3 +237,20 @@ def test_order_product_packaging_container_deposit_quantities_case5(self):
self.order.order_line[0].qty_delivered = 200
self.assertEqual(pallet_line.qty_delivered, 0)
self.assertEqual(box_line.qty_delivered, 8)

def test_confirmed_sale_product_packaging_container_deposit_quantities6(self):
"""Test deposit line is added deleted after reduce product_a quantity"""
order_line = self.env["container.deposit.order.line.test"].create(
{
"order_id": self.order.id,
"name": self.product_a.name,
"product_id": self.product_a.id,
"product_qty": 240,
},
)
order_line.write({"product_qty": 10})

pallet_line = self.order.order_line.filtered(
lambda ol: ol.product_id == self.pallet
)
self.assertFalse(pallet_line)
Loading