将sf_manufacturing模块中stock.py的_run_manufacture方法进行拆分

This commit is contained in:
胡尧
2025-06-18 09:25:44 +08:00
parent 5c7e6e969f
commit 92f591c3e7
6 changed files with 368 additions and 222 deletions

View File

@@ -0,0 +1,41 @@
from odoo import models, api
class MrpProduction(models.Model):
_inherit = 'mrp.production'
@api.model_create_multi
def create(self, vals_list):
"""
创建生产计划
"""
productions = super().create(vals_list)
for production in productions:
# 工单耗时
workorder_duration = 0
for workorder in production.workorder_ids:
workorder_duration += workorder.duration_expected
sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)])
# 如果订单为空,则获取来源制造订单的销售单
if not sale_order:
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', production.origin)],
limit=1)
if mrp_production:
sale_order = self.env['sale.order'].sudo().search([('name', '=', mrp_production.origin)])
else:
mrp_production = production
# if sale_order:
# sale_order.write({'schedule_status': 'to schedule'})
self.env['sf.production.plan'].sudo().with_company(production.company_id).create({
'name': production.name,
'order_deadline': sale_order.deadline_of_delivery,
'production_id': production.id,
'date_planned_start': production.date_planned_start,
'origin': mrp_production.origin,
'product_qty': production.product_qty,
'product_id': production.product_id.id,
'state': 'draft',
})
return productions