Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
1545 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
Cost Break Up Vyřešeno
2
kvě 24
1298
0
zář 23
1680
1
kvě 23
2605
0
zář 16
3430
1
bře 15
5926