Skip to Content
Menu
This question has been flagged
5 Replies
13812 Rodiniai

Hi, I am working on a BOM (Bill of Materials) creator, but currently stuck at this error:

The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

[object with reference: product_id - product.id]

Error Log:

2019-06-28 02:57:40,220 9396 INFO 20190620 odoo.sql_db: bad query: INSERT INTO "mrp_production" ("id", "building", "procurement_group_id", "propagate", "user_id", "contract_id", "picking_type_id", "product_uom_id", "company_id", "priority", "date_planned_finished", "state", "product_id", "location_dest_id", "product_qty", "bom_id", "date_planned_start", "atlas_id", "partner_id", "location_src_id", "name", "create_uid", "write_uid", "create_date", "write_date") VALUES(nextval('mrp_production_id_seq'), NULL, 546, false, 1, 7, 6, NULL, 1, '1', '2019-06-28 02:57:40', 'confirmed', NULL, 15, '8.000000', NULL, '2019-06-28 02:57:40', 23, NULL, 28, 'MO/00528', 1, 1, (now() at time zone 'UTC'), (now() at time zone 'UTC')) RETURNING id ​

Does this means my product_id - product.id value is empty? If so, how do I set a value in its field? 

Much appreciated for any assistance.

**I am on Odoo 10**

Portretas
Atmesti
Autorius

Hi Hoang Tran, thanks for the reply, though I'm not exactly sure how to do that.

Best Answer

Hello, you can check the value of product_id. Perhaps product_id is a required value, but it is not read or not filled in in the background

Portretas
Atmesti
Best Answer

Hi,

This error occurs because the value you see on the UI gets lost while saving the record before the method is executed. Maybe the fields that you require when creating a new record using method act_product is missing. To prevent this, you can apply a quick workaround, which updating the prouduct_id in the write method. For further debugging, you should look at the fields you are using to extract the product_id, is it read-only on the UI? Do the fields you are using the creating new record in the act_product is somewhat related to other onchange or computed fields using depends?

Portretas
Atmesti
Autorius Best Answer

Hi Niyas Raphy, thanks for the reply!

This is a custom module, and here's the section I suspect the error might have occurred:

@api.multi
def act_production(self):
project_id = self.env.user.project_id
for a in self:
boms = {}
buildings = {}

for al in a.atlas_line_ids:
al.assembly_section = parse_str(al.assembly_section)
al.bom_no = parse_str(al.bom_no)

# if it doesn't have bom_no, then the data format is incorrect
if not al.bom_no or len(al.bom_no.strip()) == 0:
continue

# sub_bom create.
if al.assembly_categ.code in ['frame']: # not include 'others', 'regardless' category
group_key = "%s/%s" % (al.bom_no, al.assembly_categ.code)

sub_bom = self.env['mrp.bom'].sudo().search(
[('project_id', '=', project_id.id),
('product_id.default_code', '=', group_key),
('atlas_id', '=', al.atlas_id.edit_atlas_id.id)], limit=1)

# Create BOM when BOM does not exist
if not sub_bom:
bom_product = self.env['product.product'].sudo().search(
[('name', '=', group_key),
('default_code', '=', group_key),
('project_id', '=', project_id.id),
('categ_id', '=', al.categ_id.id)], limit=1)
if not bom_product:
bom_product = self.env['product.product'].sudo().create({
'project_id': project_id.id,
'categ_id': al.categ_id.id,
'name': group_key,
'default_code': group_key,
'product_id': bom_product.id,
'type': 'product',
# 'material': p.material_no
})
sub_bom = self.env['mrp.bom'].sudo().create ({
'project_id': project_id.id,
'product_tmpl_id': bom_product.product_tmpl_id.id,
'product_id': bom_product.id,
'atlas_id': al.atlas_id.edit_atlas_id.id,
# 'product_qty': p.qty
})

if al.categ_id.code == 'aluminum' or 'raw':
product = self.env['product.product'].sudo ().search (
[('project_id', '=', project_id.id),
('categ_id', '=', al.categ_id.id),
('default_code', '=', al.name),
('part_no', '=', al.code),
], limit=1)
else:
product = self.env['product.product'].sudo ().search (
[('project_id', '=', project_id.id),
('categ_id', '=', al.categ_id.id),
('default_code', '=', al.name),
], limit=1)
# if it already has bom_line, find it.
bom_line = sub_bom.bom_line_ids.filtered(lambda l: l.product_id.default_code == al.name)
# if it doesn't have bom_line, create it.
if not bom_line:
bom_line = self.env['mrp.bom.line'].sudo().create({
'product_id': product.id,
'product_qty': parse_float(al.unit_qty),
'bom_id': sub_bom.id
})

# then assign unit qty to bom_line.
bom_line.product_qty = parse_float(al.unit_qty)

for al in a.atlas_line_ids:
if not al.bom_no or len(al.bom_no.strip()) == 0:
continue
elif (not al.name or len(al.name.strip()) == 0) and (not al.unit_qty or len(al.unit_qty.strip()) == 0) \
and al.bom_no and (not al.assembly_categ.code) and (not al.building or len(al.building)):
# Search BOM
bom = self.env['mrp.bom'].sudo().search(
[('project_id', '=', project_id.id),
('product_id.default_code', '=', al.bom_no),
('atlas_id', '=', a.edit_atlas_id.id)], limit=1)
# Create BOM when BOM does not exist
if not bom:
bom_product = self.env['product.product'].sudo().search(
[('name', '=', al.bom_no),
('project_id', '=', project_id.id),
('categ_id', '=', al.categ_id.id)], limit=1)
if not bom_product:
bom_product = self.env['product.product'].sudo().create({
'project_id': project_id.id,
'categ_id': al.categ_id.id,
'name': al.bom_no,
'default_code': al.bom_no,
'type': 'product',
# 'material': p.material_no
})

