From eeb307ec91b7ce7dbb5c2371fc402eefb8cb7cf4 Mon Sep 17 00:00:00 2001 From: Andreu Orensanz Date: Fri, 8 Mar 2024 16:30:20 +0100 Subject: [PATCH] [MIG] mrp_bom_tracking: Migration to 17.0 --- mrp_bom_tracking/__manifest__.py | 4 +- mrp_bom_tracking/models/mrp_bom.py | 74 +++++++++++-------- .../static/description/index.html | 1 - 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/mrp_bom_tracking/__manifest__.py b/mrp_bom_tracking/__manifest__.py index 28e4723a5..24eeda225 100644 --- a/mrp_bom_tracking/__manifest__.py +++ b/mrp_bom_tracking/__manifest__.py @@ -1,9 +1,9 @@ -# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com) +# Copyright 2019-2024 ForgeFlow S.L. (https://www.forgeflow.com) # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). { "name": "MRP BoM Tracking", - "version": "16.0.1.0.0", + "version": "17.0.1.0.0", "author": "ForgeFlow, Odoo Community Association (OCA)", "summary": "Logs any change to a BoM in the chatter", "website": "https://github.com/OCA/manufacture", diff --git a/mrp_bom_tracking/models/mrp_bom.py b/mrp_bom_tracking/models/mrp_bom.py index 9799c081c..5894fde5c 100644 --- a/mrp_bom_tracking/models/mrp_bom.py +++ b/mrp_bom_tracking/models/mrp_bom.py @@ -13,8 +13,13 @@ class MrpBom(models.Model): product_qty = fields.Float(tracking=True) picking_type_id = fields.Many2one(tracking=True) type = fields.Selection(tracking=True) + ready_to_produce = fields.Selection(tracking=True) + consumption = fields.Selection(tracking=True) + produce_delay = fields.Integer(tracking=True) + days_to_prepare_mo = fields.Integer(tracking=True) def write(self, values): + template_env = self.env["ir.ui.view"] bom_line_ids = {} if "bom_line_ids" in values: for bom in self: @@ -23,13 +28,15 @@ class MrpBom(models.Model): if line[0] == 2: del_lines.append(line[1]) if del_lines: - bom.message_post_with_view( + message_body = template_env._render_template( "mrp_bom_tracking.track_bom_template", values={ "lines": self.env["mrp.bom.line"].browse(del_lines), "mode": "Removed", }, - subtype_id=self.env.ref("mail.mt_note").id, + ) + bom.message_post( + body=message_body, subtype_id=self.env.ref("mail.mt_note").id ) bom_line_ids[bom.id] = bom.bom_line_ids res = super().write(values) @@ -37,10 +44,12 @@ class MrpBom(models.Model): for bom in self: new_lines = bom.bom_line_ids - bom_line_ids[bom.id] if new_lines: - bom.message_post_with_view( + message_body = template_env._render_template( "mrp_bom_tracking.track_bom_template", values={"lines": new_lines, "mode": "New"}, - subtype_id=self.env.ref("mail.mt_note").id, + ) + bom.message_post( + body=message_body, subtype_id=self.env.ref("mail.mt_note").id ) return res @@ -49,37 +58,38 @@ class MrpBomLine(models.Model): _inherit = "mrp.bom.line" def write(self, values): + template_env = self.env["ir.ui.view"] if "product_id" in values: - for bom in self.mapped("bom_id"): - # Bind bom variable for the current iteration to the lambda - lines = self.filtered(lambda x, bom=bom: x.bom_id == bom) + for bom_line in self: + bom = bom_line.bom_id product_id = values.get("product_id") - if product_id: - product_id = self.env["product.product"].browse(product_id) - product_id = product_id or lines.product_id - if lines: - bom.message_post_with_view( + product = self.env["product.product"].browse(product_id) + if product.exists(): + message_body = template_env._render_template( "mrp_bom_tracking.track_bom_template_2", - values={"lines": lines, "product_id": product_id}, - subtype_id=self.env.ref("mail.mt_note").id, + values={"lines": bom_line, "product_id": product}, + ) + bom.message_post( + body=message_body, subtype_id=self.env.ref("mail.mt_note").id ) elif "product_qty" in values or "product_uom_id" in values: - for bom in self.mapped("bom_id"): - # Bind bom variable for the current iteration to the lambda - lines = self.filtered(lambda line, bom=bom: line.bom_id == bom) - if lines: - product_qty = values.get("product_qty") or lines.product_qty - product_uom_id = values.get("product_uom_id") - if product_uom_id: - product_uom_id = self.env["uom.uom"].browse(product_uom_id) - product_uom_id = product_uom_id or lines.product_uom_id - bom.message_post_with_view( - "mrp_bom_tracking.track_bom_line_template", - values={ - "lines": lines, - "product_qty": product_qty, - "product_uom_id": product_uom_id, - }, - subtype_id=self.env.ref("mail.mt_note").id, - ) + for bom_line in self: + bom = bom_line.bom_id + product_qty = values.get("product_qty") or bom_line.product_qty + product_uom_id = values.get("product_uom_id") + product_uom = None + if product_uom_id: + product_uom = self.env["uom.uom"].browse(product_uom_id) + product_uom = product_uom or bom_line.product_uom_id + message_body = template_env._render_template( + "mrp_bom_tracking.track_bom_line_template", + values={ + "lines": bom_line, + "product_qty": product_qty, + "product_uom_id": product_uom, + }, + ) + bom.message_post( + body=message_body, subtype_id=self.env.ref("mail.mt_note").id + ) return super().write(values) diff --git a/mrp_bom_tracking/static/description/index.html b/mrp_bom_tracking/static/description/index.html index f07dac793..29ec284ca 100644 --- a/mrp_bom_tracking/static/description/index.html +++ b/mrp_bom_tracking/static/description/index.html @@ -1,4 +1,3 @@ -