Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
1519 Vistas

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
Mejor respuesta

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 Mejor respuesta

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
Publicaciones relacionadas Respuestas Vistas Actividad
2
may 24
1247
0
sept 23
1639
1
may 23
2556
0
sept 16
3414
1
mar 15
5893