odooapps/sale_order_batch/models/sale_order_line.py
2026-02-07 23:15:25 +01:00

21 lines
741 B
Python

from odoo import api, models
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
def _update_batch_products(self):
for order_line in self:
batch_id = order_line.order_id.batch_id
if batch_id:
registered_products = batch_id.mapped("product_ids").mapped("product_id")
if order_line.product_id not in registered_products:
self.env["sale.order.batch.product"].create(
{"batch_id": batch_id.id, "product_id": order_line.product_id.id}
)
@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
res._update_batch_products()
return res