修复未保存需求计划删除明细行问题,打印列表显示

This commit is contained in:
guanhuan
2025-07-10 14:11:31 +08:00
parent 4d2ab82645
commit 1f93ba3b42
5 changed files with 76 additions and 42 deletions

View File

@@ -47,9 +47,9 @@ class ReSaleOrder(models.Model):
if demand_plan.product_id.machining_drawings_name:
filename_url = demand_plan.product_id.machining_drawings_name.rsplit('.', 1)[0]
wizard_vals = {
'demand_plan_id': demand_plan.id,
'model_id': demand_plan.model_id,
'filename_url': filename_url,
'machining_drawings': product.machining_drawings,
'type': '1',
}
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)

View File

@@ -167,7 +167,9 @@ class SfDemandPlan(models.Model):
def _compute_state(self):
for line in self:
status_line = line.line_ids.filtered(lambda p: p.status == '60')
if line.sale_order_id.state == 'cancel':
if not line.line_ids:
line.state = '10'
elif line.sale_order_id.state == 'cancel':
line.state = '50'
line.line_ids.status = '100'
elif len(line.line_ids) == len(status_line):
@@ -184,6 +186,12 @@ class SfDemandPlan(models.Model):
lambda p: p.status in ('50', '60') and p.new_supply_method == 'custom_made')
line.readonly_custom_made_type = bool(production_demand_plan)
@api.constrains('line_ids')
def check_line_ids(self):
for item in self:
if not item.line_ids:
raise ValidationError('计划不能为空!')
def write(self, vals):
res = super(SfDemandPlan, self).write(vals)
if 'line_ids' in vals:

View File

