Hi! In my custom purchase module i have quite complicated setup. Unfortunately, once i'm trying to save RFQ with any product inside, system replies with an 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: name - name]
Here is everything i have inside custom models.py regarding name:
@api.multi
def get_data_sum(self, field_name):
data_list = [getattr(line, field_name) for line in self.order_line]
return sum(data_list)
def add_product(self, rec, product_ids):
for product_id in product_ids:
pro_ref = self.env['product.product'].search([('id','=',product_id)])
name = pro_ref.name
uom = pro_ref.uom_id.id
val = {
'order_id': rec.id,
'name': name,
'product_qty': 1,
'date_planned': datetime.now(),
'product_uom': uom,
'price_unit': 0.0,
'product_id': product_id,
}
self.env['purchase.order.line'].create(val)
and
@api.onchange('product_id')
def onchange_product_id(self):
rec = super(PurchaseOrderLine, self).onchange_product_id()
name = self.product_id.name
self.update({'name': name})
@api.multi
@api.onchange('product_id', 'alt_uom', 'display_product_qty', 'price_alt_uom', 'packaging')
def _get_unit_price(self):
'''Function to calculate every automated value on pol'''
if self.product_id.type == 'service' or self.product_id.type == 'consu':
self.alt_uom = False
self.product_qty = self.display_product_qty
self.price_unit = self.price_alt_uom
else:
if self.product_id.uom_group.name:
if self.alt_uom == 'm3':
if self.product_id:
name = self.product_id.uom_group.name.split('x')
alt_uom_ratio = 1
total_m3 = (float(name[0])*float(name[1])*float(name[2])*self.display_product_qty * self.packaging.uom_value)/1000000000
self.volm = total_m3
self.price_unit = alt_uom_ratio * self.price_alt_uom
self.price_subtotal = total_m3 * self.price_alt_uom
self.product_qty = total_m3
elif self.alt_uom == 'pc':
if self.product_id:
name = self.product_id.uom_group.name.split('x')
alt_uom_ratio = 1/((float(name[0])*float(name[1])*float(name[2]))/1000000000)
total_pcs = self.display_product_qty * self.packaging.uom_value
self.volm = total_pcs
self.price_unit = alt_uom_ratio * self.price_alt_uom
self.price_subtotal = total_pcs * self.price_alt_uom
self.product_qty = (float(name[0])*float(name[1])*float(name[2])*self.display_product_qty * self.packaging.uom_value)/1000000000
elif self.alt_uom == 'm2':
if self.product_id:
name = self.product_id.uom_group.name.split('x')
alt_uom_ratio = 1/(float(name[0])/1000)
total_m2 = (float(name[1])*float(name[2])*self.display_product_qty*self.packaging.uom_value)/1000000
self.volm = total_m2
self.price_unit = alt_uom_ratio * self.price_alt_uom
self.price_subtotal = total_m2 * self.price_alt_uom
self.product_qty = (float(name[0])*float(name[1])*float(name[2])*self.display_product_qty * self.packaging.uom_value)/1000000000
elif self.alt_uom == 'ft2':
if self.product_id:
name = self.product_id.uom_group.name.split('x')
alt_uom_ratio = 1/((float(name[0])/1000)*10.76391041)
total_ft2 = (float(name[1])*float(name[2])*self.display_product_qty*self.packaging.uom_value)*10.76391041/1000000
self.volm = total_ft2
self.price_unit = alt_uom_ratio * self.price_alt_uom
self.price_subtotal = total_ft2 * self.price_alt_uom
self.product_qty = (float(name[0])*float(name[1])*float(name[2])*self.display_product_qty * self.packaging.uom_value)/1000000000
elif self.alt_uom == 'msf':
if self.product_id:
name = self.product_id.uom_group.name.split('x')
alt_uom_ratio = 1/((float(name[0])/1)*10.76391041)
total_msf = (float(name[1])*float(name[2])*self.display_product_qty*self.packaging.uom_value)*10.76391041/1000000000
self.volm = total_msf
self.price_unit = alt_uom_ratio * self.price_alt_uom
self.price_subtotal = total_msf * self.price_alt_uom
self.product_qty = (float(name[0])*float(name[1])*float(name[2])*self.display_product_qty * self.packaging.uom_value)/1000000000
Please share any of your thoughts.