bom = self.env['mrp.bom'].sudo().create({
'project_id': project_id.id,
'product_tmpl_id': bom_product.product_tmpl_id.id,
'product_id': bom_product.id,
'atlas_id': a.edit_atlas_id.id,
# 'product_qty': p.qty
})

boms['%s:%s' % (al.building, bom.id)] = {"bom": bom, "qty": parse_float (al.qty), "building": al.building}

# Add bom search in atlas_id.
for sub_categ in ['frame']:
sub_bom_name = '%s/%s' % (bom.product_id.name, sub_categ)
sub_bom_exist = bom.bom_line_ids.filtered(lambda x: x.product_id.default_code == sub_bom_name)
# if not sub_bom_exist:
sub_bom = self.env['mrp.bom'].sudo().search(
[('project_id', '=', project_id.id),
('product_id.default_code', '=', sub_bom_name),
('atlas_id', '=', al.atlas_id.edit_atlas_id.id)], limit=1)

if sub_bom and not sub_bom_exist:
bom.write({'bom_line_ids': [(0, 0, {'product_id': sub_bom.product_id.id})],})

boms['%s:%s' % (al.building, sub_bom.id)] = {"bom": sub_bom, "qty": parse_float(al.qty), "building": al.building}

# a.production_ids = [(6, 0, production_ids)]

elif al.assembly_categ.code in ['surface', 'others']:
if al.categ_id.code == 'aluminum' or 'raw':
product = self.env['product.product'].sudo ().search (
[('project_id', '=', project_id.id),
('categ_id', '=', al.categ_id.id),
('default_code', '=', al.name),
('part_no', '=', al.code),
], limit=1)
else:
product = self.env['product.product'].sudo().search (
[('project_id', '=', project_id.id),
('categ_id', '=', al.categ_id.id),
('default_code', '=', al.name),
], limit=1)
# if it already has bom_line, find it.
bom_line = bom.bom_line_ids.filtered(lambda l: l.product_id.default_code == al.name)

# if it doesn't have bom_line, create it.
if not bom_line:
bom_line = self.env['mrp.bom.line'].sudo().create ({
'product_id': product.id,
'product_qty': parse_float (al.unit_qty),
'bom_id': bom.id
})

# then assign unit qty to bom_line.
bom_line.product_qty = parse_float(al.unit_qty)


production_ids = []
# for al in a.atlas_line_ids:

categs = self.env['product.category'].sudo ().search ([('code', 'in', ['assembly', 'assembly_preparation'])])
panels = self.env['tokiku.panel'].sudo ().search (
[('project_id', '=', self.env.user.project_id.id),
('categ_id', 'in', [c.id for c in categs])])

for v in boms.itervalues():
# if i in buildings:
# for k in buildings.keys():
# if boms[i][0].id == buildings[k][0]:
production_id = self.env['mrp.production'].sudo().search(
[('contract_id', '=', a.contract_id.id),
('bom_id', '=', v['bom'].id),
('atlas_id', '=', a.edit_atlas_id.id),
('building', '=', v['building'])])
location_src_id = self.env['stock.location'].with_context(lang=None).search(
[('usage', '=', 'internal'),
('name', '=', 'Assembly')], limit=1)
location_dest_id = self.env['stock.location'].with_context (lang=None).search (
[('usage', '=', 'internal'),
('name', '=', 'Pending'),
('location_id', '=', location_src_id.id)], limit=1)
if not production_id:
prod_obj = {
'contract_id': al.atlas_id.contract_id.id,
'bom_id': v['bom'].id,
'product_id': v['bom'].product_id.id,
'product_uom_id': v['bom'].product_id.uom_id.id,
'product_qty': v['qty'],
'atlas_id': a.edit_atlas_id.id,
'location_src_id': location_src_id.id,
'building': v['building'],
'partner_id': a.partner_id.id
# 'panel_ids': panel.id,
}
default_code = v['bom'].product_id.default_code
if default_code and ('frame' in default_code):
prod_obj.update({'location_dest_id': location_dest_id.id})
production_id = self.env['mrp.production'].sudo().create(prod_obj)

for r in production_id:
production_ids.append(r.id)

a.production_ids = [(6, 0, production_ids)]

for p in panels:
p.assembly_line_ids = [(6, 0, production_ids)]
Portretas
Atmesti

by putting if or print statement in the code, the product_id key in the dictionary passed to the create method contains the value or not, sometime if might be Null or False

Best Answer

Hi,  

the error shows that ,you dint provide product when you create manufacturing order.so pass the product_id in the dictionary when you create MO.

Portretas
Atmesti
Best Answer

Hi,

By default there is no chance for such an error. Have you done any customization are you use any custom module in the database? As you specified, the issue is that, the value for the mandatory field is not supplied. For setting the value you can see the field named Product in the interface.


Thanks

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
2
gruod. 24
6643
2
lapkr. 24
26892
2
geg. 24
6443
3
kov. 24
5810
0
kov. 24
917