@@ -56,7 +56,7 @@ class SfProductionDemandPlan(models.Model):
custom_made_type = fields.Selection([
('automation', "自动化产线加工"),
('manual', "人工线下加工"),
], string='自制类型', compute='_compute_custom_made_type', store=True)
], string='产线类型', compute='_compute_custom_made_type', store=True)
supply_method = fields.Selection([
('automation', "自动化产线加工"),
@@ -360,11 +360,12 @@ class SfProductionDemandPlan(models.Model):
return action
def button_action_print(self):
model_id = self.mapped('model_id')
return {
'res_model': 'sf.demand.plan.print.wizard',
'type': 'ir.actions.act_window',
'name': _("打印"),
'domain': [('demand_plan_id', 'in', self.ids)],
'domain': [('model_id', 'in', model_id)],
'views': [[self.env.ref('sf_demand_plan.action_plan_print_tree').id, 'list']],
'target': 'new',
}
@@ -577,12 +578,13 @@ class SfProductionDemandPlan(models.Model):
# programming_no = list(set(programming_mrp_production_ids))
# numbers_str = "、".join(programming_no)
# raise ValidationError(f"编程单号:{numbers_str},请去云平台处理")
def button_delete(self):
self.ensure_one()
if len(self.demand_plan_id.line_ids) == 1:
raise ValidationError(f"最后一条计划,不能删除!")
self.unlink()
@api.model
def unlink(self):
for item in self:
if item.status not in ('10', '20', '30'):
raise ValidationError(u'只能删除状态为【草稿,待确认,需求确认】的需求计划。')
else:
super(SfProductionDemandPlan, item).unlink()
def button_batch_release_plan(self):
filtered_plan = self.filtered(lambda mo: mo.status == '30')

View File

@@ -39,8 +39,8 @@
</group>
<notebook>
<page string="计划">
<field name="line_ids" attrs="{'readonly': [('state', 'in', ('40','50'))]}">
<tree editable="bottom" delete="false">
<field name="line_ids" attrs="{'invisible': [('state', 'in', ('40','50'))]}">
<tree editable="bottom" create="false" delete="false">
<field name="status"/>
<field name="readonly_custom_made_type" invisible="1"/>
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
@@ -51,6 +51,7 @@
<field name="route_ids" widget="many2many_tags" optional="hide"/>
<field name="location_id" optional="hide"/>
<field name="bom_id" optional="hide"/>
<field name="processing_time" optional="hide"/>
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
<field name="blank_arrival_date"/>
<field name="finished_product_arrival_date"/>
@@ -69,10 +70,39 @@
class="btn-primary"
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
/>
<button name="button_delete" type="object" string="删除"
</tree>
</field>
<field name="line_ids" attrs="{'invisible': [('state', 'not in', ('40','50'))]}">
<tree editable="bottom">
<field name="status"/>
<field name="readonly_custom_made_type" invisible="1"/>
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
<field name="custom_made_type"
attrs="{
'readonly': ['|', '|', ('new_supply_method', '!=', 'custom_made'), ('status', '!=', '30'), ('readonly_custom_made_type', '=', True)],
'required': [('new_supply_method', '=', 'custom_made')]}"/>
<field name="route_ids" widget="many2many_tags" optional="hide"/>
<field name="location_id" optional="hide"/>
<field name="bom_id" optional="hide"/>
<field name="processing_time" optional="hide"/>
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
<field name="blank_arrival_date"/>
<field name="finished_product_arrival_date"/>
<field name="planned_start_date"/>
<field name="actual_start_date"/>
<field name="actual_end_date"/>
<field name="plan_remark"/>
<field name="procurement_reason"/>
<field name="write_date" string="更新时间"/>
<field name="hide_release_production_order" invisible="1"/>
<button string="下达计划" name="button_release_plan" type="object"
class="btn-primary"
attrs="{'invisible': [('status', 'not in', ('10','20','30'))]}"
confirm='是否确认删除?'/>
attrs="{'invisible': [('status', 'in', ('50','60','100'))]}"
/>
<button name="button_release_production" type="object" string="下发生产"
class="btn-primary"
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
/>
</tree>
</field>
</page>

View File

@@ -9,11 +9,6 @@ class SfDemandPlanPrintWizard(models.TransientModel):
_name = 'sf.demand.plan.print.wizard'
_description = u'打印向导'
demand_plan_id = fields.Many2one('sf.production.demand.plan', string='需求计划ID')
product_id = fields.Many2one(
comodel_name='product.product',
related='demand_plan_id.product_id',
string='产品', store=True, index=True)
model_id = fields.Char('模型ID')
filename_url = fields.Char('文件名/URL')
type = fields.Selection([
@@ -25,7 +20,7 @@ class SfDemandPlanPrintWizard(models.TransientModel):
('success', '成功'),
('fail', '失败'),
], string='状态', default='not_start')
machining_drawings = fields.Binary('2D加工图纸', related='product_id.machining_drawings', store=True)
machining_drawings = fields.Binary('2D加工图纸')
cnc_worksheet = fields.Binary('程序单')
@@ -44,14 +39,17 @@ class SfDemandPlanPrintWizard(models.TransientModel):
# 执行打印
self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
record.status = 'success'
t_part, c_part = record.demand_plan_id.print_count.split('C')
production_demand_plan_id = self.env['sf.production.demand.plan'].sudo().search(
[('model_id', '=', record.model_id)])
for production_demand_plan in production_demand_plan_id:
t_part, c_part = production_demand_plan.print_count.split('C')
t_num = int(t_part[1:])
c_num = int(c_part)
if record.type == '1':
t_num += 1
elif record.type == '2':
c_num += 1
record.demand_plan_id.print_count = f"T{t_num}C{c_num}"
production_demand_plan.print_count = f"T{t_num}C{c_num}"
success_records.append({
'filename_url': record.filename_url,
})
@@ -78,15 +76,11 @@ class MrpWorkorder(models.Model):
demand_plan_print = self.env['sf.demand.plan.print.wizard'].sudo().search(
[('model_id', '=', record.model_id), ('type', '=', '2')])
if demand_plan_print:
self.env['sf.demand.plan.print.wizard'].sudo().write(
demand_plan_print.write(
{'cnc_worksheet': record.cnc_worksheet, 'filename_url': record.cnc_worksheet_name})
else:
demand_plan = self.env['sf.production.demand.plan'].sudo().search(
[('product_id', '=', record.product_id.id)])
if demand_plan:
wizard_vals = {
'demand_plan_id': demand_plan.id,
'model_id': demand_plan.model_id,
'model_id': record.model_id,
'type': '2',
'cnc_worksheet': record.cnc_worksheet,
'filename_url': record.cnc_worksheet_name