Accept Merge Request #1551: (feature/sale_order_route_pick -> develop)
Merge Request: 采购单根据采购类型拆分 Created By: @胡尧 Accepted By: @胡尧 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1551
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
from itertools import groupby
|
||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
|
|
||||||
|
|
||||||
@@ -7,11 +8,10 @@ class StockRuleInherit(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _run_buy(self, procurements):
|
def _run_buy(self, procurements):
|
||||||
# 首先调用父类的 _run_buy 方法,以保留原有逻辑
|
# 判断补货组的采购类型
|
||||||
super(StockRuleInherit, self)._run_buy(procurements)
|
procurements_group = {'standard': [], 'consignment': []}
|
||||||
|
|
||||||
# 然后在这里添加自定义的逻辑
|
|
||||||
for procurement, rule in procurements:
|
for procurement, rule in procurements:
|
||||||
|
is_consignment = False
|
||||||
product = procurement.product_id
|
product = procurement.product_id
|
||||||
# 获取主 BOM
|
# 获取主 BOM
|
||||||
bom = self.env['mrp.bom'].search([('product_tmpl_id', '=', product.product_tmpl_id.id)], limit=1)
|
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:
|
for route in raw_material.route_ids:
|
||||||
# print('route.name:', route.name)
|
# print('route.name:', route.name)
|
||||||
if route.name == '按订单补给外包商': # 或者用 route.id 检查精确的路线
|
if route.name == '按订单补给外包商':
|
||||||
print("按订单补给外包商============是")
|
is_consignment = True
|
||||||
# 使用 procurement.values['supplier'] 获取供应商
|
|
||||||
supplier = procurement.values.get('supplier')
|
if is_consignment:
|
||||||
if supplier:
|
procurements_group['consignment'].append((procurement, rule))
|
||||||
domain = rule._make_po_get_domain(procurement.company_id, procurement.values,
|
else:
|
||||||
supplier.partner_id)
|
procurements_group['standard'].append((procurement, rule))
|
||||||
logging.info("domain=============: %s", domain)
|
|
||||||
po = self.env['purchase.order'].sudo().search([
|
for key, value in procurements_group.items():
|
||||||
('partner_id', '=', supplier.partner_id.id),
|
super(StockRuleInherit, self)._run_buy(value)
|
||||||
('company_id', '=', procurement.company_id.id), # 保证公司一致
|
|
||||||
('origin', '=', procurement.origin), # 根据来源匹配
|
if key == 'consignment':
|
||||||
('state', '=', 'draft') # 状态为草稿
|
for procurement, rule in value:
|
||||||
], limit=1)
|
supplier = procurement.values.get('supplier')
|
||||||
logging.info("po=: %s", po)
|
if supplier:
|
||||||
if po:
|
domain = rule._make_po_get_domain(procurement.company_id, procurement.values,
|
||||||
po.write({'purchase_type': 'consignment'})
|
supplier.partner_id)
|
||||||
break
|
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
|
||||||
|
|||||||
@@ -1466,6 +1466,29 @@ class MrpProduction(models.Model):
|
|||||||
])
|
])
|
||||||
order.delivery_count = len(order.picking_ids)
|
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):
|
class sf_detection_result(models.Model):
|
||||||
_name = 'sf.detection.result'
|
_name = 'sf.detection.result'
|
||||||
|
|||||||
@@ -4,5 +4,4 @@ from . import quick_easy_order_old
|
|||||||
from . import auto_quatotion_common
|
from . import auto_quatotion_common
|
||||||
from . import parser_and_calculate_work_time
|
from . import parser_and_calculate_work_time
|
||||||
from . import preload_datas_functions
|
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