[IMP] mrp_bom_tracking: black, isort

This commit is contained in:
Joan Sisquella
2020-01-07 11:51:55 +01:00
committed by Bernat Puig Font
parent 79b003070f
commit 549758e39c
3 changed files with 52 additions and 92 deletions

View File

@@ -8,12 +8,8 @@
"summary": "Logs any change to a BoM in the chatter", "summary": "Logs any change to a BoM in the chatter",
"website": "https://github.com/OCA/manufacture", "website": "https://github.com/OCA/manufacture",
"category": "Manufacturing", "category": "Manufacturing",
"depends": [ "depends": ["mrp"],
"mrp", "data": ["views/bom_template.xml"],
],
"data": [
"views/bom_template.xml",
],
"license": "LGPL-3", "license": "LGPL-3",
"installable": True, "installable": True,
} }

View File

@@ -7,54 +7,40 @@ from odoo import api, fields, models
class MrpBom(models.Model): class MrpBom(models.Model):
_inherit = "mrp.bom" _inherit = "mrp.bom"
code = fields.Char( code = fields.Char(track_visibility="onchange")
track_visibility="onchange", product_tmpl_id = fields.Many2one(track_visibility="always")
) product_qty = fields.Float(track_visibility="onchange")
product_tmpl_id = fields.Many2one( picking_type_id = fields.Many2one(track_visibility="onchange")
track_visibility="always", type = fields.Selection(track_visibility="onchange")
)
product_qty = fields.Float(
track_visibility="onchange",
)
picking_type_id = fields.Many2one(
track_visibility="onchange",
)
type = fields.Selection(
track_visibility="onchange",
)
@api.multi @api.multi
def write(self, values): def write(self, values):
bom_line_ids = {} bom_line_ids = {}
if 'bom_line_ids' in values: if "bom_line_ids" in values:
for bom in self: for bom in self:
del_lines = [] del_lines = []
for line in values['bom_line_ids']: for line in values["bom_line_ids"]:
if line[0] == 2: if line[0] == 2:
del_lines.append(line[1]) del_lines.append(line[1])
if del_lines: if del_lines:
bom.message_post_with_view( bom.message_post_with_view(
'mrp_bom_tracking.track_bom_template', "mrp_bom_tracking.track_bom_template",
values={ values={
'lines': self.env["mrp.bom.line"].browse( "lines": self.env["mrp.bom.line"].browse(del_lines),
del_lines), "mode": "Removed",
'mode': 'Removed',
}, },
subtype_id=self.env.ref('mail.mt_note').id, subtype_id=self.env.ref("mail.mt_note").id,
) )
bom_line_ids[bom.id] = bom.bom_line_ids bom_line_ids[bom.id] = bom.bom_line_ids
res = super(MrpBom, self).write(values) res = super(MrpBom, self).write(values)
if 'bom_line_ids' in values: if "bom_line_ids" in values:
for bom in self: for bom in self:
new_lines = bom.bom_line_ids - bom_line_ids[bom.id] new_lines = bom.bom_line_ids - bom_line_ids[bom.id]
if new_lines: if new_lines:
bom.message_post_with_view( bom.message_post_with_view(
'mrp_bom_tracking.track_bom_template', "mrp_bom_tracking.track_bom_template",
values={ values={"lines": new_lines, "mode": "New"},
'lines': new_lines, subtype_id=self.env.ref("mail.mt_note").id,
'mode': 'New',
},
subtype_id=self.env.ref('mail.mt_note').id,
) )
return res return res
@@ -64,41 +50,35 @@ class MrpBomLine(models.Model):
@api.multi @api.multi
def write(self, values): def write(self, values):
if 'product_id' in values: if "product_id" in values:
for bom in self.mapped('bom_id'): for bom in self.mapped("bom_id"):
lines = self.filtered(lambda l: l.bom_id == bom) lines = self.filtered(lambda l: l.bom_id == bom)
product_id = values.get('product_id') product_id = values.get("product_id")
if product_id: if product_id:
product_id = self.env["product.product"].browse( product_id = self.env["product.product"].browse(product_id)
product_id)
product_id = product_id or lines.product_id product_id = product_id or lines.product_id
if lines: if lines:
bom.message_post_with_view( bom.message_post_with_view(
'mrp_bom_tracking.track_bom_template_2', "mrp_bom_tracking.track_bom_template_2",
values={ values={"lines": lines, "product_id": product_id},
'lines': lines, subtype_id=self.env.ref("mail.mt_note").id,
'product_id': product_id,
},
subtype_id=self.env.ref('mail.mt_note').id,
) )
elif 'product_qty' in values or 'product_uom_id' in values: elif "product_qty" in values or "product_uom_id" in values:
for bom in self.mapped('bom_id'): for bom in self.mapped("bom_id"):
lines = self.filtered(lambda l: l.bom_id == bom) lines = self.filtered(lambda l: l.bom_id == bom)
if lines: if lines:
product_qty = values.get( product_qty = values.get("product_qty") or lines.product_qty
'product_qty') or lines.product_qty product_uom_id = values.get("product_uom_id")
product_uom_id = values.get('product_uom_id')
if product_uom_id: if product_uom_id:
product_uom_id = self.env["product.uom"].browse( product_uom_id = self.env["product.uom"].browse(product_uom_id)
product_uom_id)
product_uom_id = product_uom_id or lines.product_uom_id product_uom_id = product_uom_id or lines.product_uom_id
bom.message_post_with_view( bom.message_post_with_view(
'mrp_bom_tracking.track_bom_line_template', "mrp_bom_tracking.track_bom_line_template",
values={ values={
'lines': lines, "lines": lines,
'product_qty': product_qty, "product_qty": product_qty,
'product_uom_id': product_uom_id, "product_uom_id": product_uom_id,
}, },
subtype_id=self.env.ref('mail.mt_note').id, subtype_id=self.env.ref("mail.mt_note").id,
) )
return super(MrpBomLine, self).write(values) return super(MrpBomLine, self).write(values)

