Compare commits
46 Commits
feature/72
...
feature/72
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3872cb3b93 | ||
|
|
6fa4590dbd | ||
|
|
e4c3435840 | ||
|
|
2a7048dafd | ||
|
|
2bb215f9df | ||
|
|
a2be3a0dbf | ||
|
|
1f4ceab377 | ||
|
|
94d727e8e0 | ||
|
|
42d9f894dd | ||
|
|
9416d1c1a0 | ||
|
|
7dd44ca12c | ||
|
|
5a98b20988 | ||
|
|
2738085a1e | ||
|
|
61c1fdbd05 | ||
|
|
7eea5a0ff2 | ||
|
|
714c68c0c1 | ||
|
|
f3e7ba7f68 | ||
|
|
df589b43e7 | ||
|
|
8bdc65c626 | ||
|
|
0c3407572f | ||
|
|
e5404efb60 | ||
|
|
46f60028aa | ||
|
|
bfc071debd | ||
|
|
7fca59322e | ||
|
|
42694c1ac6 | ||
|
|
e88fc012ec | ||
|
|
ff7cd9c927 | ||
|
|
588b7d340f | ||
|
|
5902d61f13 | ||
|
|
8cfad007b9 | ||
|
|
5008210176 | ||
|
|
f487ab4cce | ||
|
|
0441f345ef | ||
|
|
3527105e83 | ||
|
|
88e4cfb541 | ||
|
|
5a175c078f | ||
|
|
20980bed9d | ||
|
|
9b94357439 | ||
|
|
5ae3c5dd47 | ||
|
|
60be14dda2 | ||
|
|
f0ff7c4a74 | ||
|
|
2b6e2fe31b | ||
|
|
f1390e47c9 | ||
|
|
c7cd0a6a69 | ||
|
|
fa5307a2ea | ||
|
|
4706bfe85e |
@@ -41,8 +41,10 @@ class StockPicking(models.Model):
|
|||||||
if backorder_ids:
|
if backorder_ids:
|
||||||
purchase_request_lines = self.move_ids.move_orig_ids.purchase_line_id.purchase_request_lines
|
purchase_request_lines = self.move_ids.move_orig_ids.purchase_line_id.purchase_request_lines
|
||||||
if purchase_request_lines:
|
if purchase_request_lines:
|
||||||
purchase_request_lines.move_dest_ids = [
|
purchase_request_lines.move_dest_ids = [
|
||||||
(4, x.id) for x in backorder_ids.move_ids if x.product_id.id in purchase_request_lines.mapped('product_id.id')
|
(4, x.id) for x in backorder_ids.move_ids if
|
||||||
|
x.product_id.id in purchase_request_lines.mapped('product_id.id') and \
|
||||||
|
not x.created_purchase_request_line_id
|
||||||
]
|
]
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
|
||||||
});
|
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
""",
|
""",
|
||||||
'category': 'sf',
|
'category': 'sf',
|
||||||
'website': 'https://www.sf.jikimo.com',
|
'website': 'https://www.sf.jikimo.com',
|
||||||
'depends': ['sf_plan','jikimo_printing'],
|
'depends': ['sf_plan','jikimo_printing'],
|
||||||
'data': [
|
'data': [
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'data/stock_route_group.xml',
|
'data/stock_route_group.xml',
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
'web.assets_backend': [
|
'web.assets_backend': [
|
||||||
'sf_demand_plan/static/src/scss/style.css',
|
'sf_demand_plan/static/src/scss/style.css',
|
||||||
'sf_demand_plan/static/src/js/print_demand.js',
|
'sf_demand_plan/static/src/js/print_demand.js',
|
||||||
|
'sf_demand_plan/static/src/js/custom_button.js',
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'license': 'LGPL-3',
|
'license': 'LGPL-3',
|
||||||
|
|||||||
@@ -18,3 +18,12 @@ class MrpBom(models.Model):
|
|||||||
subcontract = self.get_supplier(product.materials_type_id)
|
subcontract = self.get_supplier(product.materials_type_id)
|
||||||
bom_id.subcontractor_id = subcontract.partner_id.id
|
bom_id.subcontractor_id = subcontract.partner_id.id
|
||||||
return bom_id
|
return bom_id
|
||||||
|
|
||||||
|
def name_get(self):
|
||||||
|
"""重写name_get方法,只显示BOM编码"""
|
||||||
|
result = []
|
||||||
|
for record in self:
|
||||||
|
# 只显示BOM编码,如果编码为空则显示产品名称
|
||||||
|
display_name = record.code or record.product_tmpl_id.name or f'BOM-{record.id}'
|
||||||
|
result.append((record.id, display_name))
|
||||||
|
return result
|
||||||
@@ -36,7 +36,7 @@ class PurchaseOrderLine(models.Model):
|
|||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
res = super(PurchaseOrderLine, self).create(vals)
|
res = super(PurchaseOrderLine, self).create(vals)
|
||||||
if not res.demand_plan_line_id:
|
if not res.demand_plan_line_id and res.order_id.origin:
|
||||||
origin = [origin.replace(' ', '') for origin in res.order_id.origin.split(',')]
|
origin = [origin.replace(' ', '') for origin in res.order_id.origin.split(',')]
|
||||||
if self.env.context.get('demand_plan_line_id'):
|
if self.env.context.get('demand_plan_line_id'):
|
||||||
res.demand_plan_line_id = self.env.context.get('demand_plan_line_id')
|
res.demand_plan_line_id = self.env.context.get('demand_plan_line_id')
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ class SfDemandPlan(models.Model):
|
|||||||
|
|
||||||
blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类',
|
blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类',
|
||||||
related='product_id.blank_type')
|
related='product_id.blank_type')
|
||||||
|
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型',
|
||||||
|
related='product_id.blank_precision')
|
||||||
|
manual_quotation = fields.Boolean('人工编程', related='product_id.manual_quotation', default=False)
|
||||||
embryo_long = fields.Char('坯料尺寸(mm)', compute='_compute_embryo_long', store=True)
|
embryo_long = fields.Char('坯料尺寸(mm)', compute='_compute_embryo_long', store=True)
|
||||||
is_incoming_material = fields.Boolean('客供料', related='sale_order_line_id.is_incoming_material', store=True)
|
is_incoming_material = fields.Boolean('客供料', related='sale_order_line_id.is_incoming_material', store=True)
|
||||||
pending_qty = fields.Float(
|
pending_qty = fields.Float(
|
||||||
@@ -112,7 +115,10 @@ class SfDemandPlan(models.Model):
|
|||||||
def _compute_embryo_long(self):
|
def _compute_embryo_long(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
if line.product_id:
|
if line.product_id:
|
||||||
line.embryo_long = f"{round(line.product_id.model_long, 3)}*{round(line.product_id.model_width, 3)}*{round(line.product_id.model_height, 3)}"
|
if line.product_id.blank_type == '圆料':
|
||||||
|
line.embryo_long = f"Ø{round(line.product_id.model_width, 3)}*{round(line.product_id.model_long, 3)}"
|
||||||
|
else:
|
||||||
|
line.embryo_long = f"{round(line.product_id.model_long, 3)}*{round(line.product_id.model_width, 3)}*{round(line.product_id.model_height, 3)}"
|
||||||
else:
|
else:
|
||||||
line.embryo_long = None
|
line.embryo_long = None
|
||||||
|
|
||||||
@@ -209,19 +215,24 @@ class SfDemandPlan(models.Model):
|
|||||||
def name_get(self):
|
def name_get(self):
|
||||||
result = []
|
result = []
|
||||||
for plan in self:
|
for plan in self:
|
||||||
result.append((plan.id, plan.product_id.name))
|
result.append((plan.id, plan.demand_plan_number))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def button_production_release_plan(self):
|
def button_production_release_plan(self):
|
||||||
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 {
|
||||||
'name': _('需求计划'),
|
'name': _('需求计划'),
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
@@ -237,11 +248,12 @@ class SfDemandPlan(models.Model):
|
|||||||
else:
|
else:
|
||||||
for demand_plan_line_id in line_ids:
|
for demand_plan_line_id in line_ids:
|
||||||
demand_plan_line_id.action_confirm()
|
demand_plan_line_id.action_confirm()
|
||||||
#需求要求取值格式是来源+来源明细行ID,但是来源明细行ID取得就是product_id.name得最后一位,所以这里也直接截取product_id.name
|
|
||||||
|
# 需求要求取值格式是来源+来源明细行ID,但是来源明细行ID取得就是product_id.name得最后一位,所以这里也直接截取product_id.name
|
||||||
@api.depends('product_id.name')
|
@api.depends('product_id.name')
|
||||||
def _compute_demand_plan_number(self):
|
def _compute_demand_plan_number(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
product_name = line.product_id.name or ''
|
product_name = line.product_id.name or ''
|
||||||
plan_no = None
|
plan_no = None
|
||||||
if line.product_id:
|
if line.product_id:
|
||||||
# 使用正则表达式匹配P-后面的所有字符
|
# 使用正则表达式匹配P-后面的所有字符
|
||||||
@@ -250,4 +262,4 @@ class SfDemandPlan(models.Model):
|
|||||||
plan_no = match.group(1)
|
plan_no = match.group(1)
|
||||||
line.demand_plan_number = plan_no
|
line.demand_plan_number = plan_no
|
||||||
else:
|
else:
|
||||||
line.demand_plan_number = None
|
line.demand_plan_number = None
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
_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', '待确认'),
|
||||||
('30', '需求确认'),
|
('30', '待工艺设计'),
|
||||||
('50', '待下达生产'),
|
('50', '待下达生产'),
|
||||||
('60', '已下达'),
|
('60', '已下达'),
|
||||||
('100', '取消'),
|
('100', '取消'),
|
||||||
@@ -34,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文件地址')
|
||||||
@@ -81,8 +81,9 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
related='product_id.blank_type')
|
related='product_id.blank_type')
|
||||||
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型',
|
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型',
|
||||||
related='product_id.blank_precision')
|
related='product_id.blank_precision')
|
||||||
|
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='表面工艺', )
|
||||||
@@ -126,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',
|
||||||
@@ -169,6 +176,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
finished_product_arrival_date = fields.Date('采购计划到货(成品)')
|
finished_product_arrival_date = fields.Date('采购计划到货(成品)')
|
||||||
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
|
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
|
||||||
location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, readonly=True)
|
location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, readonly=True)
|
||||||
|
manual_quotation = fields.Boolean('人工编程', related='product_id.manual_quotation', default=False)
|
||||||
|
|
||||||
@api.constrains('plan_uom_qty')
|
@api.constrains('plan_uom_qty')
|
||||||
def _check_plan_uom_qty(self):
|
def _check_plan_uom_qty(self):
|
||||||
@@ -176,15 +184,22 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
if line_ids:
|
if line_ids:
|
||||||
raise ValidationError(_("计划量不能小于等于0"))
|
raise ValidationError(_("计划量不能小于等于0"))
|
||||||
|
|
||||||
@api.constrains('new_supply_method')
|
@api.constrains('supply_method')
|
||||||
def _check_new_supply_method(self):
|
def _check_supply_method(self):
|
||||||
product_name = []
|
product_name = []
|
||||||
|
product = []
|
||||||
for line in self:
|
for line in self:
|
||||||
if line.new_supply_method == 'purchase' and line.is_incoming_material:
|
if line.supply_method == 'purchase' and line.is_incoming_material:
|
||||||
product_name.append(line.product_id.display_name)
|
product_name.append(line.product_id.display_name)
|
||||||
|
if line.supply_method == 'automation' and line.manual_quotation:
|
||||||
|
product.append(line.product_id.display_name)
|
||||||
|
|
||||||
if product_name:
|
if product_name:
|
||||||
unique_product_names = list(set(product_name))
|
unique_product_names = list(set(product_name))
|
||||||
raise UserError('当前(%s)产品为客供料,不能选择外购' % ','.join(unique_product_names))
|
raise UserError('当前(%s)产品为客供料,不能选择外购' % ','.join(unique_product_names))
|
||||||
|
if product:
|
||||||
|
unique_product = list(set(product))
|
||||||
|
raise UserError('当前(%s)产品为人工编程,不能选择自动化产线加工' % ','.join(unique_product))
|
||||||
|
|
||||||
@api.depends('new_supply_method')
|
@api.depends('new_supply_method')
|
||||||
def _compute_custom_made_type(self):
|
def _compute_custom_made_type(self):
|
||||||
@@ -344,9 +359,12 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
pro_plan.do_production_schedule()
|
pro_plan.do_production_schedule()
|
||||||
|
|
||||||
def update_sale_order_state(self):
|
def update_sale_order_state(self):
|
||||||
demand_plan = self.env['sf.demand.plan'].sudo().search([('sale_order_id', '=', self.sale_order_id.id)])
|
# demand_plan = self.env['sf.demand.plan'].sudo().search([('sale_order_id', '=', self.sale_order_id.id)])
|
||||||
demand_plan_state = demand_plan.filtered(lambda line: line.state != '40')
|
# demand_plan_state = demand_plan.filtered(lambda line: line.state != '40')
|
||||||
if not demand_plan_state:
|
production_demand_plan = self.env['sf.production.demand.plan'].sudo().search(
|
||||||
|
[('sale_order_id', '=', self.sale_order_id.id)])
|
||||||
|
production_demand_plan_state = production_demand_plan.filtered(lambda line: line.status in ('10', '20', '30'))
|
||||||
|
if not production_demand_plan_state:
|
||||||
# 修改销售订单为加工中
|
# 修改销售订单为加工中
|
||||||
self.sale_order_id.state = 'processing'
|
self.sale_order_id.state = 'processing'
|
||||||
|
|
||||||
@@ -587,7 +605,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
def unlink(self):
|
def unlink(self):
|
||||||
for item in self:
|
for item in self:
|
||||||
if item.status not in ('10', '20', '30'):
|
if item.status not in ('10', '20', '30'):
|
||||||
raise ValidationError(u'只能删除状态为【草稿,待确认,需求确认】的需求计划。')
|
raise ValidationError(u'只能删除状态为【草稿,待确认,待工艺设计】的需求计划。')
|
||||||
else:
|
else:
|
||||||
super(SfProductionDemandPlan, item).unlink()
|
super(SfProductionDemandPlan, item).unlink()
|
||||||
|
|
||||||
@@ -595,14 +613,14 @@ 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:
|
||||||
|
check_overdelivery_allowed = False
|
||||||
|
if not plan.demand_plan_id.overdelivery_allowed:
|
||||||
|
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
||||||
|
if plan.location_id.id == customer_location_id:
|
||||||
|
check_overdelivery_allowed = True
|
||||||
if plan.product_id not in product_data:
|
if plan.product_id not in product_data:
|
||||||
# 初始化产品数据,从产品上获取需求量
|
# 初始化产品数据,从产品上获取需求量
|
||||||
product_data[plan.product_id] = {
|
product_data[plan.product_id] = {
|
||||||
@@ -612,17 +630,22 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
|
|
||||||
# 累加计划数量
|
# 累加计划数量
|
||||||
product_data[plan.product_id]['plan_uom_qty'] += plan.plan_uom_qty
|
product_data[plan.product_id]['plan_uom_qty'] += plan.plan_uom_qty
|
||||||
|
product_data[plan.product_id]['overdelivery_allowed'] = check_overdelivery_allowed
|
||||||
# 检查需求超过计划数量的产品
|
# 检查需求超过计划数量的产品
|
||||||
warning_messages = []
|
warning_messages = []
|
||||||
|
error_messages = []
|
||||||
for product, data in product_data.items():
|
for product, data in product_data.items():
|
||||||
if float_compare(data['plan_uom_qty'], data['product_uom_qty'],
|
if data['overdelivery_allowed'] and float_compare(data['plan_uom_qty'], data['product_uom_qty'],precision_rounding=product.uom_id.rounding) == 1:
|
||||||
precision_rounding=product.uom_id.rounding) == 1:
|
error_messages.append(f"您正在下达的产品 {product.display_name},已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
||||||
|
elif float_compare(data['plan_uom_qty'], data['product_uom_qty'],
|
||||||
|
precision_rounding=product.uom_id.rounding) == 1:
|
||||||
warning_messages.append(
|
warning_messages.append(
|
||||||
_("您正在下达的产品 %s,计划量%s,需求数量为%s,已超过需求数量") %
|
_("您正在下达的产品 %s,计划量%s,需求数量为%s,已超过需求数量") %
|
||||||
(product.display_name, data['plan_uom_qty'], data['product_uom_qty'])
|
(product.display_name, data['plan_uom_qty'], data['product_uom_qty'])
|
||||||
)
|
)
|
||||||
if warning_messages and check_overdelivery_allowed:
|
if error_messages:
|
||||||
raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
error_message = "\n".join(error_messages)
|
||||||
|
raise ValidationError(error_message)
|
||||||
elif warning_messages:
|
elif warning_messages:
|
||||||
warning_message = "\n".join(warning_messages)
|
warning_message = "\n".join(warning_messages)
|
||||||
return {
|
return {
|
||||||
@@ -637,20 +660,26 @@ 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 not self.new_supply_method:
|
if self.is_processing:
|
||||||
raise ValidationError(f"供货方式不能为空!")
|
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')
|
||||||
if self.location_id.id == customer_location_id:
|
if self.location_id.id == customer_location_id:
|
||||||
check_overdelivery_allowed = True
|
check_overdelivery_allowed = True
|
||||||
if check_overdelivery_allowed:
|
if check_overdelivery_allowed:
|
||||||
if float_compare(self.plan_uom_qty, self.product_uom_qty,precision_rounding=self.product_id.uom_id.rounding) == 1:
|
if float_compare(self.plan_uom_qty, self.product_uom_qty,
|
||||||
|
precision_rounding=self.product_id.uom_id.rounding) == 1:
|
||||||
raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
||||||
elif float_compare(self.plan_uom_qty, self.product_uom_qty,precision_rounding=self.product_id.uom_id.rounding) == 1:
|
elif float_compare(self.plan_uom_qty, self.product_uom_qty,
|
||||||
|
precision_rounding=self.product_id.uom_id.rounding) == 1:
|
||||||
return {
|
return {
|
||||||
'name': _('需求计划'),
|
'name': _('需求计划'),
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
@@ -666,18 +695,49 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
self.action_confirm()
|
self.action_confirm()
|
||||||
|
|
||||||
def action_confirm(self):
|
def action_confirm(self):
|
||||||
self = self.with_context(
|
|
||||||
demand_plan_line_id=self.id
|
#确认需求计划行,创建 BOM、触发库存规则,并更新状态。
|
||||||
)
|
|
||||||
|
# 将当前需求计划行 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()
|
||||||
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(包含胚料与成品 BOM),用于后续生产或采购流程。
|
||||||
|
|
||||||
|
# 如果同一计划中已有对应的 BOM 可复用,则直接使用
|
||||||
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'))
|
||||||
@@ -690,32 +750,32 @@ 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 = ''
|
bom_type = ''
|
||||||
# 根据供货方式修改成品模板
|
|
||||||
if self.supply_method == 'automation':
|
if self.supply_method == 'automation':
|
||||||
bom_type = 'normal'
|
bom_type = 'normal'
|
||||||
product_template_id = self.env.ref('sf_dlm.product_template_sf').sudo().product_tmpl_id
|
product_template_id = self.env.ref('sf_dlm.product_template_sf').sudo().product_tmpl_id
|
||||||
elif self.supply_method == 'outsourcing':
|
elif self.supply_method == 'outsourcing':
|
||||||
bom_type = 'subcontract'
|
bom_type = 'subcontract'
|
||||||
product_template_id = self.env.ref(
|
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_outsourcing').sudo()
|
||||||
'jikimo_sale_multiple_supply_methods.product_template_outsourcing').sudo()
|
|
||||||
elif self.supply_method == 'purchase':
|
elif self.supply_method == 'purchase':
|
||||||
product_template_id = self.env.ref(
|
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_purchase').sudo()
|
||||||
'jikimo_sale_multiple_supply_methods.product_template_purchase').sudo()
|
|
||||||
elif self.supply_method == 'manual':
|
elif self.supply_method == 'manual':
|
||||||
bom_type = 'normal'
|
bom_type = 'normal'
|
||||||
product_template_id = self.env.ref(
|
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo()
|
||||||
'jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo()
|
|
||||||
|
|
||||||
# 复制成品模板上的属性
|
# 使用模板复制内容到当前产品
|
||||||
self.product_id.product_tmpl_id.copy_template(product_template_id)
|
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,
|
||||||
@@ -728,110 +788,81 @@ 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()
|
||||||
customer_provided_embryo = self.env.ref(
|
embryo_key = 'material_customer_provided'
|
||||||
'jikimo_sale_multiple_supply_methods.product_template_embryo_customer_provided').sudo()
|
else:
|
||||||
# 创建坯料,客供料的批量不需要创建bom
|
embryo_template = self._get_embryo_template_by_supply_method()
|
||||||
material_customer_provided_embryo = self.env['product.template'].sudo().no_bom_product_create(
|
embryo_key = self.supply_method
|
||||||
customer_provided_embryo.with_context(active_test=False).product_variant_id,
|
|
||||||
item,
|
# 获取批次追踪方式
|
||||||
order_id, 'material_customer_provided', product_seria, product)
|
tracking_method = embryo_template.tracking
|
||||||
# 成品配置bom
|
|
||||||
product_bom_material_customer_provided = self.env['mrp.bom'].with_user(
|
# 创建胚料产品(无 BOM 产品)
|
||||||
self.env.ref("base.user_admin")).bom_create(
|
embryo_product = self.env['product.template'].sudo().no_bom_product_create(
|
||||||
product, bom_type, 'product', code)
|
embryo_template.with_context(active_test=False).product_variant_id,
|
||||||
product_bom_material_customer_provided.with_user(
|
item,
|
||||||
self.env.ref("base.user_admin")).bom_create_line_has(
|
order_id,
|
||||||
material_customer_provided_embryo)
|
embryo_key,
|
||||||
self.bom_id = product_bom_material_customer_provided.id
|
product_seria,
|
||||||
elif self.product_id.materials_type_id.gain_way == '自加工':
|
product
|
||||||
self_machining_id = self.env.ref('sf_dlm.product_embryo_sf_self_machining').sudo()
|
)
|
||||||
# 创建坯料
|
|
||||||
self_machining_embryo = self.env['product.template'].sudo().no_bom_product_create(
|
if embryo_product == -3:
|
||||||
self_machining_id,
|
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
|
||||||
item,
|
|
||||||
order_id, 'self_machining', product_seria, product)
|
# 设置胚料 BOM 类型
|
||||||
# 创建坯料的bom
|
if embryo_key in ('automation', 'manual', 'material_customer_provided'):
|
||||||
self_machining_bom = self.env['mrp.bom'].with_user(
|
embryo_bom_type = 'normal'
|
||||||
self.env.ref("base.user_admin")).bom_create(
|
elif embryo_key == 'outsourcing':
|
||||||
self_machining_embryo, 'normal', False)
|
embryo_bom_type = 'subcontract'
|
||||||
# 创建坯料里bom的组件
|
elif embryo_key == 'purchase':
|
||||||
self_machining_bom_line = self_machining_bom.with_user(
|
embryo_bom_type = 'purchase'
|
||||||
self.env.ref("base.user_admin")).bom_create_line(
|
else:
|
||||||
self_machining_embryo)
|
embryo_bom_type = 'normal'
|
||||||
if not self_machining_bom_line:
|
|
||||||
raise UserError('该订单模型的材料型号暂未有原材料,请先配置再进行分配')
|
# 创建胚料 BOM 及 BOM 行
|
||||||
# 产品配置bom
|
embryo_bom = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).bom_create(
|
||||||
product_bom_self_machining = self.env['mrp.bom'].with_user(
|
embryo_product, embryo_bom_type, True, tracking=tracking_method)
|
||||||
self.env.ref("base.user_admin")).bom_create(
|
|
||||||
product, bom_type, 'product', code)
|
embryo_bom_line = embryo_bom.with_user(self.env.ref("base.user_admin")).bom_create_line(embryo_product)
|
||||||
product_bom_self_machining.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
|
if not embryo_bom_line:
|
||||||
self_machining_embryo)
|
raise UserError('该订单模型的材料型号暂未有原材料,请先配置再进行分配')
|
||||||
self.bom_id = product_bom_self_machining.id
|
|
||||||
elif self.product_id.materials_type_id.gain_way == '外协':
|
# 创建成品 BOM(包含胚料)
|
||||||
outsource_id = self.env.ref('sf_dlm.product_embryo_sf_outsource').sudo()
|
product_bom = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).bom_create(
|
||||||
# 创建坯料
|
product, bom_type, 'product', code, tracking=tracking_method)
|
||||||
outsource_embryo = self.env['product.template'].sudo().no_bom_product_create(outsource_id,
|
product_bom.with_user(self.env.ref("base.user_admin")).bom_create_line_has(embryo_product)
|
||||||
item,
|
|
||||||
order_id,
|
# 赋值 BOM ID
|
||||||
'subcontract',
|
self.bom_id = product_bom.id
|
||||||
product_seria,
|
|
||||||
product)
|
|
||||||
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})
|
||||||
@@ -839,27 +870,42 @@ 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,
|
||||||
@@ -867,11 +913,18 @@ 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,
|
||||||
@@ -887,4 +940,8 @@ 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
|
||||||
|
|||||||
59
sf_demand_plan/static/src/js/custom_button.js
Normal file
59
sf_demand_plan/static/src/js/custom_button.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import { registry } from "@web/core/registry";
|
||||||
|
import { ListRenderer } from "@web/views/list/list_renderer";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
import { useEffect } from "@odoo/owl";
|
||||||
|
|
||||||
|
export class CustomDemandPlanListRenderer extends ListRenderer {
|
||||||
|
setup() {
|
||||||
|
super.setup();
|
||||||
|
this.orm = useService("orm");
|
||||||
|
this.notification = useService("notification");
|
||||||
|
console.log('setup', this.props);
|
||||||
|
|
||||||
|
// 监听selection属性的变化
|
||||||
|
useEffect(() => {
|
||||||
|
this.updateButtonState();
|
||||||
|
}, () => [this.props.list.selection]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新按钮状态
|
||||||
|
*/
|
||||||
|
async updateButtonState() {
|
||||||
|
const selectedRecords = this.props.list.selection;
|
||||||
|
const isStatus30 = selectedRecords.some(record => record.data.status != "30");
|
||||||
|
const button = $(this.__owl__.parent.bdom.parentEl).find('button[name="button_batch_release_plan"]');
|
||||||
|
console.log('isStatus30', isStatus30, button);
|
||||||
|
if (isStatus30) {
|
||||||
|
// 禁用按钮
|
||||||
|
button.attr('disabled', true);
|
||||||
|
} else {
|
||||||
|
button.attr('disabled', false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 使用setTimeout延迟注册,避免在模块加载时立即执行
|
||||||
|
setTimeout(() => {
|
||||||
|
const registerCustomRenderer = () => {
|
||||||
|
try {
|
||||||
|
const listView = registry.category("views").get("list");
|
||||||
|
if (listView) {
|
||||||
|
registry.category("views").add("custom_demand_plan_list", {
|
||||||
|
...listView,
|
||||||
|
Renderer: CustomDemandPlanListRenderer,
|
||||||
|
});
|
||||||
|
console.log("Custom demand plan list renderer registered successfully");
|
||||||
|
} else {
|
||||||
|
console.warn("List view not found, retrying...");
|
||||||
|
// 如果还没找到,再等一段时间
|
||||||
|
setTimeout(registerCustomRenderer, 1000);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error registering custom renderer:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
registerCustomRenderer();
|
||||||
|
}, 1000);
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
th[data-name=processing_time] + th::before{
|
/*.demand_plan_tree th[data-name=planned_start_date] + th::before{*/
|
||||||
content: '待执行单据';
|
/* content: '待执行单据';*/
|
||||||
line-height: 38px;
|
/* line-height: 38px;*/
|
||||||
}
|
/*}*/
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
<field name="model">sf.production.demand.plan</field>
|
<field name="model">sf.production.demand.plan</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="需求计划" default_order="sequence desc,id desc" editable="bottom"
|
<tree string="需求计划" default_order="sequence desc,id desc" editable="bottom"
|
||||||
class="demand_plan_tree freeze-columns-before-part_number" create="false" delete="false">
|
class="demand_plan_tree freeze-columns-before-part_number" create="false" delete="false"
|
||||||
|
js_class="custom_demand_plan_list">
|
||||||
<header>
|
<header>
|
||||||
<button string="打印" name="button_action_print" type="object"
|
<button string="打印" name="button_action_print" type="object"
|
||||||
class="btn-primary"/>
|
class="btn-primary"/>
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
<field name="model_id" optional="hide"/>
|
<field name="model_id" optional="hide"/>
|
||||||
<field name="part_name"/>
|
<field name="part_name"/>
|
||||||
<field name="part_number"/>
|
<field name="part_number"/>
|
||||||
|
<field name="manual_quotation" optional="hide"/>
|
||||||
<field name="is_incoming_material"/>
|
<field name="is_incoming_material"/>
|
||||||
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||||
<field name="readonly_custom_made_type" invisible="1"/>
|
<field name="readonly_custom_made_type" invisible="1"/>
|
||||||
@@ -31,13 +33,14 @@
|
|||||||
<field name="product_uom_qty"/>
|
<field name="product_uom_qty"/>
|
||||||
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||||
<field name="deadline_of_delivery"/>
|
<field name="deadline_of_delivery"/>
|
||||||
<field name="inventory_quantity_auto_apply"/>
|
<field name="inventory_quantity_auto_apply" optional="hide"/>
|
||||||
<field name="qty_delivered"/>
|
<field name="qty_delivered" optional="hide"/>
|
||||||
<field name="qty_to_deliver"/>
|
<field name="qty_to_deliver" optional="hide"/>
|
||||||
<field name="model_long"/>
|
<field name="model_long"/>
|
||||||
<field name="blank_type" optional="hide"/>
|
<field name="blank_type" optional="hide"/>
|
||||||
<field name="blank_precision"/>
|
<field name="blank_precision"/>
|
||||||
<field name="embryo_long"/>
|
<field name="embryo_long"/>
|
||||||
|
<field name="unit_number" optional="hide"/>
|
||||||
<field name="materials_id"/>
|
<field name="materials_id"/>
|
||||||
<field name="model_machining_precision"/>
|
<field name="model_machining_precision"/>
|
||||||
<field name="model_process_parameters_ids" widget="many2many_tags"/>
|
<field name="model_process_parameters_ids" widget="many2many_tags"/>
|
||||||
|
|||||||
@@ -20,7 +20,9 @@
|
|||||||
<field name="part_number"/>
|
<field name="part_number"/>
|
||||||
<field name="materials_id"/>
|
<field name="materials_id"/>
|
||||||
<field name="blank_type"/>
|
<field name="blank_type"/>
|
||||||
<field name="embryo_long"/>
|
<field name="blank_precision"/>
|
||||||
|
<field name="embryo_long"/>
|
||||||
|
<field name="manual_quotation"/>
|
||||||
<field name="is_incoming_material"/>
|
<field name="is_incoming_material"/>
|
||||||
<field name="pending_qty"/>
|
<field name="pending_qty"/>
|
||||||
<field name="planned_qty"/>
|
<field name="planned_qty"/>
|
||||||
@@ -86,7 +88,7 @@
|
|||||||
'required': [('new_supply_method', '=', 'custom_made')]}"/>
|
'required': [('new_supply_method', '=', 'custom_made')]}"/>
|
||||||
<field name="route_ids" widget="many2many_tags" optional="hide"/>
|
<field name="route_ids" widget="many2many_tags" optional="hide"/>
|
||||||
<field name="location_id" optional="hide"/>
|
<field name="location_id" optional="hide"/>
|
||||||
<field name="bom_id" optional="hide"/>
|
<field name="bom_id" optional="hide" readonly="1" options="{'no_create': True}"/>
|
||||||
<field name="processing_time" optional="hide"/>
|
<field name="processing_time" optional="hide"/>
|
||||||
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||||
<field name="blank_arrival_date"/>
|
<field name="blank_arrival_date"/>
|
||||||
@@ -106,6 +108,9 @@
|
|||||||
class="btn-primary"
|
class="btn-primary"
|
||||||
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
||||||
/>
|
/>
|
||||||
|
<button string="详情" name="button_plan_detail" type="object"
|
||||||
|
class="btn-primary"
|
||||||
|
/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</page>
|
</page>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
|||||||
if pdf_data:
|
if pdf_data:
|
||||||
try:
|
try:
|
||||||
# 执行打印
|
# 执行打印
|
||||||
self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
|
# self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
|
||||||
record.status = 'success'
|
record.status = 'success'
|
||||||
production_demand_plan_id = self.env['sf.production.demand.plan'].sudo().search(
|
production_demand_plan_id = self.env['sf.production.demand.plan'].sudo().search(
|
||||||
[('model_id', '=', record.model_id)])
|
[('model_id', '=', record.model_id)])
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import logging
|
import logging
|
||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -17,4 +18,10 @@ class SfReleasePlanWizard(models.TransientModel):
|
|||||||
def confirm(self):
|
def confirm(self):
|
||||||
if self.demand_plan_line_id:
|
if self.demand_plan_line_id:
|
||||||
for demand_plan_line_id in self.demand_plan_line_id:
|
for demand_plan_line_id in self.demand_plan_line_id:
|
||||||
demand_plan_line_id.action_confirm()
|
try:
|
||||||
|
demand_plan_line_id.action_confirm()
|
||||||
|
except Exception as e:
|
||||||
|
self.env.cr.rollback()
|
||||||
|
demand_plan_line_id.write({'is_processing': False})
|
||||||
|
self.env.cr.commit()
|
||||||
|
raise InternalServerError('操作失败', e)
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
@@ -217,7 +217,8 @@ class StockRule(models.Model):
|
|||||||
'''
|
'''
|
||||||
创建制造订单时生成序列号
|
创建制造订单时生成序列号
|
||||||
'''
|
'''
|
||||||
production.action_generate_serial()
|
if production.product_id.tracking != "none":
|
||||||
|
production.action_generate_serial()
|
||||||
origin_production = production.move_dest_ids and production.move_dest_ids[
|
origin_production = production.move_dest_ids and production.move_dest_ids[
|
||||||
0].raw_material_production_id or False
|
0].raw_material_production_id or False
|
||||||
orderpoint = production.orderpoint_id
|
orderpoint = production.orderpoint_id
|
||||||
@@ -442,7 +443,7 @@ class ProductionLot(models.Model):
|
|||||||
@api.model
|
@api.model
|
||||||
def _get_next_serial(self, company, product):
|
def _get_next_serial(self, company, product):
|
||||||
"""Return the next serial number to be attributed to the product."""
|
"""Return the next serial number to be attributed to the product."""
|
||||||
if product.tracking == "serial":
|
if product.tracking != "none":
|
||||||
last_serial = self.env['stock.lot'].search(
|
last_serial = self.env['stock.lot'].search(
|
||||||
[('company_id', '=', company.id), ('product_id', '=', product.id), ('name', 'ilike', product.name)],
|
[('company_id', '=', company.id), ('product_id', '=', product.id), ('name', 'ilike', product.name)],
|
||||||
limit=1, order='name desc')
|
limit=1, order='name desc')
|
||||||
@@ -453,7 +454,9 @@ class ProductionLot(models.Model):
|
|||||||
return self.env['stock.lot'].generate_lot_names1(product.name, last_serial.name if (
|
return self.env['stock.lot'].generate_lot_names1(product.name, last_serial.name if (
|
||||||
not move_line_id or
|
not move_line_id or
|
||||||
(last_serial and last_serial.name > move_line_id.lot_name)) else move_line_id.lot_name, 2)[1]
|
(last_serial and last_serial.name > move_line_id.lot_name)) else move_line_id.lot_name, 2)[1]
|
||||||
return "%s-%03d" % (product.name, 1)
|
else:
|
||||||
|
return "%s-%03d" % (product.name, 1)
|
||||||
|
return False
|
||||||
|
|
||||||
qr_code_image = fields.Binary(string='二维码', compute='_generate_qr_code')
|
qr_code_image = fields.Binary(string='二维码', compute='_generate_qr_code')
|
||||||
|
|
||||||
|
|||||||
@@ -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