跳至內容
選單
此問題已被標幟
1 回覆
1641 瀏覽次數
I want to Please create the MRP order whenever the Main Products scrap orders created and validated. Please note that
if Child MO of MRP is used in MRP those should be created as well. Once created
then validate the MRP orders and its associated Child MO. The below code create main and child mrps when it goes to to_close state it generate error "Produce qty must be positive"
Any body know which step i missed.

_inherit = 'stock.scrap'

def action_validate(self):
res = super(StockScrap, self).action_validate()

for scrap in self:
boms = self.env['mrp.bom'].search([('product_tmpl_id', '=', scrap.product_id.product_tmpl_id.id)])
if not boms:
raise exceptions.UserError("No Bill of Materials found for the product.")

mrp_orders_to_confirm = []
print('.............', boms)

for scrap in self:
for bom in boms:
mrp_order_vals = {
'product_id': scrap.product_id.id,
'product_qty': scrap.scrap_qty,
'product_uom_id': scrap.product_id.uom_id.id,
'bom_id': bom.id,

}
print(bom.product_id.name, '.................................PRD ID')

print(mrp_order_vals, '.......................created mrp order')
mrp_order = self.env['mrp.production'].create(mrp_order_vals)
mrp_orders_to_confirm.append(mrp_order)
print(mrp_order, 'MRP ODER ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,')

for line in bom.bom_line_ids:
print(line.product_id.name, ',,,,,,,,,,,,,,,,,,,,,,,,,,,,,PRODUCT NAME')

if line.child_bom_id:
child_mrp_order_vals = {
'product_id': line.product_id.id,
'product_qty': scrap.scrap_qty,
'product_uom_id': line.product_id.uom_id.id,
'bom_id': line.child_bom_id.id,
# 'move_raw_ids': [(0, 0, {
# 'product_id': line.product_id.id, })]
}
child_mrp_order = self.env['mrp.production'].create(child_mrp_order_vals)
mrp_orders_to_confirm.append(child_mrp_order)

for mrp_order in mrp_orders_to_confirm:
mrp_order.action_confirm()

return res

Thanks
your reply will be appreciable


頭像
捨棄
最佳答案

Instead of coding, take a look at standard functions in Odoo.  

On products you want to keep in stock create a reorder rule.  Here you can set MIN / MAX QTY and a reorder qty.  If you set MIN / MAX = 0 and reorder (Qty Multiple) = 1  it will only reorder when there is a demand.

You can choose Manual or Automatic trigger.  With Manual setting, you must use the function in Inventory -> Operation -> Replenishment and press button 'Order'. You can manually adjust qty you want to create order.

Automatic trigger: By default there is an automatic job - Scheduler that will create new orders, when there is a demand. You find the automatic job in Scheduled Action named Procurement Run Scheduler.  By default in run once a day.  You can modify the time to suit your needs.  It can also be run manually from Inventory -> Operations -> Run Scheduler.

An option for you might also be to create an automatic action to run scheduler when a scrap order is posted.

You can use Automatic trigger for some products, and manual for others according to what suits your business process.

The result will be that for whatever reason you are short for the product, an order will be created.

Child order:  If you use MTO route a child order will always be created connected to the mother order.  If you do not use MTO and you have multilevel manufacturing, the semifinished product will be created also with the same logic as for the main product.


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
2月 25
783
0
12月 23
1299
0
7月 22
462
1
7月 22
2144
1
6月 23
2651