采购明细加需求计划明细字段

This commit is contained in:
guanhuan
2025-07-09 16:46:46 +08:00
parent c2cb24c60b
commit acb6fd42ca
3 changed files with 30 additions and 91 deletions

View File

@@ -5,38 +5,42 @@ from odoo.tools import float_compare
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan",
string="需求计划明细", readonly=True)
def button_confirm(self):
if self.demand_plan_line_id:
if self.order_line[0].demand_plan_line_id:
self = self.with_context(
demand_plan_line_id=self.demand_plan_line_id.id
demand_plan_line_id=self.order_line[0].demand_plan_line_id.id
)
res = super(PurchaseOrder, self).button_confirm()
return res
@api.depends('origin', 'demand_plan_line_id')
@api.depends('origin')
def _compute_purchase_type(self):
for purchase in self:
if purchase.order_line[0].product_id.categ_id.name == '坯料':
if purchase.order_line[0].product_id.materials_type_id.gain_way == '外协':
purchase.purchase_type = 'outsourcing'
else:
if purchase.demand_plan_line_id.supply_method == 'outsourcing':
if purchase.order_line[0].demand_plan_line_id.supply_method == 'outsourcing':
purchase.purchase_type = 'outsourcing'
elif purchase.demand_plan_line_id.supply_method == 'purchase':
elif purchase.order_line[0].demand_plan_line_id.supply_method == 'purchase':
purchase.purchase_type = 'outside'
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan",
string="需求计划明细", readonly=True)
@api.model
def create(self, vals):
res = super(PurchaseOrder, self).create(vals)
res = super(PurchaseOrderLine, self).create(vals)
if not res.demand_plan_line_id:
origin = [origin.replace(' ', '') for origin in res.origin.split(',')]
origin = [origin.replace(' ', '') for origin in res.order_id.origin.split(',')]
if self.env.context.get('demand_plan_line_id'):
res.demand_plan_line_id = self.env.context.get('demand_plan_line_id')
elif 'MO' in res.origin:
elif 'MO' in res.order_id.origin:
# 原单据是制造订单
mp_ids = self.env['mrp.production'].sudo().search([('name', 'in', origin)])
if mp_ids: