Skip to content

Commit

Permalink
[IMP] sale_kit_description/
Browse files Browse the repository at this point in the history
  • Loading branch information
unaiberis committed Oct 3, 2024
1 parent 3bc7c71 commit 91917b4
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions sale_kit_description/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ class SaleOrderLine(models.Model):

@api.onchange("product_id")
def _onchange_sale_description_product_id(self):

if self.product_id and self.product_id.bom_ids:

bom = self.env["mrp.bom"].search(
[
("product_tmpl_id", "=", self.product_id.product_tmpl_id.id),
Expand All @@ -30,3 +28,31 @@ def _onchange_sale_description_product_id(self):
description_lines.append(description_line)

self.name = "\n".join(description_lines)

@api.model
def create(self, vals):
if "product_id" in vals:
product_id = self.env["product.product"].browse(vals["product_id"])
if product_id and product_id.bom_ids:
bom = self.env["mrp.bom"].search(
[
("product_tmpl_id", "=", product_id.product_tmpl_id.id),
("active", "=", True),
],
order="sequence",
limit=1,
)

if bom:
name = product_id.name
bom_lines = bom.bom_line_ids

description_lines = [name]
for line in bom_lines:
description_line = f"""- {line.product_id.name} \
{line.product_qty} {line.product_uom_id.name}"""
description_lines.append(description_line)

vals["name"] = "\n".join(description_lines)

return super().create(vals)

0 comments on commit 91917b4

Please sign in to comment.