Skip to Content
Menu
This question has been flagged
3 Replies
1517 Views

Hello, 

I would like to restrict the number of BoM that can be created per product.

I want to do this so people will be able to create a BoM but only if the BoM didn't exist yet. 


We don't use variant so we don't need more than one BoM per product and we don't want to either (to make data management as simple as possible). 


I tried to make a Record Rules, with this code : 

[("product.template.bom_count", "

But I have an error : "

ValueError: Invalid field mrp.bom.product in leaf ('product.template.bom_count', '


If someone have a solution...

Thank you

Avatar
Discard
Best Answer

Hi,

You can achieve the same functionality using a constrains method. Here's the modified code:

class MrpBom(models.Model):

    _inherit = 'mrp.bom'


    @api.constrains('product_tmpl_id')

    def _check_bom_count(self):

        for bom in self:

            if bom.product_tmpl_id.bom_count > 1:

                raise ValidationError("Only one Bill of Materials allowed per product.")


Hope it helps

Avatar
Discard
Author Best Answer

Hi,

I haven't even think that I could use product record rules instead of BoM record rules to manage BoM creation. 

So, for the record, it work with :

  • [("bom_count", 


(I don't know why, probably for security purposes, but half my code is deleted by the forum, you need to make it be inferior at 2)


Avatar
Discard
Related Posts Replies Views Activity
2
May 24
1247
0
Sep 23
1639
1
May 23
2554
0
Sep 16
3414
1
Mar 15
5892