跳至内容
菜单
此问题已终结
1 回复
2109 查看

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.

形象
丢弃
编写者 最佳答案

I got the solution after wrote 1 more query for add an entry of Manufacturing product in stock.move,

here is my new code,

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': component.product_uom_qty,
'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)
print(bom.product_id.name)
bom_main_val = {
'production_id': new_mo.id,
'product_id': new_mo.product_id.id,
# 'description': new_mo.product_id.name,
# 'production_id': new_mo.id,
'name': new_mo.product_id.name,
'product_uom_qty': component.product_uom_qty,
'product_uom': bom.product_uom_id.id,
'location_id': 15,
'location_dest_id': 8,
}
print(bom_main_val)
new_mo_stock = self.env['stock.move'].create(bom_main_val)

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


形象
丢弃
相关帖文 回复 查看 活动
1
9月 23
1988
2
6月 23
2202
1
5月 20
2372
1
5月 20
2846
2
8月 23
2803