From b30e839932dbd9803e5477eb2558fdd2b3d79a20 Mon Sep 17 00:00:00 2001 From: rexwu <rex@rexwu.tw> Date: Tue, 11 Jul 2023 13:01:27 +0800 Subject: [PATCH 1/3] feat(mrp): bom amount computing --- extra-addons/kci-mrp/models/mrp_bom.py | 22 +++++++++++++------- extra-addons/kci-mrp/views/mrp_bom_views.xml | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/extra-addons/kci-mrp/models/mrp_bom.py b/extra-addons/kci-mrp/models/mrp_bom.py index 4ec7705f6fe..818e514f985 100644 --- a/extra-addons/kci-mrp/models/mrp_bom.py +++ b/extra-addons/kci-mrp/models/mrp_bom.py @@ -31,13 +31,13 @@ class Bom(models.Model): 'amount_total': amount, }) - @api.onchange('status') - def _change_status(self): - for bom in self: - for line in bom.bom_line_ids: - line.update({ - 'status': self.status, - }) + # @api.depends('status') + # def _change_status(self): + # for bom in self: + # for line in bom.bom_line_ids: + # line.update({ + # 'status': self.status, + # }) class BomLine(models.Model): @@ -50,6 +50,14 @@ class BomLine(models.Model): price = fields.Float(string='�寞聢', store=True) + @api.depends('bom_id.status') + def _change_status(self): + print('111') + for line in self: + print('222') + line.update({ + 'status': self.bom_id.status, + }) # class InternalBom(models.Model): # _name = "mrp.internal.bom" diff --git a/extra-addons/kci-mrp/views/mrp_bom_views.xml b/extra-addons/kci-mrp/views/mrp_bom_views.xml index ab0e0567adb..80ea7cf61b0 100644 --- a/extra-addons/kci-mrp/views/mrp_bom_views.xml +++ b/extra-addons/kci-mrp/views/mrp_bom_views.xml @@ -23,7 +23,7 @@ </xpath> <xpath expr="//field[@name='company_id']" position="after"> - <field name="status" invisible="1"/> + <field name="status" invisible="0"/> <field name="amount_total" attrs="{'invisible': [('status', '=', 'external')]}"/> </xpath> </field> -- GitLab From a5447c0a15b1bd8a5f9a8034f48bd549f44b24bc Mon Sep 17 00:00:00 2001 From: rexwu <spplkk113@gmail.com> Date: Tue, 11 Jul 2023 23:35:04 +0800 Subject: [PATCH 2/3] fixed(mrp): bom and bom line status sync --- extra-addons/kci-mrp/models/mrp_bom.py | 34 ++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/extra-addons/kci-mrp/models/mrp_bom.py b/extra-addons/kci-mrp/models/mrp_bom.py index 818e514f985..44cb669043c 100644 --- a/extra-addons/kci-mrp/models/mrp_bom.py +++ b/extra-addons/kci-mrp/models/mrp_bom.py @@ -31,18 +31,22 @@ class Bom(models.Model): 'amount_total': amount, }) - # @api.depends('status') - # def _change_status(self): - # for bom in self: - # for line in bom.bom_line_ids: - # line.update({ - # 'status': self.status, - # }) + @api.onchange('status', 'bom_line_ids') + def _change_status(self): + for bom in self: + for line in bom.bom_line_ids: + line.update({ + 'status': self.status, + }) class BomLine(models.Model): _inherit = 'mrp.bom.line' + bom_id = fields.Many2one( + 'mrp.bom', 'Parent BoM', + index=True, ondelete='cascade', required=True) + status = fields.Selection([ ('internal', 'bom1'), ('external', 'bom2') @@ -50,14 +54,14 @@ class BomLine(models.Model): price = fields.Float(string='�寞聢', store=True) - @api.depends('bom_id.status') - def _change_status(self): - print('111') - for line in self: - print('222') - line.update({ - 'status': self.bom_id.status, - }) + # @api.depends('bom_id.status') + # def _change_status(self): + # print('111') + # for line in self: + # print('222') + # line.update({ + # 'status': self.bom_id.status, + # }) # class InternalBom(models.Model): # _name = "mrp.internal.bom" -- GitLab From 09ff5cc3895299d3ae09091b758854fc66fde60e Mon Sep 17 00:00:00 2001 From: rexwu <spplkk113@gmail.com> Date: Wed, 12 Jul 2023 08:27:12 +0800 Subject: [PATCH 3/3] feature(mrp): materiels type --- extra-addons/kci-mrp/models/product.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/extra-addons/kci-mrp/models/product.py b/extra-addons/kci-mrp/models/product.py index 4cf473d1bf3..a576babe601 100644 --- a/extra-addons/kci-mrp/models/product.py +++ b/extra-addons/kci-mrp/models/product.py @@ -7,15 +7,31 @@ class Product(models.Model): _inherit = "product.product" product_type = fields.Selection([ + ('project', 'Project'), + ('component', 'Component')], default='component') + + component_type = fields.Selection([ + ('none', 'None'), ('product', 'Product'), - ('semi_product', 'Semi Product'), - ('component', 'Component')], default='product') + ('processed', 'Processed Part'), + ('3d', '3D Printing'), + ('consumable', 'Consumable'), + ('cb', 'Control Box'), + ('ec', 'Electric Component')], default=lambda self: 'product' if self.product_type == 'component' else 'none') class ProductTemplate(models.Model): _inherit = "product.template" product_type = fields.Selection([ - ('product', 'Product'), - ('semi_product', 'Semi Product'), + ('project', 'Project'), ('component', 'Component')], default='product') + + component_type = fields.Selection([ + ('none', 'None'), + ('product', 'Product'), + ('processed', 'Processed Part'), + ('3d', '3D Printing'), + ('consumable', 'Consumable'), + ('cb', 'Control Box'), + ('ec', 'Electric Component')], default=lambda self: 'product' if self.product_type == 'component' else 'none') -- GitLab