物料需求计划管理
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
'views/sale_order_views.xml',
|
||||
'wizard/sf_demand_plan_print_wizard_view.xml',
|
||||
'wizard/sf_release_plan_wizard_views.xml',
|
||||
'views/menu_view.xml',
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
|
||||
@@ -19,3 +19,8 @@ class MrpProduction(models.Model):
|
||||
production.production_type = '人工线下加工'
|
||||
else:
|
||||
production.production_type = None
|
||||
|
||||
def _get_purchase_request(self):
|
||||
"""获取跟制造订单相关的采购申请单"""
|
||||
pr_ids = self.env['purchase.request'].sudo().search([('origin', '=', self.name)])
|
||||
return pr_ids
|
||||
|
||||
@@ -108,37 +108,49 @@ class SfProductionDemandPlan(models.Model):
|
||||
print_count = fields.Char('打印次数', default='T0C0', readonly=True)
|
||||
sequence = fields.Integer('序号')
|
||||
|
||||
hide_action_open_mrp_production = fields.Boolean(
|
||||
string='显示待工艺确认按钮',
|
||||
compute='_compute_hid_button',
|
||||
mrp_production_ids = fields.Many2many(
|
||||
'mrp.production',
|
||||
compute='_compute_mrp_production_ids',
|
||||
string='与此相需求计划关联的制造订单',
|
||||
store=True)
|
||||
|
||||
hide_release_production_order = fields.Boolean(
|
||||
string='显示下发生产按钮',
|
||||
compute='_compute_hide_release_production_order',
|
||||
default=False
|
||||
)
|
||||
|
||||
hide_action_purchase_orders = fields.Boolean(
|
||||
string='显示采购按钮',
|
||||
compute='_compute_hide_action_purchase_orders',
|
||||
default=False
|
||||
)
|
||||
|
||||
hide_action_stock_picking = fields.Boolean(
|
||||
string='显示调拨单按钮',
|
||||
compute='_compute_hide_action_stock_picking',
|
||||
default=False
|
||||
)
|
||||
|
||||
hide_action_outsourcing_stock_picking = fields.Boolean(
|
||||
string='委外显示调拨单按钮',
|
||||
compute='_compute_hide_action_stock_picking',
|
||||
default=False
|
||||
)
|
||||
|
||||
hide_action_view_programming = fields.Boolean(
|
||||
string='显示编程单按钮',
|
||||
compute='_compute_hid_button',
|
||||
default=False
|
||||
)
|
||||
|
||||
outsourcing_purchase_request = fields.Char('委外采购申请单')
|
||||
# hide_action_open_mrp_production = fields.Boolean(
|
||||
# string='显示待工艺确认按钮',
|
||||
# compute='_compute_hid_button',
|
||||
# default=False
|
||||
# )
|
||||
#
|
||||
# hide_action_purchase_orders = fields.Boolean(
|
||||
# string='显示采购按钮',
|
||||
# compute='_compute_hide_action_purchase_orders',
|
||||
# default=False
|
||||
# )
|
||||
#
|
||||
# hide_action_stock_picking = fields.Boolean(
|
||||
# string='显示调拨单按钮',
|
||||
# compute='_compute_hide_action_stock_picking',
|
||||
# default=False
|
||||
# )
|
||||
#
|
||||
# hide_action_outsourcing_stock_picking = fields.Boolean(
|
||||
# string='委外显示调拨单按钮',
|
||||
# compute='_compute_hide_action_stock_picking',
|
||||
# default=False
|
||||
# )
|
||||
#
|
||||
# hide_action_view_programming = fields.Boolean(
|
||||
# string='显示编程单按钮',
|
||||
# compute='_compute_hid_button',
|
||||
# default=False
|
||||
# )
|
||||
#
|
||||
# outsourcing_purchase_request = fields.Char('委外采购申请单')
|
||||
|
||||
plan_uom_qty = fields.Float(string="计划量")
|
||||
procurement_reason = fields.Selection([
|
||||
@@ -242,6 +254,20 @@ class SfProductionDemandPlan(models.Model):
|
||||
else:
|
||||
record.material_check = None
|
||||
|
||||
@api.depends('status')
|
||||
def _compute_mrp_production_ids(self):
|
||||
for record in self:
|
||||
record.mrp_production_ids = self.env['mrp.production'].sudo().search(
|
||||
[('demand_plan_line_id', '=', record.id)]).ids
|
||||
|
||||
@api.depends('mrp_production_ids.state')
|
||||
def _compute_hide_release_production_order(self):
|
||||
for record in self:
|
||||
# 检查这条需求计划所有制造订单的排程单状态,有一个为待排程状态,就显示改按钮
|
||||
record.hide_release_production_order = bool(record.mrp_production_ids.filtered(
|
||||
lambda p: p.state == 'confirmed'
|
||||
))
|
||||
|
||||
@api.constrains('planned_start_date')
|
||||
def _check_planned_start_date(self):
|
||||
for record in self:
|
||||
@@ -252,7 +278,7 @@ class SfProductionDemandPlan(models.Model):
|
||||
if not self.planned_start_date:
|
||||
raise ValidationError("请先填写计划开工日期")
|
||||
pro_plan_list = self.env['sf.production.plan'].search(
|
||||
[('product_id', '=', self.product_id.id), ('state', '=', 'draft')])
|
||||
[('production_id', 'in', self.mrp_production_ids.ids), ('state', '=', 'draft')])
|
||||
sf_production_line = self.env['sf.production.line'].sudo().search(
|
||||
[('name', '=', '1#CNC自动生产线')], limit=1)
|
||||
if sf_production_line:
|
||||
@@ -263,6 +289,11 @@ class SfProductionDemandPlan(models.Model):
|
||||
pro_plan_list.production_line_id = sf_production_line.id
|
||||
pro_plan_list.date_planned_start = date_planned_start
|
||||
self._do_production_schedule(pro_plan_list)
|
||||
self.status = '60'
|
||||
|
||||
def _do_production_schedule(self, pro_plan_list):
|
||||
for pro_plan in pro_plan_list:
|
||||
pro_plan.do_production_schedule()
|
||||
|
||||
def edit_button(self):
|
||||
self.ensure_one()
|
||||
@@ -278,10 +309,6 @@ class SfProductionDemandPlan(models.Model):
|
||||
action.update({'flags': {'mode': 'readonly'}})
|
||||
return action
|
||||
|
||||
def _do_production_schedule(self, pro_plan_list):
|
||||
for pro_plan in pro_plan_list:
|
||||
pro_plan.do_production_schedule()
|
||||
|
||||
def button_action_print(self):
|
||||
return {
|
||||
'res_model': 'sf.demand.plan.print.wizard',
|
||||
@@ -292,214 +319,214 @@ class SfProductionDemandPlan(models.Model):
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
@api.depends('sale_order_id.mrp_production_ids.state', 'sale_order_id.mrp_production_ids.programming_state')
|
||||
def _compute_hid_button(self):
|
||||
for record in self:
|
||||
mrp_production_ids = record.sale_order_id.mrp_production_ids.filtered(
|
||||
lambda p: p.state == 'technology_to_confirmed' and p.product_id.id == record.product_id.id
|
||||
)
|
||||
record.hide_action_open_mrp_production = bool(mrp_production_ids) and record.supply_method in (
|
||||
'automation', 'manual')
|
||||
programming_mrp_production_ids = record.sale_order_id.mrp_production_ids.filtered(
|
||||
lambda p: p.programming_state == '编程中' and p.product_id.id == record.product_id.id
|
||||
)
|
||||
record.hide_action_view_programming = bool(programming_mrp_production_ids)
|
||||
# @api.depends('sale_order_id.mrp_production_ids.state', 'sale_order_id.mrp_production_ids.programming_state')
|
||||
# def _compute_hid_button(self):
|
||||
# for record in self:
|
||||
# mrp_production_ids = record.sale_order_id.mrp_production_ids.filtered(
|
||||
# lambda p: p.state == 'technology_to_confirmed' and p.product_id.id == record.product_id.id
|
||||
# )
|
||||
# record.hide_action_open_mrp_production = bool(mrp_production_ids) and record.supply_method in (
|
||||
# 'automation', 'manual')
|
||||
# programming_mrp_production_ids = record.sale_order_id.mrp_production_ids.filtered(
|
||||
# lambda p: p.programming_state == '编程中' and p.product_id.id == record.product_id.id
|
||||
# )
|
||||
# record.hide_action_view_programming = bool(programming_mrp_production_ids)
|
||||
#
|
||||
# def _compute_hide_action_purchase_orders(self):
|
||||
# for record in self:
|
||||
# record.hide_action_purchase_orders = False
|
||||
# outsourcing_purchase_request = []
|
||||
# if record.supply_method in ('automation',
|
||||
# 'manual') and record.material_check == '0' and not record.sale_order_line_id.is_incoming_material:
|
||||
# mrp_production = record.sale_order_id.mrp_production_ids.filtered(
|
||||
# lambda p: p.product_id.id == record.product_id.id
|
||||
# ).sorted(key=lambda p: p.id)
|
||||
# if mrp_production:
|
||||
# raw_materials = mrp_production.mapped('move_raw_ids.product_id')
|
||||
# if raw_materials:
|
||||
# purchase_orders = self.env['purchase.order'].sudo().search([
|
||||
# ('state', '=', 'purchase'),
|
||||
# ('order_line.product_id', 'in', raw_materials.ids)
|
||||
# ])
|
||||
# total_purchase_quantity = sum(
|
||||
# sum(
|
||||
# order.order_line.filtered(
|
||||
# lambda line: line.product_id in raw_materials
|
||||
# ).mapped('product_qty')
|
||||
# )
|
||||
# for order in purchase_orders
|
||||
# )
|
||||
# if float_compare(total_purchase_quantity, record.product_uom_qty,
|
||||
# precision_rounding=record.product_id.uom_id.rounding) == -1:
|
||||
# pr_ids = self.env['purchase.request'].sudo().search(
|
||||
# [('line_ids.product_id', 'in', raw_materials.ids), ('state', '!=', 'done')])
|
||||
# outsourcing_purchase_request.extend(pr_ids.ids)
|
||||
# elif record.supply_method in ('purchase', 'outsourcing'):
|
||||
# purchase_orders = self.env['purchase.order'].sudo().search([
|
||||
# ('state', 'in', ('purchase', 'done')),
|
||||
# ('order_line.product_id', '=', record.product_id.id)
|
||||
# ])
|
||||
# total_purchase_quantity = sum(
|
||||
# sum(
|
||||
# order.order_line.filtered(
|
||||
# lambda line: line.product_id in record.product_id
|
||||
# ).mapped('product_qty')
|
||||
# )
|
||||
# for order in purchase_orders
|
||||
# )
|
||||
#
|
||||
# if float_compare(total_purchase_quantity, record.product_uom_qty,
|
||||
# precision_rounding=record.product_id.uom_id.rounding) == -1:
|
||||
# pr_ids = self.env['purchase.request'].sudo().search(
|
||||
# [('origin', 'like', record.sale_order_id.name), ('state', '!=', 'done')])
|
||||
# outsourcing_purchase_request.extend(pr_ids.ids)
|
||||
# if record.supply_method == 'outsourcing' and not record.sale_order_line_id.is_incoming_material:
|
||||
# bom_line_ids = record.product_id.bom_ids.bom_line_ids
|
||||
# if bom_line_ids:
|
||||
# # BOM_数量
|
||||
# total_product_qty = sum(line.product_qty for line in bom_line_ids)
|
||||
# bom_product_ids = bom_line_ids.mapped('product_id')
|
||||
# product_purchase_orders = self.env['purchase.order'].sudo().search([
|
||||
# ('state', 'in', ('purchase', 'done')),
|
||||
# ('order_line.product_id', 'in', bom_product_ids.ids)
|
||||
# ])
|
||||
# # 购订单_数量
|
||||
# total_outsourcing_purchase_quantity = sum(
|
||||
# sum(
|
||||
# order.order_line.filtered(
|
||||
# lambda line: line.product_id in bom_product_ids
|
||||
# ).mapped('product_qty')
|
||||
# )
|
||||
# for order in product_purchase_orders
|
||||
# )
|
||||
# quantity = total_outsourcing_purchase_quantity / total_product_qty
|
||||
# if float_compare(quantity, record.product_uom_qty,
|
||||
# precision_rounding=record.product_id.uom_id.rounding) == -1:
|
||||
# purchase_request = self.env['purchase.request'].sudo().search(
|
||||
# [('line_ids.product_id', 'in', bom_product_ids.ids),
|
||||
# ('line_ids.purchase_state', 'not in', ('purchase', 'done')), ('state', '!=', 'done')])
|
||||
# outsourcing_purchase_request.extend(purchase_request.ids)
|
||||
# record.outsourcing_purchase_request = json.dumps(outsourcing_purchase_request)
|
||||
# if outsourcing_purchase_request:
|
||||
# record.hide_action_purchase_orders = True
|
||||
#
|
||||
# @api.depends('sale_order_id.mrp_production_ids.picking_ids.state', 'sale_order_id.picking_ids.state')
|
||||
# def _compute_hide_action_stock_picking(self):
|
||||
# for record in self:
|
||||
# record.hide_action_stock_picking = False
|
||||
# record.hide_action_outsourcing_stock_picking = False
|
||||
# if record.supply_method in ('automation', 'manual'):
|
||||
# manufacturing_orders = record.sale_order_id.mrp_production_ids.filtered(
|
||||
# lambda p: p.product_id.id == record.product_id.id
|
||||
# )
|
||||
# record.hide_action_stock_picking = bool(manufacturing_orders.mapped('picking_ids').filtered(
|
||||
# lambda p: p.state == 'assigned'))
|
||||
# elif record.supply_method in ('purchase', 'outsourcing'):
|
||||
# assigned_picking_ids = record.sale_order_id.picking_ids.filtered(
|
||||
# lambda
|
||||
# p: p.state == 'assigned' and p.picking_type_id.name != '发料出库' and p.move_line_ids.product_id in record.product_id)
|
||||
# if record.supply_method == 'outsourcing':
|
||||
# outsourcing_assigned_picking_ids = record.get_outsourcing_picking_ids()
|
||||
# record.hide_action_outsourcing_stock_picking = outsourcing_assigned_picking_ids
|
||||
# record.hide_action_stock_picking = assigned_picking_ids or outsourcing_assigned_picking_ids
|
||||
# else:
|
||||
# record.hide_action_stock_picking = assigned_picking_ids
|
||||
#
|
||||
# def get_outsourcing_picking_ids(self):
|
||||
# order_ids = self.env['purchase.order'].sudo().search(
|
||||
# [('order_line.product_id', 'in', self.product_id.ids),
|
||||
# ('purchase_type', '=', 'outsourcing')])
|
||||
# outsourcing_picking_ids = order_ids._get_subcontracting_resupplies()
|
||||
# outsourcing_assigned_picking_ids = outsourcing_picking_ids.filtered(lambda p: p.state == 'assigned')
|
||||
# return outsourcing_assigned_picking_ids
|
||||
|
||||
def _compute_hide_action_purchase_orders(self):
|
||||
for record in self:
|
||||
record.hide_action_purchase_orders = False
|
||||
outsourcing_purchase_request = []
|
||||
if record.supply_method in ('automation',
|
||||
'manual') and record.material_check == '0' and not record.sale_order_line_id.is_incoming_material:
|
||||
mrp_production = record.sale_order_id.mrp_production_ids.filtered(
|
||||
lambda p: p.product_id.id == record.product_id.id
|
||||
).sorted(key=lambda p: p.id)
|
||||
if mrp_production:
|
||||
raw_materials = mrp_production.mapped('move_raw_ids.product_id')
|
||||
if raw_materials:
|
||||
purchase_orders = self.env['purchase.order'].sudo().search([
|
||||
('state', '=', 'purchase'),
|
||||
('order_line.product_id', 'in', raw_materials.ids)
|
||||
])
|
||||
total_purchase_quantity = sum(
|
||||
sum(
|
||||
order.order_line.filtered(
|
||||
lambda line: line.product_id in raw_materials
|
||||
).mapped('product_qty')
|
||||
)
|
||||
for order in purchase_orders
|
||||
)
|
||||
if float_compare(total_purchase_quantity, record.product_uom_qty,
|
||||
precision_rounding=record.product_id.uom_id.rounding) == -1:
|
||||
pr_ids = self.env['purchase.request'].sudo().search(
|
||||
[('line_ids.product_id', 'in', raw_materials.ids), ('state', '!=', 'done')])
|
||||
outsourcing_purchase_request.extend(pr_ids.ids)
|
||||
elif record.supply_method in ('purchase', 'outsourcing'):
|
||||
purchase_orders = self.env['purchase.order'].sudo().search([
|
||||
('state', 'in', ('purchase', 'done')),
|
||||
('order_line.product_id', '=', record.product_id.id)
|
||||
])
|
||||
total_purchase_quantity = sum(
|
||||
sum(
|
||||
order.order_line.filtered(
|
||||
lambda line: line.product_id in record.product_id
|
||||
).mapped('product_qty')
|
||||
)
|
||||
for order in purchase_orders
|
||||
)
|
||||
# def action_open_sale_order(self):
|
||||
# self.ensure_one()
|
||||
# return {
|
||||
# 'type': 'ir.actions.act_window',
|
||||
# 'res_model': 'sale.order',
|
||||
# 'res_id': self.sale_order_id.id,
|
||||
# 'view_mode': 'form',
|
||||
# }
|
||||
|
||||
if float_compare(total_purchase_quantity, record.product_uom_qty,
|
||||
precision_rounding=record.product_id.uom_id.rounding) == -1:
|
||||
pr_ids = self.env['purchase.request'].sudo().search(
|
||||
[('origin', 'like', record.sale_order_id.name), ('state', '!=', 'done')])
|
||||
outsourcing_purchase_request.extend(pr_ids.ids)
|
||||
if record.supply_method == 'outsourcing' and not record.sale_order_line_id.is_incoming_material:
|
||||
bom_line_ids = record.product_id.bom_ids.bom_line_ids
|
||||
if bom_line_ids:
|
||||
# BOM_数量
|
||||
total_product_qty = sum(line.product_qty for line in bom_line_ids)
|
||||
bom_product_ids = bom_line_ids.mapped('product_id')
|
||||
product_purchase_orders = self.env['purchase.order'].sudo().search([
|
||||
('state', 'in', ('purchase', 'done')),
|
||||
('order_line.product_id', 'in', bom_product_ids.ids)
|
||||
])
|
||||
# 购订单_数量
|
||||
total_outsourcing_purchase_quantity = sum(
|
||||
sum(
|
||||
order.order_line.filtered(
|
||||
lambda line: line.product_id in bom_product_ids
|
||||
).mapped('product_qty')
|
||||
)
|
||||
for order in product_purchase_orders
|
||||
)
|
||||
quantity = total_outsourcing_purchase_quantity / total_product_qty
|
||||
if float_compare(quantity, record.product_uom_qty,
|
||||
precision_rounding=record.product_id.uom_id.rounding) == -1:
|
||||
purchase_request = self.env['purchase.request'].sudo().search(
|
||||
[('line_ids.product_id', 'in', bom_product_ids.ids),
|
||||
('line_ids.purchase_state', 'not in', ('purchase', 'done')), ('state', '!=', 'done')])
|
||||
outsourcing_purchase_request.extend(purchase_request.ids)
|
||||
record.outsourcing_purchase_request = json.dumps(outsourcing_purchase_request)
|
||||
if outsourcing_purchase_request:
|
||||
record.hide_action_purchase_orders = True
|
||||
# def action_open_mrp_production(self):
|
||||
# self.ensure_one()
|
||||
# mrp_production_ids = self.sale_order_id.mrp_production_ids.filtered(
|
||||
# lambda p: p.state == 'technology_to_confirmed' and p.product_id.id == self.product_id.id
|
||||
# )
|
||||
# action = {
|
||||
# 'res_model': 'mrp.production',
|
||||
# 'type': 'ir.actions.act_window',
|
||||
# }
|
||||
# if len(mrp_production_ids) == 1:
|
||||
# action.update({
|
||||
# 'view_mode': 'form',
|
||||
# 'res_id': mrp_production_ids.id,
|
||||
# })
|
||||
# else:
|
||||
# action.update({
|
||||
# 'name': _("制造订单列表"),
|
||||
# 'domain': [('id', 'in', mrp_production_ids.ids)],
|
||||
# 'view_mode': 'tree,form',
|
||||
# })
|
||||
# return action
|
||||
|
||||
@api.depends('sale_order_id.mrp_production_ids.picking_ids.state', 'sale_order_id.picking_ids.state')
|
||||
def _compute_hide_action_stock_picking(self):
|
||||
for record in self:
|
||||
record.hide_action_stock_picking = False
|
||||
record.hide_action_outsourcing_stock_picking = False
|
||||
if record.supply_method in ('automation', 'manual'):
|
||||
manufacturing_orders = record.sale_order_id.mrp_production_ids.filtered(
|
||||
lambda p: p.product_id.id == record.product_id.id
|
||||
)
|
||||
record.hide_action_stock_picking = bool(manufacturing_orders.mapped('picking_ids').filtered(
|
||||
lambda p: p.state == 'assigned'))
|
||||
elif record.supply_method in ('purchase', 'outsourcing'):
|
||||
assigned_picking_ids = record.sale_order_id.picking_ids.filtered(
|
||||
lambda
|
||||
p: p.state == 'assigned' and p.picking_type_id.name != '发料出库' and p.move_line_ids.product_id in record.product_id)
|
||||
if record.supply_method == 'outsourcing':
|
||||
outsourcing_assigned_picking_ids = record.get_outsourcing_picking_ids()
|
||||
record.hide_action_outsourcing_stock_picking = outsourcing_assigned_picking_ids
|
||||
record.hide_action_stock_picking = assigned_picking_ids or outsourcing_assigned_picking_ids
|
||||
else:
|
||||
record.hide_action_stock_picking = assigned_picking_ids
|
||||
# def action_view_purchase_request(self):
|
||||
# self.ensure_one()
|
||||
# pr_ids = self.env['purchase.request'].sudo().search(
|
||||
# [('id', 'in', ast.literal_eval(self.outsourcing_purchase_request))])
|
||||
# action = {
|
||||
# 'res_model': 'purchase.request',
|
||||
# 'type': 'ir.actions.act_window',
|
||||
# }
|
||||
# if len(pr_ids) == 1:
|
||||
# action.update({
|
||||
# 'view_mode': 'form',
|
||||
# 'res_id': pr_ids[0].id,
|
||||
# })
|
||||
# else:
|
||||
# action.update({
|
||||
# 'name': _("采购申请"),
|
||||
# 'domain': [('id', 'in', pr_ids.ids)],
|
||||
# 'view_mode': 'tree,form',
|
||||
# })
|
||||
# return action
|
||||
|
||||
def get_outsourcing_picking_ids(self):
|
||||
order_ids = self.env['purchase.order'].sudo().search(
|
||||
[('order_line.product_id', 'in', self.product_id.ids),
|
||||
('purchase_type', '=', 'outsourcing')])
|
||||
outsourcing_picking_ids = order_ids._get_subcontracting_resupplies()
|
||||
outsourcing_assigned_picking_ids = outsourcing_picking_ids.filtered(lambda p: p.state == 'assigned')
|
||||
return outsourcing_assigned_picking_ids
|
||||
# def action_view_stock_picking(self):
|
||||
# self.ensure_one()
|
||||
# action = self.env["ir.actions.actions"]._for_xml_id("stock.action_picking_tree_all")
|
||||
# picking_ids = None
|
||||
# if self.supply_method in ('automation', 'manual'):
|
||||
# mrp_production_ids = self.sale_order_id.mrp_production_ids.filtered(
|
||||
# lambda p: p.product_id.id == self.product_id.id
|
||||
# )
|
||||
# picking_ids = mrp_production_ids.mapped('picking_ids').filtered(
|
||||
# lambda p: p.state == 'assigned')
|
||||
# elif self.supply_method in ('purchase', 'outsourcing'):
|
||||
# picking_ids = self.sale_order_id.picking_ids.filtered(
|
||||
# lambda
|
||||
# p: p.state == 'assigned' and p.picking_type_id.name != '发料出库' and p.move_line_ids.product_id in self.product_id)
|
||||
# if self.supply_method == 'outsourcing' and self.hide_action_outsourcing_stock_picking:
|
||||
# picking_ids = picking_ids.union(self.get_outsourcing_picking_ids())
|
||||
# if picking_ids:
|
||||
# if len(picking_ids) > 1:
|
||||
# action['domain'] = [('id', 'in', picking_ids.ids)]
|
||||
# elif picking_ids:
|
||||
# action['res_id'] = picking_ids.id
|
||||
# action['views'] = [(self.env.ref('stock.view_picking_form').id, 'form')]
|
||||
# if 'views' in action:
|
||||
# action['views'] += [(state, view) for state, view in action['views'] if view != 'form']
|
||||
# return action
|
||||
|
||||
def action_open_sale_order(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'sale.order',
|
||||
'res_id': self.sale_order_id.id,
|
||||
'view_mode': 'form',
|
||||
}
|
||||
|
||||
def action_open_mrp_production(self):
|
||||
self.ensure_one()
|
||||
mrp_production_ids = self.sale_order_id.mrp_production_ids.filtered(
|
||||
lambda p: p.state == 'technology_to_confirmed' and p.product_id.id == self.product_id.id
|
||||
)
|
||||
action = {
|
||||
'res_model': 'mrp.production',
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
if len(mrp_production_ids) == 1:
|
||||
action.update({
|
||||
'view_mode': 'form',
|
||||
'res_id': mrp_production_ids.id,
|
||||
})
|
||||
else:
|
||||
action.update({
|
||||
'name': _("制造订单列表"),
|
||||
'domain': [('id', 'in', mrp_production_ids.ids)],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
|
||||
def action_view_purchase_request(self):
|
||||
self.ensure_one()
|
||||
pr_ids = self.env['purchase.request'].sudo().search(
|
||||
[('id', 'in', ast.literal_eval(self.outsourcing_purchase_request))])
|
||||
action = {
|
||||
'res_model': 'purchase.request',
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
if len(pr_ids) == 1:
|
||||
action.update({
|
||||
'view_mode': 'form',
|
||||
'res_id': pr_ids[0].id,
|
||||
})
|
||||
else:
|
||||
action.update({
|
||||
'name': _("采购申请"),
|
||||
'domain': [('id', 'in', pr_ids.ids)],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
|
||||
def action_view_stock_picking(self):
|
||||
self.ensure_one()
|
||||
action = self.env["ir.actions.actions"]._for_xml_id("stock.action_picking_tree_all")
|
||||
picking_ids = None
|
||||
if self.supply_method in ('automation', 'manual'):
|
||||
mrp_production_ids = self.sale_order_id.mrp_production_ids.filtered(
|
||||
lambda p: p.product_id.id == self.product_id.id
|
||||
)
|
||||
picking_ids = mrp_production_ids.mapped('picking_ids').filtered(
|
||||
lambda p: p.state == 'assigned')
|
||||
elif self.supply_method in ('purchase', 'outsourcing'):
|
||||
picking_ids = self.sale_order_id.picking_ids.filtered(
|
||||
lambda
|
||||
p: p.state == 'assigned' and p.picking_type_id.name != '发料出库' and p.move_line_ids.product_id in self.product_id)
|
||||
if self.supply_method == 'outsourcing' and self.hide_action_outsourcing_stock_picking:
|
||||
picking_ids = picking_ids.union(self.get_outsourcing_picking_ids())
|
||||
if picking_ids:
|
||||
if len(picking_ids) > 1:
|
||||
action['domain'] = [('id', 'in', picking_ids.ids)]
|
||||
elif picking_ids:
|
||||
action['res_id'] = picking_ids.id
|
||||
action['views'] = [(self.env.ref('stock.view_picking_form').id, 'form')]
|
||||
if 'views' in action:
|
||||
action['views'] += [(state, view) for state, view in action['views'] if view != 'form']
|
||||
return action
|
||||
|
||||
def action_view_programming(self):
|
||||
self.ensure_one()
|
||||
programming_mrp_production_ids = self.sale_order_id.mrp_production_ids.filtered(
|
||||
lambda p: p.programming_state == '编程中' and p.product_id.id == self.product_id.id
|
||||
).mapped('programming_no')
|
||||
if programming_mrp_production_ids:
|
||||
programming_no = list(set(programming_mrp_production_ids))
|
||||
numbers_str = "、".join(programming_no)
|
||||
raise ValidationError(f"编程单号:{numbers_str},请去云平台处理")
|
||||
# def action_view_programming(self):
|
||||
# self.ensure_one()
|
||||
# programming_mrp_production_ids = self.sale_order_id.mrp_production_ids.filtered(
|
||||
# lambda p: p.programming_state == '编程中' and p.product_id.id == self.product_id.id
|
||||
# ).mapped('programming_no')
|
||||
# if programming_mrp_production_ids:
|
||||
# programming_no = list(set(programming_mrp_production_ids))
|
||||
# numbers_str = "、".join(programming_no)
|
||||
# raise ValidationError(f"编程单号:{numbers_str},请去云平台处理")
|
||||
|
||||
def button_delete(self):
|
||||
self.ensure_one()
|
||||
|
||||
15
sf_demand_plan/models/sf_production_plan.py
Normal file
15
sf_demand_plan/models/sf_production_plan.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields, api, _
|
||||
|
||||
|
||||
class SfProductionPlan(models.Model):
|
||||
_inherit = 'sf.production.plan'
|
||||
|
||||
demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan",
|
||||
string="需求计划明细", readonly=True)
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
res = super(SfProductionPlan, self).create(vals)
|
||||
res.demand_plan_line_id = res.production_id.demand_plan_line_id.id
|
||||
return res
|
||||
@@ -46,20 +46,20 @@
|
||||
<field name="plan_remark"/>
|
||||
<field name="processing_time"/>
|
||||
<field name="material_check" optional="hide"/>
|
||||
<field name="hide_action_open_mrp_production" invisible="1"/>
|
||||
<field name="hide_action_purchase_orders" invisible="1"/>
|
||||
<field name="hide_action_stock_picking" invisible="1"/>
|
||||
<field name="hide_action_view_programming" invisible="1"/>
|
||||
<button name="action_open_sale_order" type="object" string="供货方式待确认" class="btn-secondary"
|
||||
attrs="{'invisible': [('supply_method', '!=', False)]}"/>
|
||||
<button name="action_open_mrp_production" type="object" string="待工艺确认" class="btn-secondary"
|
||||
attrs="{'invisible': [('hide_action_open_mrp_production', '=', False)]}"/>
|
||||
<button name="action_view_purchase_request" type="object" string="采购申请" class="btn-secondary"
|
||||
attrs="{'invisible': [('hide_action_purchase_orders', '=', False)]}"/>
|
||||
<button name="action_view_stock_picking" type="object" string="调拨单" class="btn-secondary"
|
||||
attrs="{'invisible': [('hide_action_stock_picking', '=', False)]}"/>
|
||||
<button name="action_view_programming" type="object" string="编程单" class="btn-secondary"
|
||||
attrs="{'invisible': [('hide_action_view_programming', '=', False)]}"/>
|
||||
<!-- <field name="hide_action_open_mrp_production" invisible="1"/>-->
|
||||
<!-- <field name="hide_action_purchase_orders" invisible="1"/>-->
|
||||
<!-- <field name="hide_action_stock_picking" invisible="1"/>-->
|
||||
<!-- <field name="hide_action_view_programming" invisible="1"/>-->
|
||||
<!-- <button name="action_open_sale_order" type="object" string="供货方式待确认" class="btn-secondary"-->
|
||||
<!-- attrs="{'invisible': [('supply_method', '!=', False)]}"/>-->
|
||||
<!-- <button name="action_open_mrp_production" type="object" string="待工艺确认" class="btn-secondary"-->
|
||||
<!-- attrs="{'invisible': [('hide_action_open_mrp_production', '=', False)]}"/>-->
|
||||
<!-- <button name="action_view_purchase_request" type="object" string="采购申请" class="btn-secondary"-->
|
||||
<!-- attrs="{'invisible': [('hide_action_purchase_orders', '=', False)]}"/>-->
|
||||
<!-- <button name="action_view_stock_picking" type="object" string="调拨单" class="btn-secondary"-->
|
||||
<!-- attrs="{'invisible': [('hide_action_stock_picking', '=', False)]}"/>-->
|
||||
<!-- <button name="action_view_programming" type="object" string="编程单" class="btn-secondary"-->
|
||||
<!-- attrs="{'invisible': [('hide_action_view_programming', '=', False)]}"/>-->
|
||||
<field name="planned_start_date"/>
|
||||
<field name="actual_start_date"/>
|
||||
<field name="actual_end_date"/>
|
||||
@@ -68,9 +68,10 @@
|
||||
<field name="write_date" string="更新时间"/>
|
||||
<field name="write_uid" optional="hide" string="更新人"/>
|
||||
<field name="print_count"/>
|
||||
<button name="release_production_order" type="object" string="下达生产" class="btn-primary"
|
||||
attrs="{'invisible': ['|',('status', '!=', '50'), ('supply_method', 'not in', ['automation', 'manual'])]}"/>
|
||||
|
||||
<field name="hide_release_production_order" invisible="1"/>
|
||||
<button name="release_production_order" type="object" string="下发生产" class="btn-primary"
|
||||
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
||||
/>
|
||||
<button name="edit_button" type="object" string="拆分" class="btn-primary"/>
|
||||
</tree>
|
||||
</field>
|
||||
@@ -118,12 +119,4 @@
|
||||
<field name="view_mode">tree</field>
|
||||
</record>
|
||||
|
||||
|
||||
<menuitem
|
||||
id="demand_plan_menu"
|
||||
name="需求计划"
|
||||
sequence="140"
|
||||
action="sf_production_demand_plan_action"
|
||||
parent="sf_plan.sf_production_plan_menu"
|
||||
/>
|
||||
</odoo>
|
||||
@@ -54,10 +54,15 @@
|
||||
<field name="plan_remark"/>
|
||||
<field name="procurement_reason"/>
|
||||
<field name="write_date" string="更新时间"/>
|
||||
<field name="hide_release_production_order" invisible="1"/>
|
||||
<button string="下达计划" name="button_release_plan" type="object"
|
||||
class="btn-primary"
|
||||
attrs="{'invisible': [('status', 'in', ('50','60','100'))]}"
|
||||
/>
|
||||
<button name="release_production_order" type="object" string="下发生产"
|
||||
class="btn-primary"
|
||||
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
||||
/>
|
||||
<button name="button_delete" type="object" string="删除"
|
||||
class="btn-primary"
|
||||
attrs="{'invisible': [('status', 'not in', ('10','20','30'))]}"
|
||||
|
||||
18
sf_demand_plan/views/menu_view.xml
Normal file
18
sf_demand_plan/views/menu_view.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<menuitem
|
||||
id="demand_plan_menu"
|
||||
name="需求计划"
|
||||
sequence="140"
|
||||
action="sf_demand_plan.sf_production_demand_plan_action"
|
||||
parent="sf_plan.sf_production_plan_menu"
|
||||
/>
|
||||
|
||||
<!-- 调拨动作中屏蔽验证-->
|
||||
<record id="stock.action_validate_picking" model="ir.actions.server">
|
||||
<field name="binding_model_id" eval="False"/>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user