Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
1537 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
Cost Break Up Diselesaikan
2
Mei 24
1278
0
Sep 23
1659
1
Mei 23
2592
0
Sep 16
3424
1
Mar 15
5921