Compare commits

...

11 Commits

Author SHA1 Message Date
guanhuan
5a98b20988 下达计划按钮重复点击生成重复数据 2025-07-16 09:32:28 +08:00
hyyy
7eea5a0ff2 重复点击 2025-07-15 16:25:28 +08:00
guanhuan
0c3407572f 需求计划详情 2025-07-15 11:51:14 +08:00
hyyy
e5404efb60 批量下达计划禁用 2025-07-15 11:39:20 +08:00
guanhuan
46f60028aa 需求位置修改 2025-07-15 10:40:19 +08:00
guanhuan
bfc071debd 需求位置修改 2025-07-15 10:34:28 +08:00
guanhuan
ff7cd9c927 校验修改 2025-07-14 16:13:49 +08:00
guanhuan
588b7d340f Merge branch 'refs/heads/develop' into feature/物料需求计划管理 2025-07-14 15:52:10 +08:00
guanhuan
5902d61f13 新增单件用量显示 2025-07-14 15:39:37 +08:00
陈烨
8cfad007b9 Accept Merge Request #2283: (feature/7249 -> develop)
Merge Request: 合并 develop 分支到 feature/7249

Created By: @陈烨
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @陈烨
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2283
2025-07-14 14:29:24 +08:00
guanhuan
0441f345ef 新增单件用量显示 2025-07-14 14:11:28 +08:00
9 changed files with 132 additions and 42 deletions

View File

@@ -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',

View File

@@ -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')

View File

@@ -222,9 +222,6 @@ 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')
for line in self.line_ids:
if line.manual_quotation and line.custom_made_type == 'automation':
raise ValidationError(f"产品{line.product_id.name}为人工编程,不能选择自动化产线加工")
if not self.overdelivery_allowed and line_ids.filtered(lambda p: p.location_id.id == customer_location_id): if not self.overdelivery_allowed and line_ids.filtered(lambda p: p.location_id.id == customer_location_id):
if float_compare(sum_product_uom_qty, self.product_uom_qty, if 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:
@@ -246,6 +243,7 @@ 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):

View File

@@ -14,10 +14,10 @@ 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', '待确认'),
@@ -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',
@@ -170,21 +177,29 @@ class SfProductionDemandPlan(models.Model):
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) 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):
line_ids = self.filtered(lambda p: p.plan_uom_qty == 0 or p.plan_uom_qty < 0) line_ids = self.filtered(lambda p: p.plan_uom_qty == 0 or p.plan_uom_qty < 0)
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):
@@ -346,7 +361,8 @@ class SfProductionDemandPlan(models.Model):
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')
production_demand_plan = self.env['sf.production.demand.plan'].sudo().search([('sale_order_id', '=', self.sale_order_id.id)]) 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')) production_demand_plan_state = production_demand_plan.filtered(lambda line: line.status in ('10', '20', '30'))
if not production_demand_plan_state: if not production_demand_plan_state:
# 修改销售订单为加工中 # 修改销售订单为加工中
@@ -642,19 +658,20 @@ class SfProductionDemandPlan(models.Model):
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
if self.product_id.manual_quotation and self.custom_made_type == 'automation': self.is_processing = True
raise ValidationError(f"产品{self.product_id.name}为人工编程,不能选择自动化产线加工")
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',
@@ -683,18 +700,6 @@ class SfProductionDemandPlan(models.Model):
self.update_sale_order_state() self.update_sale_order_state()
def mrp_bom_create(self): def mrp_bom_create(self):
if self.supply_method in ('automation', 'manual'):
line_ids = self.demand_plan_id.line_ids.filtered(
lambda p: p.supply_method in ('automation', 'manual') and p.status in ('50', '60'))
if line_ids:
self.bom_id = line_ids[0].bom_id.id
return
elif self.supply_method == 'outsourcing':
line_ids = self.demand_plan_id.line_ids.filtered(
lambda p: p.supply_method == 'outsourcing' and p.status == '60')
if line_ids:
self.bom_id = line_ids[0].bom_id.id
return
bom_type = '' bom_type = ''
# 根据供货方式修改成品模板 # 根据供货方式修改成品模板
if self.supply_method == 'automation': if self.supply_method == 'automation':
@@ -714,6 +719,18 @@ class SfProductionDemandPlan(models.Model):
# 复制成品模板上的属性 # 复制成品模板上的属性
self.product_id.product_tmpl_id.copy_template(product_template_id) self.product_id.product_tmpl_id.copy_template(product_template_id)
if self.supply_method in ('automation', 'manual'):
line_ids = self.demand_plan_id.line_ids.filtered(
lambda p: p.supply_method in ('automation', 'manual') and p.status in ('50', '60'))
if line_ids:
self.bom_id = line_ids[0].bom_id.id
return
elif self.supply_method == 'outsourcing':
line_ids = self.demand_plan_id.line_ids.filtered(
lambda p: p.supply_method == 'outsourcing' and p.status == '60')
if line_ids:
self.bom_id = line_ids[0].bom_id.id
return
future_time = datetime.now() + timedelta(hours=8) future_time = datetime.now() + timedelta(hours=8)
# 生成BOM单据编码 # 生成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')}"
@@ -893,3 +910,6 @@ class SfProductionDemandPlan(models.Model):
'demand_plan_line_id': self.id 'demand_plan_line_id': self.id
} }
return values return values
def button_plan_detail(self):
pass

View 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);

View File

@@ -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"/>
@@ -39,6 +40,7 @@
<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"/>

View File

@@ -108,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>

View File

@@ -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)])

View File

@@ -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:
try:
demand_plan_line_id.action_confirm() 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)