View File

@@ -6,49 +6,33 @@ from odoo.tests import common
class TestBomTracking(common.SavepointCase): class TestBomTracking(common.SavepointCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
cls.product_obj = cls.env['product.product'] cls.product_obj = cls.env["product.product"]
cls.bom_obj = cls.env['mrp.bom'] cls.bom_obj = cls.env["mrp.bom"]
cls.bom_line_obj = cls.env['mrp.bom.line'] cls.bom_line_obj = cls.env["mrp.bom.line"]
# Create products: # Create products:
cls.product_1 = cls.product_obj.create({ cls.product_1 = cls.product_obj.create({"name": "TEST 01", "type": "product"})
'name': 'TEST 01',
'type': 'product',
})
cls.component_1 = cls.product_obj.create({ cls.component_1 = cls.product_obj.create({"name": "RM 01", "type": "product"})
'name': 'RM 01', cls.component_2 = cls.product_obj.create({"name": "RM 02", "type": "product"})
'type': 'product', cls.component_2_alt = cls.product_obj.create(
}) {"name": "RM 02-B", "type": "product"}
cls.component_2 = cls.product_obj.create({ )
'name': 'RM 02',
'type': 'product',
})
cls.component_2_alt = cls.product_obj.create({
'name': 'RM 02-B',
'type': 'product',
})
# Create Bills of Materials: # Create Bills of Materials:
cls.bom = cls.bom_obj.create({ cls.bom = cls.bom_obj.create(
'product_tmpl_id': cls.product_1.product_tmpl_id.id, {"product_tmpl_id": cls.product_1.product_tmpl_id.id}
)
}) cls.line_1 = cls.bom_line_obj.create(
cls.line_1 = cls.bom_line_obj.create({ {"product_id": cls.component_1.id, "bom_id": cls.bom.id, "product_qty": 2.0}
'product_id': cls.component_1.id, )
'bom_id': cls.bom.id, cls.line_2 = cls.bom_line_obj.create(
'product_qty': 2.0, {"product_id": cls.component_2.id, "bom_id": cls.bom.id, "product_qty": 5.0}
}) )
cls.line_2 = cls.bom_line_obj.create({
'product_id': cls.component_2.id,
'bom_id': cls.bom.id,
'product_qty': 5.0,
})
def test_01_change_bom_line_qty(self): def test_01_change_bom_line_qty(self):
before = self.bom.message_ids before = self.bom.message_ids