This question has been flagged
1 Reply
9753 Views

This is my method that I'm creating a production from, but I'm getting "Record does not exist or have been deleted" when create method are called at the end.

@api.multi
def do_production(self, product, location_src_id, qty_value,
location_dest_id=None):
mrp_obj = self.env['mrp.production']
mrp_bom_obj = self.env['mrp.bom']
bom_obj = mrp_bom_obj.search([('product_tmpl_id', '=',
product.product_tmpl_id.id)])
if not bom_obj:
raise AccessError(_('Create bill of materials for ') +
product.name_template)
if not location_dest_id:
location_dest_id = self.location_id.id
vals = mrp_obj.default_get(mrp_obj._columns.keys())
vals.update({

"product_qty": qty_value,
"product_uom": product.uom_id.id,
"product_id": product.id,
"bom_id": bom_obj.id,
"block_peat_id": self.id,
"location_dest_id": location_dest_id,
"location_src_id": location_src_id,
})
production = mrp_obj.create(vals)

and this is vals that i'm creating production with

{'user_id': 1, 'location_src_id': 20, 'product_uom': 20, 'date_planned': '2019-01-03 18:56:12', 'block_peat_id': False, 'completing': False, 'company_id': 1, 'priority': '1', 'state': 'draft', 'product_id': 25, 'location_dest_id': 34, 'product_qty': 0.375, 'bom_id': 17, 'name': u'MO00204'}

so i can't find where the problem is.


Avatar
Discard
Best Answer

Hi Grf,

i think you need to improve your code. I review your code and i found some improvements. Just do it. if it will work.

1) when you use @api.multi, it is better to iterate your self in loop so:

@api.multi

def do_production(self, product, location_src_id, qty_value,

                  location_dest_id=None):

for rec in self:

    mrp_obj = self.env['mrp.production']

    mrp_bom_obj = self.env['mrp.bom']

    bom_obj = mrp_bom_obj.search([('product_tmpl_id', '=',

                                   product.product_tmpl_id.id)])

    if not bom_obj:

        raise AccessError(_('Create bill of materials for ') +

                          product.name_template)

    if not location_dest_id:

        location_dest_id = rec.location_id.id

    vals = mrp_obj.default_get(mrp_obj._columns.keys())

    vals.update({

      

        "product_qty": qty_value,

        "product_uom": product.uom_id.id,

        "product_id": product.id,

        "bom_id": bom_obj.id,

        "block_peat_id": rec.id,

        "location_dest_id": location_dest_id,

        "location_src_id": location_src_id,

    })

    production = mrp_obj.create(vals) 

2) Check in mrp.production model of base that how many required fields are in that model and if any required field missing when you create record in your custom function.

i have found some required fields that you need to give in vals:

 product_uom_id

    picking_type_id

    date_planned_start

    company_id


Hope it will useful for you.

Avatar
Discard