库存移动新增需求计划关联
This commit is contained in:
@@ -9,3 +9,4 @@ from . import mrp_production
|
||||
from . import stock_rule
|
||||
from . import purchase_request
|
||||
from . import purchase_order
|
||||
from . import stock_move
|
||||
|
||||
@@ -922,6 +922,11 @@ class SfProductionDemandPlan(models.Model):
|
||||
], limit=1))
|
||||
|
||||
def button_plan_detail(self):
|
||||
self.ensure_one()
|
||||
purchase_request_ids = self.env['purchase.request'].sudo().search(
|
||||
[('line_ids.demand_plan_line_id', 'in', self.ids)])
|
||||
purchase_order_ids = self.env['purchase.order'].sudo().search(
|
||||
[('order_line.demand_plan_line_id', 'in', self.ids)])
|
||||
return {
|
||||
'name': _('详情'),
|
||||
'type': 'ir.actions.act_window',
|
||||
@@ -930,6 +935,18 @@ class SfProductionDemandPlan(models.Model):
|
||||
'target': 'new',
|
||||
'views': [(False, 'form')],
|
||||
'context': {
|
||||
'default_demand_plan_line_ids': self.ids,
|
||||
'default_mrp_production_ids': self.mrp_production_ids.ids,
|
||||
'default_purchase_request_ids': purchase_request_ids.ids,
|
||||
'default_standard_purchase_order_ids': purchase_order_ids.filtered(
|
||||
lambda o: o.purchase_type == 'standard'
|
||||
).ids,
|
||||
'default_consignment_purchase_order_ids': purchase_order_ids.filtered(
|
||||
lambda o: o.purchase_type == 'consignment'
|
||||
).ids,
|
||||
'default_outsourcing_purchase_order_ids': purchase_order_ids.filtered(
|
||||
lambda o: o.purchase_type == 'outsourcing'
|
||||
).ids,
|
||||
'default_outside_purchase_order_ids': purchase_order_ids.filtered(
|
||||
lambda o: o.purchase_type == 'outside'
|
||||
).ids,
|
||||
}}
|
||||
|
||||
37
sf_demand_plan/models/stock_move.py
Normal file
37
sf_demand_plan/models/stock_move.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# -*- 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]
|
||||
Reference in New Issue
Block a user