Skip to Content
Menú
This question has been flagged
3 Respostes
1536 Vistes

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
Descartar
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
Descartar
Autor 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
Descartar
Related Posts Respostes Vistes Activitat
2
de maig 24
1277
0
de set. 23
1658
1
de maig 23
2589
0
de set. 16
3424
1
de març 15
5921