I written a query for create manufacturing order in create method of mrp.production but Manufacturing Orders created through my query is not deletable, instead of that I am getting an error
"
Cannot delete a manufacturing order in done state"
even the order is in draft state and I am getting another error,
"
The quantity to produce must be positive! "
when I try to click "Mark as Done" for Manufacturing Orders created through my query.
Here is my code below,
def _create_mo_recursive(self, component, main_mo):
if component.stock_in_hand bom = self.env['mrp.bom'].search(
[('product_tmpl_id', '=', component.product_id.product_tmpl_id.id)], limit=1)
if bom:
vals = {
'product_id': component.product_id.id,
'bom_id': bom.id,
'state': 'draft',
'product_qty': component.product_uom_qty,
'qty_producing': 0,
'product_uom_id': component.product_uom.id,
'reference': main_mo.name,
'main_mo_id': main_mo.id,
}
new_mo = self.env['mrp.production'].create(vals)
for bom_line in bom.bom_line_ids:
move_raw_vals = {
'product_id': bom_line.product_id.id,
# 'production_id': new_mo.id,
'name': bom_line.product_id.name,
'product_uom_qty': bom_line.product_qty * component.product_uom_qty,
'product_uom': bom_line.product_uom_id.id,
'location_id': 8,
'location_dest_id': 15,
}
new_mo.write({'move_raw_ids': [(0, 0, move_raw_vals)]})
# new_mo_stock = self.env['stock.move'].create(move_raw_vals)
for operation in bom.operation_ids:
workorder_vals = {
'name': operation.name,
'workcenter_id': operation.workcenter_id.id,
'duration_expected': operation.time_cycle,
'product_uom_id': component.product_uom.id,
}
new_mo.write({'workorder_ids': [(0, 0, workorder_vals)]})
for sub_component in new_mo.move_raw_ids:
self._create_mo_recursive(sub_component, main_mo)
@api.model
def create(self, vals):
res = super(MrpProductionExtent, self).create(vals)
res.create_mo_for_bom_component()
return res
Please give me solution for this problem.
I hope anyone will give me the solution.
Thank You.