1、销售订单供货方式为委外加工时生成的采购单问题优化
This commit is contained in:
@@ -9,9 +9,9 @@ class StockRuleInherit(models.Model):
|
||||
@api.model
|
||||
def _run_buy(self, procurements):
|
||||
# 判断补货组的采购类型
|
||||
procurements_group = {'standard': [], 'consignment': []}
|
||||
procurements_group = {'standard': [], 'outsourcing': []}
|
||||
for procurement, rule in procurements:
|
||||
is_consignment = False
|
||||
is_outsourcing = False
|
||||
product = procurement.product_id
|
||||
# 获取主 BOM
|
||||
bom = self.env['mrp.bom'].search([('product_tmpl_id', '=', product.product_tmpl_id.id)], limit=1)
|
||||
@@ -24,17 +24,17 @@ class StockRuleInherit(models.Model):
|
||||
for route in raw_material.route_ids:
|
||||
# print('route.name:', route.name)
|
||||
if route.name == '按订单补给外包商':
|
||||
is_consignment = True
|
||||
is_outsourcing = True
|
||||
|
||||
if is_consignment:
|
||||
procurements_group['consignment'].append((procurement, rule))
|
||||
if is_outsourcing:
|
||||
procurements_group['outsourcing'].append((procurement, rule))
|
||||
else:
|
||||
procurements_group['standard'].append((procurement, rule))
|
||||
|
||||
for key, value in procurements_group.items():
|
||||
super(StockRuleInherit, self)._run_buy(value)
|
||||
|
||||
if key == 'consignment':
|
||||
if key == 'outsourcing':
|
||||
for procurement, rule in value:
|
||||
supplier = procurement.values.get('supplier')
|
||||
if supplier:
|
||||
@@ -49,7 +49,7 @@ class StockRuleInherit(models.Model):
|
||||
], limit=1)
|
||||
logging.info("po=: %s", po)
|
||||
if po:
|
||||
po.write({'purchase_type': 'consignment'})
|
||||
po.write({'purchase_type': 'outsourcing'})
|
||||
|
||||
# # 首先调用父类的 _run_buy 方法,以保留原有逻辑
|
||||
# super(StockRuleInherit, self)._run_buy(procurements)
|
||||
@@ -83,5 +83,5 @@ class StockRuleInherit(models.Model):
|
||||
# ], limit=1)
|
||||
# logging.info("po=: %s", po)
|
||||
# if po:
|
||||
# po.write({'purchase_type': 'consignment'})
|
||||
# po.write({'purchase_type': 'outsourcing'})
|
||||
# break
|
||||
|
||||
@@ -30,7 +30,7 @@ class SFMessageSale(models.Model):
|
||||
purchase_order_info.add_queue('坯料采购提醒')
|
||||
purchase_order_ids = self.order_line.purchase_line_ids.order_id | self.procurement_group_id.stock_move_ids.created_purchase_line_id.order_id | self.procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id
|
||||
for purchase_order_id in purchase_order_ids:
|
||||
if purchase_order_id.purchase_type == 'consignment':
|
||||
if purchase_order_id.purchase_type == 'outsourcing':
|
||||
purchase_order_id.add_queue('委外加工采购单提醒')
|
||||
if purchase_order_id.purchase_type == 'standard':
|
||||
purchase_order_id.add_queue('外购订单采购单提醒')
|
||||
|
||||
@@ -170,9 +170,9 @@ class ReSaleOrder(models.Model):
|
||||
def _compute_purchase_order_count(self):
|
||||
for order in self:
|
||||
order.purchase_order_count = len(order._get_purchase_orders().filtered(
|
||||
lambda po: po.purchase_type not in ['consignment']))
|
||||
lambda po: po.purchase_type not in ['outsourcing']))
|
||||
order.consignment_purchase_order_count = len(order._get_purchase_orders().filtered(
|
||||
lambda po: po.purchase_type in ['consignment']))
|
||||
lambda po: po.purchase_type in ['outsourcing']))
|
||||
|
||||
def action_view_purchase_orders(self):
|
||||
"""
|
||||
@@ -180,7 +180,7 @@ class ReSaleOrder(models.Model):
|
||||
"""
|
||||
self.ensure_one()
|
||||
purchase_order_ids = self._get_purchase_orders().filtered(
|
||||
lambda po: po.purchase_type not in ['consignment']).ids
|
||||
lambda po: po.purchase_type not in ['outsourcing']).ids
|
||||
action = {
|
||||
'res_model': 'purchase.order',
|
||||
'type': 'ir.actions.act_window',
|
||||
@@ -203,21 +203,21 @@ class ReSaleOrder(models.Model):
|
||||
委外加工
|
||||
"""
|
||||
self.ensure_one()
|
||||
consignment_purchase_order_ids = self._get_purchase_orders().filtered(
|
||||
lambda po: po.purchase_type in ['consignment']).ids
|
||||
outsourcing_purchase_order_ids = self._get_purchase_orders().filtered(
|
||||
lambda po: po.purchase_type in ['outsourcing']).ids
|
||||
action = {
|
||||
'res_model': 'purchase.order',
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
if len(consignment_purchase_order_ids) == 1:
|
||||
if len(outsourcing_purchase_order_ids) == 1:
|
||||
action.update({
|
||||
'view_mode': 'form',
|
||||
'res_id': consignment_purchase_order_ids[0],
|
||||
'res_id': outsourcing_purchase_order_ids[0],
|
||||
})
|
||||
else:
|
||||
action.update({
|
||||
'name': _("从 %s生成委外加工订单", self.name),
|
||||
'domain': [('id', 'in', consignment_purchase_order_ids)],
|
||||
'domain': [('id', 'in', outsourcing_purchase_order_ids)],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
|
||||
Reference in New Issue
Block a user