[IMP] sale_order_batch: fix multi deletion issue
This commit is contained in:
parent
c1d3d4fa28
commit
bdf2d25470
2 changed files with 3 additions and 10 deletions
|
|
@ -42,7 +42,6 @@ class SaleOrder(models.Model):
|
||||||
raise UserError(_(f"Sale Order belongs to a Batch: {', '.join(invalid_orders)}"))
|
raise UserError(_(f"Sale Order belongs to a Batch: {', '.join(invalid_orders)}"))
|
||||||
return super().action_confirm()
|
return super().action_confirm()
|
||||||
|
|
||||||
# TODO: Unlink batch_product when no so lines anymore
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
res = super().write(vals)
|
res = super().write(vals)
|
||||||
if "batch_id" in vals.keys():
|
if "batch_id" in vals.keys():
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,9 @@ class SaleOrderLine(models.Model):
|
||||||
|
|
||||||
def _unlink_batch_product(self):
|
def _unlink_batch_product(self):
|
||||||
lines_to_unlink = self.filtered(lambda l: l.batch_product_id)
|
lines_to_unlink = self.filtered(lambda l: l.batch_product_id)
|
||||||
batch_product_unlink = self.env["sale.order.batch.product"]
|
batch_products = lines_to_unlink.mapped("batch_product_id")
|
||||||
for line in lines_to_unlink:
|
lines_to_unlink.update({"batch_product_id": False})
|
||||||
if line.batch_product_id:
|
batch_products.filtered(lambda p: len(p.sale_order_line_ids) == 0).unlink()
|
||||||
batch_product = line.batch_product_id
|
|
||||||
if len(batch_product.sale_order_line_ids) == 1:
|
|
||||||
batch_product_unlink += batch_product
|
|
||||||
else:
|
|
||||||
line.batch_product_id = False
|
|
||||||
batch_product_unlink.unlink()
|
|
||||||
|
|
||||||
def _update_batch_product(self):
|
def _update_batch_product(self):
|
||||||
lines_with_batch = self.filtered(lambda l: l.batch_id)
|
lines_with_batch = self.filtered(lambda l: l.batch_id)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue