跳至內容
選單
此問題已被標幟
2 回覆
8687 瀏覽次數

Hi,

I don't know why I get this error: null value in column "product_tmpl_id" violates not-null constraint.
My function has input and output. But the function output is not in the field product_tmpl_id.

        mrp_bom_obj = self.env['mrp.bom']
        abc = {
                'code' : values.get('code'),
                'category' : 'test',                            
                'product_tmpl_id'self.find_product_finish(values.get('name')),

        }
        bom_id = mrp_bom_obj.create(abc)       


    @api.multi
    def find_product_finish(self,name):
        product_obj = self.env['product.template']
        product_search = product_obj.search([('name''=', name)])
        if product_search != 0:
            return product_search.id
        else:
            raise UserError(_(%s product are not available.') % name)
頭像
捨棄
作者

thank you raphy for solving my problem so many times so far.

If you can also help with the function of adding component to mrp.bom from csv.

(product_id,'product_qty', 'product_uom_id')

for product_id and product_uom_id like product_tmpl_id the function is written

How to put it on the bom_line_id؟

'bom_line_ids':[(6,0,[y.id for y in bom_line_ids])

最佳答案

Hi,

Here you are creating a record into the model mrp.bom where product_tmpl_id is a required field. Checking your code it seems, you are not checking whether there is a value supplied for the product_tmpl_id during creation.

This error is thrown while the value for a required field is no supplied.


Update your code like this,

mrp_bom_obj = self.env['mrp.bom']
product_id = self.find_product_finish(values.get('name'))
if product_id:
abc = {
'code': values.get('code'),
'category': 'test',
'product_tmpl_id': product_id,

}
bom_id = mrp_bom_obj.create(abc)

@api.multi
def find_product_finish(self, name):
product_obj = self.env['product.template']
product_search = product_obj.search([('name', '=', name)], limit=1)
if product_search:
return product_search.id
else:
raise UserError(_(' %s product are not available.') % name)


Thanks

頭像
捨棄