38 lines
1.9 KiB
Python
38 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class StockMove(models.Model):
|
|
_inherit = 'stock.move'
|
|
|
|
demand_plan_line_ids = fields.Many2many(comodel_name="sf.production.demand.plan",
|
|
string="需求计划明细", compute='_compute_demand_plan_line_ids', store=True)
|
|
|
|
@api.depends('origin', 'move_orig_ids')
|
|
def _compute_demand_plan_line_ids(self):
|
|
sorted_records = self.sorted(key=lambda r: -r.id)
|
|
for line in sorted_records:
|
|
origin = [origin.replace(' ', '') for origin in line.origin.split(',')]
|
|
if line.created_purchase_request_line_id:
|
|
line.demand_plan_line_ids = line.created_purchase_request_line_id.demand_plan_line_id.ids
|
|
elif line.origin and 'MO' in line.origin:
|
|
mp_ids = self.env['mrp.production'].sudo().search([('name', '=', origin[0])])
|
|
line.demand_plan_line_ids = mp_ids.demand_plan_line_id.ids if mp_ids else []
|
|
elif line.origin and 'P' in line.origin:
|
|
purchase_order_ids = self.env['purchase.order'].sudo().search([('name', '=', origin[0])])
|
|
if purchase_order_ids.order_line:
|
|
line.demand_plan_line_ids = purchase_order_ids.order_line.demand_plan_line_id.ids
|
|
elif line.move_orig_ids:
|
|
demand_plan_lines = self.env['sf.production.demand.plan']
|
|
for move_orig in line.move_orig_ids:
|
|
demand_plan_lines |= move_orig.demand_plan_line_ids
|
|
line.demand_plan_line_ids = demand_plan_lines.ids
|
|
else:
|
|
line.demand_plan_line_ids = []
|
|
|
|
if not line.demand_plan_line_ids and self.env.context.get('demand_plan_line_id'):
|
|
plan_ids = self.env.context['demand_plan_line_id']
|
|
line.demand_plan_line_ids = [plan_ids]
|