Compare commits
9 Commits
feature/72
...
feature/72
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bba9e8e8a8 | ||
|
|
e4c3435840 | ||
|
|
2a7048dafd | ||
|
|
2bb215f9df | ||
|
|
a2be3a0dbf | ||
|
|
1f4ceab377 | ||
|
|
94d727e8e0 | ||
|
|
42d9f894dd | ||
|
|
9416d1c1a0 |
@@ -35,7 +35,6 @@
|
|||||||
],
|
],
|
||||||
'web.assets_backend': [
|
'web.assets_backend': [
|
||||||
'sf_base/static/src/scss/*.scss',
|
'sf_base/static/src/scss/*.scss',
|
||||||
'sf_base/static/src/js/*.js',
|
|
||||||
],
|
],
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
/** @odoo-module **/
|
|
||||||
|
|
||||||
import { registry } from "@web/core/registry";
|
|
||||||
import { barcodeGenericHandlers } from '@barcodes/barcode_handlers';
|
|
||||||
import { patch } from "@web/core/utils/patch";
|
|
||||||
|
|
||||||
// 定义新的 clickOnButton 函数
|
|
||||||
function customClickOnButton(selector) {
|
|
||||||
console.log("This is the custom clickOnButton function!");
|
|
||||||
|
|
||||||
const buttons = document.body.querySelectorAll(selector);
|
|
||||||
|
|
||||||
let length = buttons.length;
|
|
||||||
if (length > 0) {
|
|
||||||
buttons[length - 1].click();
|
|
||||||
} else {
|
|
||||||
console.warn(`Button with selector ${selector} not found`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
patch(barcodeGenericHandlers, "start", {
|
|
||||||
start(env, { ui, barcode, notification }) {
|
|
||||||
// 使用新定义的 clickOnButton 函数
|
|
||||||
const COMMANDS = {
|
|
||||||
"O-CMD.EDIT": () => customClickOnButton(".o_form_button_edit"),
|
|
||||||
"O-CMD.DISCARD": () => customClickOnButton(".o_form_button_cancel"),
|
|
||||||
"O-CMD.SAVE": () => customClickOnButton(".o_form_button_save"),
|
|
||||||
"O-CMD.PREV": () => customClickOnButton(".o_pager_previous"),
|
|
||||||
"O-CMD.NEXT": () => customClickOnButton(".o_pager_next"),
|
|
||||||
"O-CMD.PAGER-FIRST": () => updatePager("first"),
|
|
||||||
"O-CMD.PAGER-LAST": () => updatePager("last"),
|
|
||||||
"O-CMD.CONFIRM": () => customClickOnButton(".jikimo_button_confirm"),
|
|
||||||
"O-CMD.FLUSHED": () => customClickOnButton(".jikimo_button_flushed"),
|
|
||||||
};
|
|
||||||
|
|
||||||
barcode.bus.addEventListener("barcode_scanned", (ev) => {
|
|
||||||
const barcode = ev.detail.barcode;
|
|
||||||
if (barcode.startsWith("O-BTN.")) {
|
|
||||||
let targets = [];
|
|
||||||
try {
|
|
||||||
targets = getVisibleElements(ui.activeElement, `[barcode_trigger=${barcode.slice(6)}]`);
|
|
||||||
} catch (_e) {
|
|
||||||
console.warn(`Barcode '${barcode}' is not valid`);
|
|
||||||
}
|
|
||||||
for (let elem of targets) {
|
|
||||||
elem.click();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (barcode.startsWith("O-CMD.")) {
|
|
||||||
const fn = COMMANDS[barcode];
|
|
||||||
if (fn) {
|
|
||||||
fn();
|
|
||||||
} else {
|
|
||||||
notification.add(env._t("Barcode: ") + `'${barcode}'`, {
|
|
||||||
title: env._t("Unknown barcode command"),
|
|
||||||
type: "danger"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/** @odoo-module **/
|
|
||||||
|
|
||||||
import { registry } from '@web/core/registry';
|
|
||||||
|
|
||||||
import { formView } from '@web/views/form/form_view';
|
|
||||||
import { FormController } from '@web/views/form/form_controller';
|
|
||||||
|
|
||||||
import { listView } from '@web/views/list/list_view';
|
|
||||||
import { ListController } from '@web/views/list/list_controller'
|
|
||||||
|
|
||||||
import { onRendered, onMounted } from "@odoo/owl";
|
|
||||||
|
|
||||||
export class RemoveFocusFormController extends FormController {
|
|
||||||
setup() {
|
|
||||||
super.setup();
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
this.__owl__.bdom.el.querySelectorAll(':focus').forEach(element => element.blur());
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
registry.category('views').add('remove_focus_form_view', {
|
|
||||||
...formView,
|
|
||||||
Controller: RemoveFocusFormController,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
export class RemoveFocusListController extends ListController {
|
|
||||||
setup() {
|
|
||||||
super.setup();
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
this.__owl__.bdom.el.querySelectorAll(':focus').forEach(element => element.blur());
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
registry.category('views').add('remove_focus_list_view', {
|
|
||||||
...listView,
|
|
||||||
Controller: RemoveFocusListController,
|
|
||||||
});
|
|
||||||
@@ -222,10 +222,15 @@ class SfDemandPlan(models.Model):
|
|||||||
line_ids = self.line_ids.filtered(lambda p: p.status == '30')
|
line_ids = self.line_ids.filtered(lambda p: p.status == '30')
|
||||||
sum_product_uom_qty = sum(line_ids.mapped('plan_uom_qty'))
|
sum_product_uom_qty = sum(line_ids.mapped('plan_uom_qty'))
|
||||||
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
||||||
if not self.overdelivery_allowed and line_ids.filtered(lambda p: p.location_id.id == customer_location_id):
|
check_overdelivery_allowed = False
|
||||||
if float_compare(sum_product_uom_qty, self.product_uom_qty,
|
for line in line_ids:
|
||||||
precision_rounding=self.product_id.uom_id.rounding) == 1:
|
if line.location_id.id == customer_location_id:
|
||||||
raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
if not self.overdelivery_allowed:
|
||||||
|
if float_compare(sum_product_uom_qty, self.product_uom_qty,
|
||||||
|
precision_rounding=line.product_id.uom_id.rounding) == 1:
|
||||||
|
check_overdelivery_allowed = True
|
||||||
|
if check_overdelivery_allowed:
|
||||||
|
raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
||||||
elif float_compare(sum_product_uom_qty, self.product_uom_qty,
|
elif float_compare(sum_product_uom_qty, self.product_uom_qty,
|
||||||
precision_rounding=self.product_id.uom_id.rounding) == 1:
|
precision_rounding=self.product_id.uom_id.rounding) == 1:
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -7,39 +7,17 @@ from odoo.tools import float_compare
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
import re
|
import re
|
||||||
#本地环境问题 不加报错
|
|
||||||
class ProductCategory(models.Model):
|
|
||||||
_inherit = 'product.category'
|
|
||||||
|
|
||||||
negative_inventory_allowed = fields.Boolean(string="允许负库存", default=False)
|
|
||||||
|
|
||||||
class StockPicking(models.Model):
|
|
||||||
_inherit = 'stock.picking'
|
|
||||||
|
|
||||||
whether_show_quality_check = fields.Boolean(string="是否显示质检")
|
|
||||||
|
|
||||||
class ProductTemplate(models.Model):
|
|
||||||
_inherit = 'product.template'
|
|
||||||
|
|
||||||
blank_type = fields.Selection([
|
|
||||||
('圆料', '圆料'),
|
|
||||||
('方料', '方料'),
|
|
||||||
], string='坯料分类')
|
|
||||||
|
|
||||||
blank_precision = fields.Selection([
|
|
||||||
('精坯', '精坯'),
|
|
||||||
('粗坯', '粗坯'),
|
|
||||||
], string='坯料类型')
|
|
||||||
|
|
||||||
class SfProductionDemandPlan(models.Model):
|
class SfProductionDemandPlan(models.Model):
|
||||||
_name = 'sf.production.demand.plan'
|
_name = 'sf.production.demand.plan'
|
||||||
_description = 'sf_production_demand_plan'
|
_description = 'sf_production_demand_plan'
|
||||||
|
|
||||||
def get_location_id(self):
|
def get_location_id(self):
|
||||||
stock_location = self.env['stock.location'].sudo().search([('name', '=', '客户')], limit=1)
|
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
||||||
return stock_location.id
|
return customer_location_id
|
||||||
|
|
||||||
priority = fields.Selection(related='demand_plan_id.priority', string='优先级')
|
priority = fields.Selection(related='demand_plan_id.priority', string='优先级', store=True)
|
||||||
status = fields.Selection([
|
status = fields.Selection([
|
||||||
('10', '草稿'),
|
('10', '草稿'),
|
||||||
('20', '待确认'),
|
('20', '待确认'),
|
||||||
@@ -56,7 +34,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
company_id = fields.Many2one(
|
company_id = fields.Many2one(
|
||||||
related='sale_order_id.company_id',
|
related='sale_order_id.company_id',
|
||||||
store=True, index=True, precompute=True)
|
store=True, index=True, precompute=True)
|
||||||
customer_name = fields.Char('客户', related='sale_order_id.customer_name')
|
customer_name = fields.Char('客户', related='sale_order_id.customer_name', store=True)
|
||||||
order_remark = fields.Text(related='sale_order_id.remark',
|
order_remark = fields.Text(related='sale_order_id.remark',
|
||||||
string="订单备注", store=True)
|
string="订单备注", store=True)
|
||||||
glb_url = fields.Char(related='sale_order_line_id.glb_url', string='glb文件地址')
|
glb_url = fields.Char(related='sale_order_line_id.glb_url', string='glb文件地址')
|
||||||
@@ -105,7 +83,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
related='product_id.blank_precision')
|
related='product_id.blank_precision')
|
||||||
unit_number = fields.Float('单件用量', digits=(16, 3), related='product_id.unit_number')
|
unit_number = fields.Float('单件用量', digits=(16, 3), related='product_id.unit_number')
|
||||||
embryo_long = fields.Char('坯料尺寸(mm)', related='demand_plan_id.embryo_long')
|
embryo_long = fields.Char('坯料尺寸(mm)', related='demand_plan_id.embryo_long')
|
||||||
materials_id = fields.Char('材料', related='demand_plan_id.materials_id')
|
materials_id = fields.Char('材料', related='demand_plan_id.materials_id', store=True)
|
||||||
model_machining_precision = fields.Selection(related='product_id.model_machining_precision', string='精度')
|
model_machining_precision = fields.Selection(related='product_id.model_machining_precision', string='精度')
|
||||||
model_process_parameters_ids = fields.Many2many(related='demand_plan_id.model_process_parameters_ids',
|
model_process_parameters_ids = fields.Many2many(related='demand_plan_id.model_process_parameters_ids',
|
||||||
string='表面工艺', )
|
string='表面工艺', )
|
||||||
@@ -149,6 +127,12 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
string='字段自制类型只读'
|
string='字段自制类型只读'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
is_processing = fields.Boolean(
|
||||||
|
string='正在处理中',
|
||||||
|
default=False,
|
||||||
|
help='用于防止重复点击按钮'
|
||||||
|
)
|
||||||
|
|
||||||
# hide_action_open_mrp_production = fields.Boolean(
|
# hide_action_open_mrp_production = fields.Boolean(
|
||||||
# string='显示待工艺确认按钮',
|
# string='显示待工艺确认按钮',
|
||||||
# compute='_compute_hid_button',
|
# compute='_compute_hid_button',
|
||||||
@@ -629,11 +613,6 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
filtered_plan = self.filtered(lambda mo: mo.status == '30')
|
filtered_plan = self.filtered(lambda mo: mo.status == '30')
|
||||||
if not filtered_plan:
|
if not filtered_plan:
|
||||||
raise UserError(_("没有需要下达的计划!"))
|
raise UserError(_("没有需要下达的计划!"))
|
||||||
check_overdelivery_allowed = False
|
|
||||||
if not self.demand_plan_id.overdelivery_allowed:
|
|
||||||
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
|
||||||
if self.location_id.id == customer_location_id:
|
|
||||||
check_overdelivery_allowed = True
|
|
||||||
# 按产品分组并计算总数
|
# 按产品分组并计算总数
|
||||||
product_data = {}
|
product_data = {}
|
||||||
for plan in filtered_plan:
|
for plan in filtered_plan:
|
||||||
@@ -681,9 +660,15 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
'default_demand_plan_line_id': self.ids,
|
'default_demand_plan_line_id': self.ids,
|
||||||
'default_release_message': warning_message,
|
'default_release_message': warning_message,
|
||||||
}}
|
}}
|
||||||
|
else:
|
||||||
|
for demand_plan_line_id in filtered_plan:
|
||||||
|
demand_plan_line_id.action_confirm()
|
||||||
|
|
||||||
def button_release_plan(self):
|
def button_release_plan(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
|
if self.is_processing:
|
||||||
|
return
|
||||||
|
self.is_processing = True
|
||||||
check_overdelivery_allowed = False
|
check_overdelivery_allowed = False
|
||||||
if not self.demand_plan_id.overdelivery_allowed:
|
if not self.demand_plan_id.overdelivery_allowed:
|
||||||
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
||||||
@@ -710,49 +695,38 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
self.action_confirm()
|
self.action_confirm()
|
||||||
|
|
||||||
def action_confirm(self):
|
def action_confirm(self):
|
||||||
"""
|
self = self.with_context(
|
||||||
确认需求计划行,创建 BOM、触发库存规则,并更新状态。
|
demand_plan_line_id=self.id
|
||||||
"""
|
)
|
||||||
# 将当前需求计划行 ID 写入上下文,便于后续方法使用
|
|
||||||
self = self.with_context(demand_plan_line_id=self.id)
|
|
||||||
|
|
||||||
# 创建物料清单(BOM),根据供货方式进行不同的处理
|
|
||||||
self.mrp_bom_create()
|
self.mrp_bom_create()
|
||||||
|
|
||||||
# 启动库存规则(创建采购、生产等)
|
|
||||||
self._action_launch_stock_rule()
|
self._action_launch_stock_rule()
|
||||||
|
|
||||||
# 根据供货方式设置状态字段
|
|
||||||
if self.supply_method in ('automation', 'manual'):
|
if self.supply_method in ('automation', 'manual'):
|
||||||
self.write({'status': '50'}) # 自动/手工 供货:待排产
|
self.write({'status': '50'})
|
||||||
self.update_sale_order_state()
|
self.update_sale_order_state()
|
||||||
else:
|
else:
|
||||||
self.write({'status': '60'}) # 外购/外协/客户自供:无需排产
|
self.write({'status': '60'})
|
||||||
self.update_sale_order_state()
|
self.update_sale_order_state()
|
||||||
|
|
||||||
|
|
||||||
def _get_embryo_template_by_supply_method(self):
|
|
||||||
"""
|
|
||||||
根据供货方式返回对应的胚料模板 product.template 记录。
|
|
||||||
"""
|
|
||||||
supply_map = {
|
|
||||||
'automation': self.env.ref('sf_dlm.product_embryo_sf_self_machining').sudo(),
|
|
||||||
'outsourcing': self.env.ref('sf_dlm.product_embryo_sf_outsource').sudo(),
|
|
||||||
'purchase': self.env.ref('sf_dlm.product_embryo_sf_purchase').sudo(),
|
|
||||||
'manual': self.env.ref('jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo(),
|
|
||||||
'material_customer_provided': self.env.ref('jikimo_sale_multiple_supply_methods.product_template_embryo_customer_provided').sudo(),
|
|
||||||
}
|
|
||||||
template = supply_map.get(self.supply_method)
|
|
||||||
if not template:
|
|
||||||
raise UserError(f"未配置供货方式 {self.supply_method} 对应的胚料模板")
|
|
||||||
return template
|
|
||||||
|
|
||||||
|
|
||||||
def mrp_bom_create(self):
|
def mrp_bom_create(self):
|
||||||
"""
|
bom_type = ''
|
||||||
创建 BOM(包含胚料与成品 BOM),用于后续生产或采购流程。
|
# 根据供货方式修改成品模板
|
||||||
"""
|
if self.supply_method == 'automation':
|
||||||
# 如果同一计划中已有对应的 BOM 可复用,则直接使用
|
bom_type = 'normal'
|
||||||
|
product_template_id = self.env.ref('sf_dlm.product_template_sf').sudo().product_tmpl_id
|
||||||
|
elif self.supply_method == 'outsourcing':
|
||||||
|
bom_type = 'subcontract'
|
||||||
|
product_template_id = self.env.ref(
|
||||||
|
'jikimo_sale_multiple_supply_methods.product_template_outsourcing').sudo()
|
||||||
|
elif self.supply_method == 'purchase':
|
||||||
|
product_template_id = self.env.ref(
|
||||||
|
'jikimo_sale_multiple_supply_methods.product_template_purchase').sudo()
|
||||||
|
elif self.supply_method == 'manual':
|
||||||
|
bom_type = 'normal'
|
||||||
|
product_template_id = self.env.ref(
|
||||||
|
'jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo()
|
||||||
|
|
||||||
|
# 复制成品模板上的属性
|
||||||
|
self.product_id.product_tmpl_id.copy_template(product_template_id)
|
||||||
if self.supply_method in ('automation', 'manual'):
|
if self.supply_method in ('automation', 'manual'):
|
||||||
line_ids = self.demand_plan_id.line_ids.filtered(
|
line_ids = self.demand_plan_id.line_ids.filtered(
|
||||||
lambda p: p.supply_method in ('automation', 'manual') and p.status in ('50', '60'))
|
lambda p: p.supply_method in ('automation', 'manual') and p.status in ('50', '60'))
|
||||||
@@ -765,32 +739,13 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
if line_ids:
|
if line_ids:
|
||||||
self.bom_id = line_ids[0].bom_id.id
|
self.bom_id = line_ids[0].bom_id.id
|
||||||
return
|
return
|
||||||
|
|
||||||
# 根据供货方式选择模板和 BOM 类型
|
|
||||||
bom_type = ''
|
|
||||||
if self.supply_method == 'automation':
|
|
||||||
bom_type = 'normal'
|
|
||||||
product_template_id = self.env.ref('sf_dlm.product_template_sf').sudo().product_tmpl_id
|
|
||||||
elif self.supply_method == 'outsourcing':
|
|
||||||
bom_type = 'subcontract'
|
|
||||||
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_outsourcing').sudo()
|
|
||||||
elif self.supply_method == 'purchase':
|
|
||||||
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_purchase').sudo()
|
|
||||||
elif self.supply_method == 'manual':
|
|
||||||
bom_type = 'normal'
|
|
||||||
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo()
|
|
||||||
|
|
||||||
# 使用模板复制内容到当前产品
|
|
||||||
self.product_id.product_tmpl_id.copy_template(product_template_id)
|
|
||||||
|
|
||||||
# 构造 BOM 编码(包含时间戳)
|
|
||||||
future_time = datetime.now() + timedelta(hours=8)
|
future_time = datetime.now() + timedelta(hours=8)
|
||||||
|
# 生成BOM单据编码
|
||||||
code = f"{self.product_id.default_code}-{bom_type}-{future_time.strftime('%Y%m%d%H%M%S')}"
|
code = f"{self.product_id.default_code}-{bom_type}-{future_time.strftime('%Y%m%d%H%M%S')}"
|
||||||
|
|
||||||
order_id = self.sale_order_id
|
order_id = self.sale_order_id
|
||||||
product = self.product_id
|
product = self.product_id
|
||||||
|
# 拼接方法需要的item结构,成品的模型数据信息就是坯料的数据信息
|
||||||
# 构造胚料产品的参数
|
|
||||||
item = {
|
item = {
|
||||||
'texture_code': product.materials_id.materials_no,
|
'texture_code': product.materials_id.materials_no,
|
||||||
'texture_type_code': product.materials_type_id.materials_no,
|
'texture_type_code': product.materials_type_id.materials_no,
|
||||||
@@ -803,84 +758,110 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
'embryo_redundancy_id': self.sale_order_line_id.embryo_redundancy_id,
|
'embryo_redundancy_id': self.sale_order_line_id.embryo_redundancy_id,
|
||||||
'model_id': self.model_id
|
'model_id': self.model_id
|
||||||
}
|
}
|
||||||
|
|
||||||
# 从产品名中提取编号(如 S12345-3)
|
|
||||||
product_name = ''
|
product_name = ''
|
||||||
match = re.search(r'(S\d{5}-\d+)', product.name)
|
match = re.search(r'(S\d{5}-\d+)', product.name)
|
||||||
product_seria = 0
|
product_seria = 0
|
||||||
|
# 如果匹配成功,提取结果
|
||||||
if match:
|
if match:
|
||||||
product_name = match.group(0)
|
product_name = match.group(0)
|
||||||
|
# 获取成品名结尾-n的n
|
||||||
product_seria = int(product_name.split('-')[-1])
|
product_seria = int(product_name.split('-')[-1])
|
||||||
|
|
||||||
# 如果供货方式不是采购,则需要先创建胚料产品
|
# 成品供货方式为采购则不生成bom
|
||||||
if self.supply_method != 'purchase':
|
if self.supply_method != 'purchase':
|
||||||
# 判断是否为客户自供
|
# 当成品上带有客供料选项时,生成坯料时选择“客供料”路线
|
||||||
if self.sale_order_line_id.embryo_redundancy_id:
|
if self.sale_order_line_id.embryo_redundancy_id:
|
||||||
embryo_template = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_embryo_customer_provided').sudo()
|
# 将成品模板的内容复制到成品上
|
||||||
embryo_key = 'material_customer_provided'
|
customer_provided_embryo = self.env.ref(
|
||||||
else:
|
'jikimo_sale_multiple_supply_methods.product_template_embryo_customer_provided').sudo()
|
||||||
embryo_template = self._get_embryo_template_by_supply_method()
|
# 创建坯料,客供料的批量不需要创建bom
|
||||||
embryo_key = self.supply_method
|
material_customer_provided_embryo = self.env['product.template'].sudo().no_bom_product_create(
|
||||||
|
customer_provided_embryo.with_context(active_test=False).product_variant_id,
|
||||||
# 获取批次追踪方式 依据模版
|
item,
|
||||||
tracking_method = embryo_template.tracking
|
order_id, 'material_customer_provided', product_seria, product)
|
||||||
|
# 成品配置bom
|
||||||
# 创建胚料产品(无 BOM 产品)
|
product_bom_material_customer_provided = self.env['mrp.bom'].with_user(
|
||||||
embryo_product = self.env['product.template'].sudo().no_bom_product_create(
|
self.env.ref("base.user_admin")).bom_create(
|
||||||
embryo_template.with_context(active_test=False).product_variant_id,
|
product, bom_type, 'product', code)
|
||||||
item,
|
product_bom_material_customer_provided.with_user(
|
||||||
order_id,
|
self.env.ref("base.user_admin")).bom_create_line_has(
|
||||||
embryo_key,
|
material_customer_provided_embryo)
|
||||||
product_seria,
|
self.bom_id = product_bom_material_customer_provided.id
|
||||||
product
|
elif self.product_id.materials_type_id.gain_way == '自加工':
|
||||||
)
|
self_machining_id = self.env.ref('sf_dlm.product_embryo_sf_self_machining').sudo()
|
||||||
|
# 创建坯料
|
||||||
if isinstance(embryo_product, models.Model): # 确保返回的是记录而非错误码
|
self_machining_embryo = self.env['product.template'].sudo().no_bom_product_create(
|
||||||
embryo_product.write({'tracking': tracking_method})
|
self_machining_id,
|
||||||
|
item,
|
||||||
if embryo_product == -3:
|
order_id, 'self_machining', product_seria, product)
|
||||||
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
|
# 创建坯料的bom
|
||||||
|
self_machining_bom = self.env['mrp.bom'].with_user(
|
||||||
# 设置胚料 BOM 类型
|
self.env.ref("base.user_admin")).bom_create(
|
||||||
if embryo_key in ('automation', 'manual', 'material_customer_provided'):
|
self_machining_embryo, 'normal', False)
|
||||||
embryo_bom_type = 'normal'
|
# 创建坯料里bom的组件
|
||||||
elif embryo_key == 'outsourcing':
|
self_machining_bom_line = self_machining_bom.with_user(
|
||||||
embryo_bom_type = 'subcontract'
|
self.env.ref("base.user_admin")).bom_create_line(
|
||||||
elif embryo_key == 'purchase':
|
self_machining_embryo)
|
||||||
embryo_bom_type = 'purchase'
|
if not self_machining_bom_line:
|
||||||
else:
|
raise UserError('该订单模型的材料型号暂未有原材料,请先配置再进行分配')
|
||||||
embryo_bom_type = 'normal'
|
# 产品配置bom
|
||||||
|
product_bom_self_machining = self.env['mrp.bom'].with_user(
|
||||||
# 创建胚料 BOM 及 BOM 行
|
self.env.ref("base.user_admin")).bom_create(
|
||||||
embryo_bom = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).bom_create(
|
product, bom_type, 'product', code)
|
||||||
embryo_product, embryo_bom_type, True, tracking=tracking_method)
|
product_bom_self_machining.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
|
||||||
|
self_machining_embryo)
|
||||||
embryo_bom_line = embryo_bom.with_user(self.env.ref("base.user_admin")).bom_create_line(embryo_product)
|
self.bom_id = product_bom_self_machining.id
|
||||||
if not embryo_bom_line:
|
elif self.product_id.materials_type_id.gain_way == '外协':
|
||||||
raise UserError('该订单模型的材料型号暂未有原材料,请先配置再进行分配')
|
outsource_id = self.env.ref('sf_dlm.product_embryo_sf_outsource').sudo()
|
||||||
|
# 创建坯料
|
||||||
# 创建成品 BOM(包含胚料)
|
outsource_embryo = self.env['product.template'].sudo().no_bom_product_create(outsource_id,
|
||||||
product_bom = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).bom_create(
|
item,
|
||||||
product, bom_type, 'product', code, tracking=tracking_method)
|
order_id,
|
||||||
product_bom.with_user(self.env.ref("base.user_admin")).bom_create_line_has(embryo_product)
|
'subcontract',
|
||||||
|
product_seria,
|
||||||
# 赋值 BOM ID
|
product)
|
||||||
self.bom_id = product_bom.id
|
if outsource_embryo == -3:
|
||||||
|
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
|
||||||
|
# 创建坯料的bom
|
||||||
|
outsource_bom = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).bom_create(
|
||||||
|
outsource_embryo,
|
||||||
|
'subcontract', True)
|
||||||
|
# 创建坯料的bom的组件
|
||||||
|
outsource_bom_line = outsource_bom.with_user(
|
||||||
|
self.env.ref("base.user_admin")).bom_create_line(outsource_embryo)
|
||||||
|
if not outsource_bom_line:
|
||||||
|
raise UserError('该订单模型的材料型号暂未有原材料,请先配置再进行分配')
|
||||||
|
# 产品配置bom
|
||||||
|
product_bom_outsource = self.env['mrp.bom'].with_user(
|
||||||
|
self.env.ref("base.user_admin")).bom_create(product, bom_type, 'product', code)
|
||||||
|
product_bom_outsource.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
|
||||||
|
outsource_embryo)
|
||||||
|
self.bom_id = product_bom_outsource.id
|
||||||
|
elif self.product_id.materials_type_id.gain_way == '采购':
|
||||||
|
purchase_id = self.env.ref('sf_dlm.product_embryo_sf_purchase').sudo()
|
||||||
|
purchase_embryo = self.env['product.template'].sudo().no_bom_product_create(purchase_id,
|
||||||
|
item,
|
||||||
|
order_id,
|
||||||
|
'purchase',
|
||||||
|
product_seria,
|
||||||
|
product)
|
||||||
|
if purchase_embryo and purchase_embryo == -3:
|
||||||
|
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
|
||||||
|
else:
|
||||||
|
# 产品配置bom
|
||||||
|
product_bom_purchase = self.env['mrp.bom'].with_user(
|
||||||
|
self.env.ref("base.user_admin")).bom_create(product, bom_type, 'product', code)
|
||||||
|
product_bom_purchase.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
|
||||||
|
purchase_embryo)
|
||||||
|
self.bom_id = product_bom_purchase.id
|
||||||
|
|
||||||
def _action_launch_stock_rule(self):
|
def _action_launch_stock_rule(self):
|
||||||
"""
|
|
||||||
触发库存规则(如采购、生产),并确认相关拣货单。
|
|
||||||
"""
|
|
||||||
procurements = []
|
procurements = []
|
||||||
|
|
||||||
group_id = self.sale_order_id.procurement_group_id
|
group_id = self.sale_order_id.procurement_group_id
|
||||||
if not group_id:
|
if not group_id:
|
||||||
# 没有分组则创建
|
|
||||||
group_id = self.env['procurement.group'].create(self._prepare_procurement_group_vals())
|
group_id = self.env['procurement.group'].create(self._prepare_procurement_group_vals())
|
||||||
self.sale_order_id.procurement_group_id = group_id
|
self.sale_order_id.procurement_group_id = group_id
|
||||||
else:
|
else:
|
||||||
# 若已有分组但字段有变动则更新
|
|
||||||
updated_vals = {}
|
updated_vals = {}
|
||||||
if group_id.partner_id != self.sale_order_id.partner_shipping_id:
|
if group_id.partner_id != self.sale_order_id.partner_shipping_id:
|
||||||
updated_vals.update({'partner_id': self.sale_order_id.partner_shipping_id.id})
|
updated_vals.update({'partner_id': self.sale_order_id.partner_shipping_id.id})
|
||||||
@@ -888,42 +869,27 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
updated_vals.update({'move_type': self.sale_order_id.picking_policy})
|
updated_vals.update({'move_type': self.sale_order_id.picking_policy})
|
||||||
if updated_vals:
|
if updated_vals:
|
||||||
group_id.write(updated_vals)
|
group_id.write(updated_vals)
|
||||||
|
|
||||||
# 构造 procurement 所需的字段
|
|
||||||
values = self._prepare_procurement_values(group_id=group_id)
|
values = self._prepare_procurement_values(group_id=group_id)
|
||||||
|
|
||||||
# 单位换算
|
|
||||||
line_uom = self.sale_order_line_id.product_uom
|
line_uom = self.sale_order_line_id.product_uom
|
||||||
quant_uom = self.product_id.uom_id
|
quant_uom = self.product_id.uom_id
|
||||||
plan_uom_qty, procurement_uom = line_uom._adjust_uom_quantities(self.plan_uom_qty, quant_uom)
|
plan_uom_qty, procurement_uom = line_uom._adjust_uom_quantities(self.plan_uom_qty, quant_uom)
|
||||||
|
|
||||||
# 创建 procurement 请求
|
|
||||||
procurements.append(self.env['procurement.group'].Procurement(
|
procurements.append(self.env['procurement.group'].Procurement(
|
||||||
self.product_id, plan_uom_qty, procurement_uom,
|
self.product_id, plan_uom_qty, procurement_uom,
|
||||||
self.sale_order_id.partner_shipping_id.property_stock_customer,
|
self.sale_order_id.partner_shipping_id.property_stock_customer,
|
||||||
self.product_id.display_name, self.sale_order_id.name, self.sale_order_id.company_id, values))
|
self.product_id.display_name, self.sale_order_id.name, self.sale_order_id.company_id, values))
|
||||||
|
|
||||||
# 执行调度
|
|
||||||
if procurements:
|
if procurements:
|
||||||
procurement_group = self.env['procurement.group']
|
procurement_group = self.env['procurement.group']
|
||||||
if self.env.context.get('import_file'):
|
if self.env.context.get('import_file'):
|
||||||
procurement_group = procurement_group.with_context(import_file=False)
|
procurement_group = procurement_group.with_context(import_file=False)
|
||||||
procurement_group.run(procurements)
|
procurement_group.run(procurements)
|
||||||
|
|
||||||
# 确认相关的拣货单
|
|
||||||
orders = self.mapped('sale_order_id')
|
orders = self.mapped('sale_order_id')
|
||||||
for order in orders:
|
for order in orders:
|
||||||
pickings_to_confirm = order.picking_ids.filtered(lambda p: p.state not in ['cancel', 'done'])
|
pickings_to_confirm = order.picking_ids.filtered(lambda p: p.state not in ['cancel', 'done'])
|
||||||
if pickings_to_confirm:
|
if pickings_to_confirm:
|
||||||
pickings_to_confirm.action_confirm()
|
pickings_to_confirm.action_confirm()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _prepare_procurement_group_vals(self):
|
def _prepare_procurement_group_vals(self):
|
||||||
"""
|
|
||||||
构造创建 procurement group 所需的字段。
|
|
||||||
"""
|
|
||||||
return {
|
return {
|
||||||
'name': self.sale_order_id.name,
|
'name': self.sale_order_id.name,
|
||||||
'move_type': self.sale_order_id.picking_policy,
|
'move_type': self.sale_order_id.picking_policy,
|
||||||
@@ -931,18 +897,11 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
'partner_id': self.sale_order_id.partner_shipping_id.id,
|
'partner_id': self.sale_order_id.partner_shipping_id.id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _prepare_procurement_values(self, group_id=False):
|
def _prepare_procurement_values(self, group_id=False):
|
||||||
"""
|
|
||||||
构造单个 procurement 请求所需的字段字典。
|
|
||||||
"""
|
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
|
|
||||||
# 交货日期与计划日期
|
|
||||||
date_deadline = self.sale_order_id.commitment_date or (
|
date_deadline = self.sale_order_id.commitment_date or (
|
||||||
self.sale_order_id.date_order + timedelta(days=self.sale_order_line_id.customer_lead or 0.0))
|
self.sale_order_id.date_order + timedelta(days=self.sale_order_line_id.customer_lead or 0.0))
|
||||||
date_planned = date_deadline - timedelta(days=self.sale_order_id.company_id.security_lead)
|
date_planned = date_deadline - timedelta(days=self.sale_order_id.company_id.security_lead)
|
||||||
|
|
||||||
values = {
|
values = {
|
||||||
'group_id': group_id,
|
'group_id': group_id,
|
||||||
'sale_line_id': self.sale_order_line_id.id,
|
'sale_line_id': self.sale_order_line_id.id,
|
||||||
@@ -958,6 +917,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
'sequence': self.sale_order_line_id.sequence,
|
'sequence': self.sale_order_line_id.sequence,
|
||||||
'demand_plan_line_id': self.id
|
'demand_plan_line_id': self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
def button_plan_detail(self):
|
||||||
|
pass
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
'category': 'sf',
|
'category': 'sf',
|
||||||
'website': 'https://www.sf.jikimo.com',
|
'website': 'https://www.sf.jikimo.com',
|
||||||
'depends': ['sf_base', 'sf_maintenance', 'web_widget_model_viewer', 'sf_warehouse', 'jikimo_attachment_viewer',
|
'depends': ['sf_base', 'sf_maintenance', 'web_widget_model_viewer', 'sf_warehouse', 'jikimo_attachment_viewer',
|
||||||
'jikimo_sale_multiple_supply_methods', 'product'],
|
'jikimo_sale_multiple_supply_methods', 'product', 'jikimo_tree_header_buttons_always_visible'],
|
||||||
'data': [
|
'data': [
|
||||||
'data/cron_data.xml',
|
'data/cron_data.xml',
|
||||||
'data/stock_data.xml',
|
'data/stock_data.xml',
|
||||||
|
|||||||
2
sf_purchase_arrival_inform/__init__.py
Normal file
2
sf_purchase_arrival_inform/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from . import models
|
||||||
|
from . import wizard
|
||||||
33
sf_purchase_arrival_inform/__manifest__.py
Normal file
33
sf_purchase_arrival_inform/__manifest__.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||||
|
{
|
||||||
|
'name': '机企猫智能工厂 采购到货通知',
|
||||||
|
'version': '1.1',
|
||||||
|
'summary': '智能工厂计划管理',
|
||||||
|
'sequence': 1,
|
||||||
|
'description': """
|
||||||
|
在本模块,支持采购到货通知
|
||||||
|
""",
|
||||||
|
'category': 'sf',
|
||||||
|
'website': 'https://www.sf.jikimo.com',
|
||||||
|
'depends': ['jikimo_purchase_request', 'quality_control', 'sf_manufacturing'],
|
||||||
|
'data': [
|
||||||
|
'views/product_category.xml',
|
||||||
|
'views/purchase_view.xml',
|
||||||
|
'wizard/purchase_confirm_wizard_view.xml',
|
||||||
|
'security/ir.model.access.csv',
|
||||||
|
],
|
||||||
|
'demo': [
|
||||||
|
],
|
||||||
|
'assets': {
|
||||||
|
'web.assets_qweb': [
|
||||||
|
],
|
||||||
|
'web.assets_backend': [
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'license': 'LGPL-3',
|
||||||
|
'installable': True,
|
||||||
|
'application': False,
|
||||||
|
'auto_install': False,
|
||||||
|
}
|
||||||
5
sf_purchase_arrival_inform/models/__init__.py
Normal file
5
sf_purchase_arrival_inform/models/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from . import product_category
|
||||||
|
from . import purchase_order
|
||||||
|
from . import storage_list
|
||||||
|
from . import quality_check
|
||||||
|
|
||||||
7
sf_purchase_arrival_inform/models/product_category.py
Normal file
7
sf_purchase_arrival_inform/models/product_category.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from odoo import models, fields
|
||||||
|
|
||||||
|
|
||||||
|
class SfProductCategory(models.Model):
|
||||||
|
_inherit = 'product.category'
|
||||||
|
arrival_inform = fields.Boolean('到货通知', default=False)
|
||||||
|
|
||||||
108
sf_purchase_arrival_inform/models/purchase_order.py
Normal file
108
sf_purchase_arrival_inform/models/purchase_order.py
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
from odoo import models, fields, api, _
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
|
class SfPurchaseOrder(models.Model):
|
||||||
|
_inherit = 'purchase.order'
|
||||||
|
|
||||||
|
# 收料入库明细
|
||||||
|
storage_list_ids = fields.One2many('storage.list', 'purchase_order_id', string='收料入库明细')
|
||||||
|
|
||||||
|
# 计算字段:总收料数量
|
||||||
|
total_received_quantity = fields.Float(string='到货数量',compute='_compute_total_received_quantity',store=True)
|
||||||
|
|
||||||
|
purchase_order_line_id = fields.Many2one('purchase.order.line', string='采购订单行')
|
||||||
|
|
||||||
|
@api.depends('order_line.arrival_quantity','order_line.product_qty')
|
||||||
|
def _compute_total_received_quantity(self):
|
||||||
|
for order in self:
|
||||||
|
total_arrival_quantity = sum(line.arrival_quantity for line in order.order_line)
|
||||||
|
total_product_qty=sum(line.product_qty for line in order.order_line)
|
||||||
|
order.total_received_quantity = f'{total_arrival_quantity}/{total_product_qty}'
|
||||||
|
|
||||||
|
def open_arrival_inform(self):
|
||||||
|
self.ensure_one()
|
||||||
|
# 方式一:把数据写入普通模型(如果要持久化关联关系等场景)
|
||||||
|
# 先清空旧数据(如果需要),避免重复
|
||||||
|
self.env["storage.list"].search([
|
||||||
|
("purchase_order_id", "=", self.id)
|
||||||
|
]).unlink()
|
||||||
|
pickings = self.env['stock.picking'].search([
|
||||||
|
('origin', '=', self.name),
|
||||||
|
# ('picking_type_code', '=', 'incoming'),
|
||||||
|
('state', '!=', 'cancel')
|
||||||
|
])
|
||||||
|
relate_vals_list = []
|
||||||
|
for picking in pickings:
|
||||||
|
for move_line in picking.move_ids_without_package:
|
||||||
|
relate_vals = {
|
||||||
|
"purchase_order_id": self.id,
|
||||||
|
"product_id": move_line.product_id.id,
|
||||||
|
"picking_id": picking.id,
|
||||||
|
"ordered_quantity": move_line.product_uom_qty,
|
||||||
|
# "current_arrival_quantity": move_line.product_uom_qty, # 默认到货数量等于需求数量
|
||||||
|
"product_code": move_line.product_id.default_code,
|
||||||
|
"product_remark": move_line.name,
|
||||||
|
"part_number": move_line.part_number,
|
||||||
|
"state": picking.state,
|
||||||
|
}
|
||||||
|
relate_vals_list.append(relate_vals)
|
||||||
|
if relate_vals_list:
|
||||||
|
self.env["storage.list"].create(relate_vals_list)
|
||||||
|
action = {
|
||||||
|
'name': _("选择到货通知"),
|
||||||
|
'type':'ir.actions.act_window',
|
||||||
|
'view_mode':'form',
|
||||||
|
'views': [(self.env.ref('sf_purchase_arrival_inform.storage_list_wrapper_form').id, 'form')],
|
||||||
|
'res_model':'purchase.order',
|
||||||
|
'target':'new',
|
||||||
|
'res_id': self.id,
|
||||||
|
'context': {
|
||||||
|
'dialog_size': 'large',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return action
|
||||||
|
|
||||||
|
def confirm_arrival_inform(self):
|
||||||
|
"""确认到货通知"""
|
||||||
|
# 直接调用storage_list的批量确认方法
|
||||||
|
if self.storage_list_ids:
|
||||||
|
self.storage_list_ids.button_confirm()
|
||||||
|
|
||||||
|
# 关闭弹窗
|
||||||
|
return {'type': 'ir.actions.act_window_close'}
|
||||||
|
|
||||||
|
#询价单确认时加二次确认逻辑
|
||||||
|
def button_confirm(self):
|
||||||
|
"""采购订单确认,弹出确认向导"""
|
||||||
|
# 无订单行时直接确认
|
||||||
|
if not self.order_line:
|
||||||
|
return super().button_confirm()
|
||||||
|
|
||||||
|
# 直接创建向导记录并打开
|
||||||
|
wizard = self.env['purchase.confirm.wizard'].create({
|
||||||
|
'purchase_order_id': self.id
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
'name': _('询价单订单确认'),
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
|
'res_model': 'purchase.confirm.wizard',
|
||||||
|
'res_id': wizard.id,
|
||||||
|
'view_mode': 'form',
|
||||||
|
'target': 'new',
|
||||||
|
}
|
||||||
|
|
||||||
|
def _execute_original_confirm(self):
|
||||||
|
"""执行原始的确认逻辑"""
|
||||||
|
res = super().button_confirm()
|
||||||
|
return res
|
||||||
|
|
||||||
|
class SfPurchaseOrderLine(models.Model):
|
||||||
|
_inherit = 'purchase.order.line'
|
||||||
|
|
||||||
|
# 到货数量(实际存储字段)
|
||||||
|
arrival_quantity = fields.Float(string='到货数量', default=0.0, help='累计到货数量')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
61
sf_purchase_arrival_inform/models/quality_check.py
Normal file
61
sf_purchase_arrival_inform/models/quality_check.py
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
from odoo import models, fields, api
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class QualityPoint(models.Model):
|
||||||
|
_inherit = 'quality.point'
|
||||||
|
|
||||||
|
quality_status = fields.Selection([
|
||||||
|
('waiting', '等待'),
|
||||||
|
('none', '待处理')
|
||||||
|
], string='默认质检状态',
|
||||||
|
help='收料入库时质量检查单的默认状态。如果设置了此值,系统会在创建质检单时自动使用该状态。')
|
||||||
|
|
||||||
|
class QualityCheck(models.Model):
|
||||||
|
_inherit = 'quality.check'
|
||||||
|
|
||||||
|
@api.model_create_multi
|
||||||
|
def create(self, vals_list):
|
||||||
|
"""
|
||||||
|
重写create方法,根据quality.point配置动态设置quality_state
|
||||||
|
当picking_type为收料入库时,从质量控制点配置中获取默认状态
|
||||||
|
"""
|
||||||
|
# 先调用父类方法创建记录
|
||||||
|
records = super().create(vals_list)
|
||||||
|
|
||||||
|
# 对创建的记录进行状态调整
|
||||||
|
for record in records:
|
||||||
|
try:
|
||||||
|
# 只处理收料入库的质检单且未手动设置状态的记录
|
||||||
|
if (record.picking_id and
|
||||||
|
record.picking_id.picking_type_id.code == 'incoming' and
|
||||||
|
record.quality_state in ['none', 'waiting']): # 只调整默认状态
|
||||||
|
|
||||||
|
# 查找匹配的质量控制点配置
|
||||||
|
quality_point = record.point_id
|
||||||
|
if not quality_point and record.product_id:
|
||||||
|
# 如果没有直接关联的质量点,则根据产品和作业类型查找
|
||||||
|
domain = self.env['quality.point']._get_domain(
|
||||||
|
record.product_id,
|
||||||
|
record.picking_id.picking_type_id,
|
||||||
|
measure_on='product'
|
||||||
|
)
|
||||||
|
quality_point = self.env['quality.point'].search(domain, limit=1)
|
||||||
|
|
||||||
|
# 如果找到配置且有默认状态值,则更新记录状态
|
||||||
|
if quality_point and quality_point.quality_status:
|
||||||
|
original_state = record.quality_state
|
||||||
|
record.quality_state = quality_point.quality_status
|
||||||
|
|
||||||
|
_logger.info(
|
||||||
|
f"质量检查单状态已更新: {record.name}, "
|
||||||
|
f"产品: {record.product_id.name}, "
|
||||||
|
f"收料单: {record.picking_id.name}, "
|
||||||
|
f"状态: {original_state} -> {quality_point.quality_status}"
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
_logger.warning(f"更新质量检查单状态时发生错误: {record.name}, 错误: {str(e)}")
|
||||||
|
|
||||||
|
return records
|
||||||
140
sf_purchase_arrival_inform/models/storage_list.py
Normal file
140
sf_purchase_arrival_inform/models/storage_list.py
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
from odoo import models, fields, api
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
|
class StorageList(models.Model):
|
||||||
|
_name = 'storage.list'
|
||||||
|
_description = '收料入库明细'
|
||||||
|
_order = 'create_date desc'
|
||||||
|
|
||||||
|
# 基础关联字段
|
||||||
|
purchase_order_id = fields.Many2one('purchase.order', string='采购订单', required=True)
|
||||||
|
picking_id = fields.Many2one('stock.picking', string='收料入库单', readonly=True)
|
||||||
|
product_id = fields.Many2one('product.product', string='产品', required=True)
|
||||||
|
|
||||||
|
# 产品信息(基于product_id的related字段)
|
||||||
|
product_code = fields.Char(related='product_id.default_code', string='产品料号', store=True)
|
||||||
|
product_remark = fields.Text(string='产品说明')
|
||||||
|
part_number = fields.Char(string='零件图号')
|
||||||
|
|
||||||
|
# 数量字段
|
||||||
|
ordered_quantity = fields.Float(string='需求数量', required=True)
|
||||||
|
# 到货数量,默认=需求数量
|
||||||
|
current_arrival_quantity = fields.Float(string='到货数量', required=True)
|
||||||
|
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def create(self, vals):
|
||||||
|
# 如果没有设置current_arrival_quantity,则默认等于ordered_quantity
|
||||||
|
if 'current_arrival_quantity' not in vals and 'ordered_quantity' in vals:
|
||||||
|
vals['current_arrival_quantity'] = vals['ordered_quantity']
|
||||||
|
return super().create(vals)
|
||||||
|
|
||||||
|
@api.constrains('current_arrival_quantity')
|
||||||
|
def _check_current_arrival_quantity(self):
|
||||||
|
for line in self:
|
||||||
|
if line.current_arrival_quantity <= 0:
|
||||||
|
raise ValidationError('到货数量必须大于0')
|
||||||
|
if line.current_arrival_quantity > line.ordered_quantity:
|
||||||
|
raise ValidationError('当前到货数量不能超过需求数量')
|
||||||
|
|
||||||
|
def button_confirm(self):
|
||||||
|
"""更新采购订单行的收料数量"""
|
||||||
|
for record in self:
|
||||||
|
# 查找对应的采购订单行
|
||||||
|
order_line = self.env['purchase.order.line'].search([
|
||||||
|
('order_id', '=', record.purchase_order_id.id),
|
||||||
|
('product_id', '=', record.product_id.id)
|
||||||
|
], limit=1)
|
||||||
|
|
||||||
|
if order_line:
|
||||||
|
# 累加当前记录的到货数量到采购订单行
|
||||||
|
order_line.arrival_quantity += record.current_arrival_quantity
|
||||||
|
|
||||||
|
# 更新质量检查单状态为待处理
|
||||||
|
if self:
|
||||||
|
self._update_quality_check_status(self[0].purchase_order_id)
|
||||||
|
|
||||||
|
|
||||||
|
def _update_quality_check_status(self, purchase_order):
|
||||||
|
"""更新质量检查单状态为待处理
|
||||||
|
Args:
|
||||||
|
purchase_order: 采购订单记录
|
||||||
|
Returns:
|
||||||
|
int: 更新的质量检查单数量
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# 获取当前到货通知涉及的收料入库单
|
||||||
|
storage_records = self.env['storage.list'].search([
|
||||||
|
('purchase_order_id', '=', purchase_order.id)
|
||||||
|
])
|
||||||
|
if not storage_records:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# 收集所有相关的picking_id和product_id(过滤空值)
|
||||||
|
picking_ids = [pid for pid in storage_records.mapped('picking_id.id') if pid]
|
||||||
|
product_ids = [pid for pid in storage_records.mapped('product_id.id') if pid]
|
||||||
|
|
||||||
|
if not picking_ids or not product_ids:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# 构建质量检查单搜索域,包含等待和待处理状态
|
||||||
|
base_domain = [
|
||||||
|
('quality_state', 'in', ['waiting', 'none']),
|
||||||
|
('product_id', 'in', product_ids),
|
||||||
|
]
|
||||||
|
|
||||||
|
# 方法1:通过picking_id精确匹配质量检查单
|
||||||
|
quality_checks_by_picking = self.env['quality.check'].search(
|
||||||
|
base_domain + [('picking_id', 'in', picking_ids)]
|
||||||
|
)
|
||||||
|
|
||||||
|
# 方法2:通过move_id匹配(更精确,因为一个picking可能有多个move)
|
||||||
|
stock_moves = self.env['stock.move'].search([
|
||||||
|
('picking_id', 'in', picking_ids),
|
||||||
|
('product_id', 'in', product_ids),
|
||||||
|
])
|
||||||
|
|
||||||
|
quality_checks_by_move = self.env['quality.check']
|
||||||
|
if stock_moves:
|
||||||
|
quality_checks_by_move = self.env['quality.check'].search(
|
||||||
|
base_domain + [('move_id', 'in', stock_moves.ids)]
|
||||||
|
)
|
||||||
|
|
||||||
|
# 方法3:通过move_line_id匹配(最精确)
|
||||||
|
move_lines = self.env['stock.move.line'].search([
|
||||||
|
('picking_id', 'in', picking_ids),
|
||||||
|
('product_id', 'in', product_ids),
|
||||||
|
])
|
||||||
|
|
||||||
|
quality_checks_by_move_line = self.env['quality.check']
|
||||||
|
if move_lines:
|
||||||
|
quality_checks_by_move_line = self.env['quality.check'].search(
|
||||||
|
base_domain + [('move_line_id', 'in', move_lines.ids)]
|
||||||
|
)
|
||||||
|
|
||||||
|
# 合并所有匹配的质量检查单(去重)
|
||||||
|
all_quality_checks = quality_checks_by_picking | quality_checks_by_move | quality_checks_by_move_line
|
||||||
|
|
||||||
|
if not all_quality_checks:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# 批量更新状态为待处理
|
||||||
|
all_quality_checks.write({'quality_state': 'none'})
|
||||||
|
|
||||||
|
# 记录日志
|
||||||
|
product_names = storage_records.mapped('product_id.name')
|
||||||
|
purchase_order.message_post(
|
||||||
|
body=f"到货通知确认:已更新 {len(all_quality_checks)} 个质量检查单状态为待处理<br/>"
|
||||||
|
f"涉及产品:{', '.join(product_names)}<br/>"
|
||||||
|
f"涉及收料入库单:{', '.join([p.name or '' for p in storage_records.mapped('picking_id')])}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return len(all_quality_checks)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
# 记录错误日志,但不阻断流程
|
||||||
|
purchase_order.message_post(
|
||||||
|
body=f"更新质量检查单状态时发生错误:{str(e)}"
|
||||||
|
)
|
||||||
|
return 0
|
||||||
4
sf_purchase_arrival_inform/security/ir.model.access.csv
Normal file
4
sf_purchase_arrival_inform/security/ir.model.access.csv
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
|
access_storage_list,storage.list,model_storage_list,purchase.group_purchase_user,1,1,1,1
|
||||||
|
access_purchase_confirm_wizard,purchase.confirm.wizard,model_purchase_confirm_wizard,purchase.group_purchase_user,1,1,1,1
|
||||||
|
access_purchase_confirm_wizard_line,purchase.confirm.wizard.line,model_purchase_confirm_wizard_line,purchase.group_purchase_user,1,1,1,1
|
||||||
|
27
sf_purchase_arrival_inform/views/product_category.xml
Normal file
27
sf_purchase_arrival_inform/views/product_category.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<data>
|
||||||
|
<!-- 继承产品分类视图 -->
|
||||||
|
<record id="product_category_form_view_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">product.category.form.inherit</field>
|
||||||
|
<field name="model">product.category</field>
|
||||||
|
<field name="inherit_id" ref="stock.product_category_form_view_inherit" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='removal_strategy_id']" position="after">
|
||||||
|
<field name="arrival_inform"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
<record id="quality_view_form" model="ir.ui.view">
|
||||||
|
<field name="name">arrival.inform.quality.point.view.form</field>
|
||||||
|
<field name="model">quality.point</field>
|
||||||
|
<field name="inherit_id" ref="mrp_workorder.quality_point_view_form_inherit_mrp"/>
|
||||||
|
<field name="mode">primary</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="picking_type_ids" position="after">
|
||||||
|
<field name="quality_status"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</odoo>
|
||||||
58
sf_purchase_arrival_inform/views/purchase_view.xml
Normal file
58
sf_purchase_arrival_inform/views/purchase_view.xml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<data>
|
||||||
|
<!-- 继承采购订单视图 -->
|
||||||
|
<record id="purchase_order_view_tree_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">purchase.order.tree.inherit</field>
|
||||||
|
<field name="model">purchase.order</field>
|
||||||
|
<field name="inherit_id" ref="purchase.purchase_order_view_tree"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='date_planned']" position="after">
|
||||||
|
<field name="total_received_quantity"/>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//tree" position="inside">
|
||||||
|
<button name="open_arrival_inform" string="到货通知" type="object" class="btn-primary"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
<record id="purchase_order_form" model="ir.ui.view">
|
||||||
|
<field name="name">purchase.order.form</field>
|
||||||
|
<field name="model">purchase.order</field>
|
||||||
|
<field name="inherit_id" ref="purchase.purchase_order_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='order_line']/tree" position="inside">
|
||||||
|
<field name="arrival_quantity"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- 到货通知form视图 -->
|
||||||
|
<record id="storage_list_wrapper_form" model="ir.ui.view">
|
||||||
|
<field name="name">storage.list.wrapper.form</field>
|
||||||
|
<field name="model">purchase.order</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="选择到货通知" create="false" duplicate="false">
|
||||||
|
<group>
|
||||||
|
<field name="name" readonly="1"/>
|
||||||
|
</group>
|
||||||
|
|
||||||
|
<field name="storage_list_ids">
|
||||||
|
<tree string="收料入库明细" editable="bottom" create="false" delete="true" export="false">
|
||||||
|
<field name="product_code"/>
|
||||||
|
<field name="product_id" readonly="1"/>
|
||||||
|
<field name="product_remark" widget="section_and_note_text" readonly="1"/>
|
||||||
|
<field name="part_number" readonly="1"/>
|
||||||
|
<field name="ordered_quantity" readonly="1"/>
|
||||||
|
<field name="current_arrival_quantity" attrs="{'invisible': [('ordered_quantity', '=', '0')]}"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<button name="confirm_arrival_inform" string="确认" type="object" class="btn-primary" data-hotkey="q"/>
|
||||||
|
<button string="取消" class="btn-secondary" special="cancel" data-hotkey="z"/>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</odoo>
|
||||||
2
sf_purchase_arrival_inform/wizard/__init__.py
Normal file
2
sf_purchase_arrival_inform/wizard/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from . import purchase_confirm_wizard
|
||||||
|
|
||||||
64
sf_purchase_arrival_inform/wizard/purchase_confirm_wizard.py
Normal file
64
sf_purchase_arrival_inform/wizard/purchase_confirm_wizard.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
from odoo import models, fields, api, _
|
||||||
|
|
||||||
|
|
||||||
|
class PurchaseConfirmWizard(models.TransientModel):
|
||||||
|
_name = 'purchase.confirm.wizard'
|
||||||
|
_description = '采购订单确认向导'
|
||||||
|
|
||||||
|
purchase_order_id = fields.Many2one('purchase.order', string='采购订单', required=True)
|
||||||
|
line_ids = fields.One2many('purchase.confirm.wizard.line', 'wizard_id', string='产品明细')
|
||||||
|
|
||||||
|
@api.model_create_multi
|
||||||
|
def create(self, vals_list):
|
||||||
|
"""创建向导时自动生成产品明细"""
|
||||||
|
records = super().create(vals_list)
|
||||||
|
|
||||||
|
for record in records:
|
||||||
|
if record.purchase_order_id:
|
||||||
|
# 自动创建产品明细行
|
||||||
|
line_data = []
|
||||||
|
for line in record.purchase_order_id.order_line:
|
||||||
|
line_data.append({
|
||||||
|
'wizard_id': record.id,
|
||||||
|
'product_id': line.product_id.id,
|
||||||
|
'product_name': line.product_id.name,
|
||||||
|
'product_qty': line.product_qty,
|
||||||
|
'product_uom': line.product_uom.name,
|
||||||
|
'uom_rounding': line.product_uom.rounding,
|
||||||
|
})
|
||||||
|
|
||||||
|
if line_data:
|
||||||
|
self.env['purchase.confirm.wizard.line'].create(line_data)
|
||||||
|
|
||||||
|
return records
|
||||||
|
|
||||||
|
def action_confirm(self):
|
||||||
|
"""确认采购订单"""
|
||||||
|
if self.purchase_order_id:
|
||||||
|
# 调用原始的确认方法
|
||||||
|
self.purchase_order_id._execute_original_confirm()
|
||||||
|
|
||||||
|
# 返回关闭向导并刷新采购订单页面
|
||||||
|
return {
|
||||||
|
'type': 'ir.actions.act_window_close',
|
||||||
|
'infos': {
|
||||||
|
'title': _('成功'),
|
||||||
|
'message': _('采购订单已确认成功!'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def action_cancel(self):
|
||||||
|
"""取消操作"""
|
||||||
|
return {'type': 'ir.actions.act_window_close'}
|
||||||
|
|
||||||
|
|
||||||
|
class PurchaseConfirmWizardLine(models.TransientModel):
|
||||||
|
_name = 'purchase.confirm.wizard.line'
|
||||||
|
_description = '采购订单确认向导明细'
|
||||||
|
|
||||||
|
wizard_id = fields.Many2one('purchase.confirm.wizard', string='向导', ondelete='cascade')
|
||||||
|
product_id = fields.Many2one('product.product', string='产品')
|
||||||
|
product_name = fields.Char(string='产品名称')
|
||||||
|
product_qty = fields.Float(string='数量')
|
||||||
|
product_uom = fields.Char(string='单位')
|
||||||
|
uom_rounding = fields.Float(string='舍入精度')
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<!-- 采购订单确认向导视图 -->
|
||||||
|
<record id="purchase_confirm_wizard_form" model="ir.ui.view">
|
||||||
|
<field name="name">purchase.confirm.wizard.form</field>
|
||||||
|
<field name="model">purchase.confirm.wizard</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="采购订单确认">
|
||||||
|
<div class="alert alert-warning" role="alert">
|
||||||
|
<strong>确认提示:</strong>以下产品数量将按单位舍入精度向上取整处理,请核实后确认是否继续。
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<group>
|
||||||
|
<field name="purchase_order_id" readonly="1"/>
|
||||||
|
</group>
|
||||||
|
|
||||||
|
<separator string="产品明细信息"/>
|
||||||
|
|
||||||
|
<field name="line_ids" readonly="1" nolabel="1" widget="one2many_list">
|
||||||
|
<tree decoration-info="True" create="false" edit="false">
|
||||||
|
<field name="product_name" string="产品名称" width="40%"/>
|
||||||
|
<field name="product_qty" string="订购数量" width="20%"/>
|
||||||
|
<field name="product_uom" string="计量单位" width="20%"/>
|
||||||
|
<field name="uom_rounding" string="舍入精度" widget="float" digits="[16,6]" width="20%"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<button name="action_confirm" string="确认订单" type="object" class="btn-primary"/>
|
||||||
|
<button name="action_cancel" string="取消" type="object" class="btn-secondary"/>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
@@ -155,7 +155,7 @@ class ReSaleOrder(models.Model):
|
|||||||
'glb_url': item['glb_url'],
|
'glb_url': item['glb_url'],
|
||||||
'remark': item.get('remark'),
|
'remark': item.get('remark'),
|
||||||
'embryo_redundancy_id': item.get('embryo_redundancy_id'),
|
'embryo_redundancy_id': item.get('embryo_redundancy_id'),
|
||||||
'is_incoming_material': True if item.get('embryo_redundancy_id') else False,
|
'is_incoming_material': True if item.get('incoming_size') else False,
|
||||||
'manual_quotation': item.get('manual_quotation'),
|
'manual_quotation': item.get('manual_quotation'),
|
||||||
'model_id': item['model_id'],
|
'model_id': item['model_id'],
|
||||||
'delivery_end_date': item['delivery_end_date']
|
'delivery_end_date': item['delivery_end_date']
|
||||||
@@ -287,7 +287,7 @@ class ResaleOrderLine(models.Model):
|
|||||||
check_status = fields.Selection(related='order_id.check_status')
|
check_status = fields.Selection(related='order_id.check_status')
|
||||||
remark = fields.Char('备注')
|
remark = fields.Char('备注')
|
||||||
|
|
||||||
is_incoming_material = fields.Boolean('客供料', compute='_compute_is_incoming_material', store=True)
|
is_incoming_material = fields.Boolean('客供料', store=True)
|
||||||
embryo_redundancy_id = fields.Many2one('sf.embryo.redundancy', '坯料冗余')
|
embryo_redundancy_id = fields.Many2one('sf.embryo.redundancy', '坯料冗余')
|
||||||
manual_quotation = fields.Boolean('人工编程', default=False)
|
manual_quotation = fields.Boolean('人工编程', default=False)
|
||||||
model_url = fields.Char('模型文件地址')
|
model_url = fields.Char('模型文件地址')
|
||||||
|
|||||||
Reference in New Issue
Block a user