采购单根据采购类型拆分
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
from itertools import groupby
|
||||
from odoo import models, fields, api, _
|
||||
|
||||
|
||||
@@ -7,11 +8,10 @@ class StockRuleInherit(models.Model):
|
||||
|
||||
@api.model
|
||||
def _run_buy(self, procurements):
|
||||
# 首先调用父类的 _run_buy 方法,以保留原有逻辑
|
||||
super(StockRuleInherit, self)._run_buy(procurements)
|
||||
|
||||
# 然后在这里添加自定义的逻辑
|
||||
# 判断补货组的采购类型
|
||||
procurements_group = {'standard': [], 'consignment': []}
|
||||
for procurement, rule in procurements:
|
||||
is_consignment = False
|
||||
product = procurement.product_id
|
||||
# 获取主 BOM
|
||||
bom = self.env['mrp.bom'].search([('product_tmpl_id', '=', product.product_tmpl_id.id)], limit=1)
|
||||
@@ -23,21 +23,65 @@ class StockRuleInherit(models.Model):
|
||||
# 检查路线
|
||||
for route in raw_material.route_ids:
|
||||
# print('route.name:', route.name)
|
||||
if route.name == '按订单补给外包商': # 或者用 route.id 检查精确的路线
|
||||
print("按订单补给外包商============是")
|
||||
# 使用 procurement.values['supplier'] 获取供应商
|
||||
supplier = procurement.values.get('supplier')
|
||||
if supplier:
|
||||
domain = rule._make_po_get_domain(procurement.company_id, procurement.values,
|
||||
supplier.partner_id)
|
||||
logging.info("domain=============: %s", domain)
|
||||
po = self.env['purchase.order'].sudo().search([
|
||||
('partner_id', '=', supplier.partner_id.id),
|
||||
('company_id', '=', procurement.company_id.id), # 保证公司一致
|
||||
('origin', '=', procurement.origin), # 根据来源匹配
|
||||
('state', '=', 'draft') # 状态为草稿
|
||||
], limit=1)
|
||||
logging.info("po=: %s", po)
|
||||
if po:
|
||||
po.write({'purchase_type': 'consignment'})
|
||||
break
|
||||
if route.name == '按订单补给外包商':
|
||||
is_consignment = True
|
||||
|
||||
if is_consignment:
|
||||
procurements_group['consignment'].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':
|
||||
for procurement, rule in value:
|
||||
supplier = procurement.values.get('supplier')
|
||||
if supplier:
|
||||
domain = rule._make_po_get_domain(procurement.company_id, procurement.values,
|
||||
supplier.partner_id)
|
||||
logging.info("domain=============: %s", domain)
|
||||
po = self.env['purchase.order'].sudo().search([
|
||||
('partner_id', '=', supplier.partner_id.id),
|
||||
('company_id', '=', procurement.company_id.id), # 保证公司一致
|
||||
('origin', '=', procurement.origin), # 根据来源匹配
|
||||
('state', '=', 'draft') # 状态为草稿
|
||||
], limit=1)
|
||||
logging.info("po=: %s", po)
|
||||
if po:
|
||||
po.write({'purchase_type': 'consignment'})
|
||||
|
||||
# # 首先调用父类的 _run_buy 方法,以保留原有逻辑
|
||||
# super(StockRuleInherit, self)._run_buy(procurements)
|
||||
|
||||
# 然后在这里添加自定义的逻辑
|
||||
# for procurement, rule in procurements:
|
||||
# product = procurement.product_id
|
||||
# # 获取主 BOM
|
||||
# bom = self.env['mrp.bom'].search([('product_tmpl_id', '=', product.product_tmpl_id.id)], limit=1)
|
||||
|
||||
# if bom:
|
||||
# # 遍历 BOM 中的组件(即坯料等)
|
||||
# for line in bom.bom_line_ids:
|
||||
# raw_material = line.product_id
|
||||
# # 检查路线
|
||||
# for route in raw_material.route_ids:
|
||||
# # print('route.name:', route.name)
|
||||
# if route.name == '按订单补给外包商': # 或者用 route.id 检查精确的路线
|
||||
# print("按订单补给外包商============是")
|
||||
# # 使用 procurement.values['supplier'] 获取供应商
|
||||
# supplier = procurement.values.get('supplier')
|
||||
# if supplier:
|
||||
# domain = rule._make_po_get_domain(procurement.company_id, procurement.values,
|
||||
# supplier.partner_id)
|
||||
# logging.info("domain=============: %s", domain)
|
||||
# po = self.env['purchase.order'].sudo().search([
|
||||
# ('partner_id', '=', supplier.partner_id.id),
|
||||
# ('company_id', '=', procurement.company_id.id), # 保证公司一致
|
||||
# ('origin', '=', procurement.origin), # 根据来源匹配
|
||||
# ('state', '=', 'draft') # 状态为草稿
|
||||
# ], limit=1)
|
||||
# logging.info("po=: %s", po)
|
||||
# if po:
|
||||
# po.write({'purchase_type': 'consignment'})
|
||||
# break
|
||||
|
||||
@@ -1442,6 +1442,30 @@ class MrpProduction(models.Model):
|
||||
])
|
||||
order.delivery_count = len(order.picking_ids)
|
||||
|
||||
def action_view_purchase_orders(self):
|
||||
self.ensure_one()
|
||||
if self.product_id.product_tmpl_id.single_manufacturing == True:
|
||||
production = self.env['mrp.production'].search([('origin', '=', self.origin), ('product_id', '=', self.product_id.id)], limit=1, order='id asc')
|
||||
else:
|
||||
production = self
|
||||
purchase_order_ids = (production.procurement_group_id.stock_move_ids.created_purchase_line_id.order_id | production.procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id).ids
|
||||
action = {
|
||||
'res_model': 'purchase.order',
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
if len(purchase_order_ids) == 1:
|
||||
action.update({
|
||||
'view_mode': 'form',
|
||||
'res_id': purchase_order_ids[0],
|
||||
})
|
||||
else:
|
||||
action.update({
|
||||
'name': _("Purchase Order generated from %s", self.name),
|
||||
'domain': [('id', 'in', purchase_order_ids)],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
|
||||
class sf_detection_result(models.Model):
|
||||
_name = 'sf.detection.result'
|
||||
_description = "检测结果"
|
||||
|
||||
@@ -4,5 +4,4 @@ from . import quick_easy_order_old
|
||||
from . import auto_quatotion_common
|
||||
from . import parser_and_calculate_work_time
|
||||
from . import preload_datas_functions
|
||||
from . import stock_move
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
from odoo import models, fields, api
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = 'stock.move'
|
||||
|
||||
@api.model
|
||||
def _prepare_merge_negative_moves_excluded_distinct_fields(self):
|
||||
excluded_fields = super()._prepare_merge_negative_moves_excluded_distinct_fields() + ['pruchase_type']
|
||||
return excluded_fields
|
||||
Reference in New Issue
Block a user