修复未保存需求计划删除明细行问题,打印列表显示
This commit is contained in:
@@ -11,7 +11,7 @@ class ReSaleOrder(models.Model):
|
|||||||
groups='mrp.group_mrp_user', store=True)
|
groups='mrp.group_mrp_user', store=True)
|
||||||
|
|
||||||
demand_plan_ids = fields.Many2many(comodel_name="sf.demand.plan",
|
demand_plan_ids = fields.Many2many(comodel_name="sf.demand.plan",
|
||||||
string="需求计划", readonly=True)
|
string="需求计划", readonly=True)
|
||||||
|
|
||||||
demand_plan_count = fields.Integer(
|
demand_plan_count = fields.Integer(
|
||||||
string="需求计划生成计数",
|
string="需求计划生成计数",
|
||||||
@@ -47,9 +47,9 @@ class ReSaleOrder(models.Model):
|
|||||||
if demand_plan.product_id.machining_drawings_name:
|
if demand_plan.product_id.machining_drawings_name:
|
||||||
filename_url = demand_plan.product_id.machining_drawings_name.rsplit('.', 1)[0]
|
filename_url = demand_plan.product_id.machining_drawings_name.rsplit('.', 1)[0]
|
||||||
wizard_vals = {
|
wizard_vals = {
|
||||||
'demand_plan_id': demand_plan.id,
|
|
||||||
'model_id': demand_plan.model_id,
|
'model_id': demand_plan.model_id,
|
||||||
'filename_url': filename_url,
|
'filename_url': filename_url,
|
||||||
|
'machining_drawings': product.machining_drawings,
|
||||||
'type': '1',
|
'type': '1',
|
||||||
}
|
}
|
||||||
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
|
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
|
||||||
|
|||||||
@@ -167,7 +167,9 @@ class SfDemandPlan(models.Model):
|
|||||||
def _compute_state(self):
|
def _compute_state(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
status_line = line.line_ids.filtered(lambda p: p.status == '60')
|
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.state = '50'
|
||||||
line.line_ids.status = '100'
|
line.line_ids.status = '100'
|
||||||
elif len(line.line_ids) == len(status_line):
|
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')
|
lambda p: p.status in ('50', '60') and p.new_supply_method == 'custom_made')
|
||||||
line.readonly_custom_made_type = bool(production_demand_plan)
|
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):
|
def write(self, vals):
|
||||||
res = super(SfDemandPlan, self).write(vals)
|
res = super(SfDemandPlan, self).write(vals)
|
||||||
if 'line_ids' in vals:
|
if 'line_ids' in vals:
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
custom_made_type = fields.Selection([
|
custom_made_type = fields.Selection([
|
||||||
('automation', "自动化产线加工"),
|
('automation', "自动化产线加工"),
|
||||||
('manual', "人工线下加工"),
|
('manual', "人工线下加工"),
|
||||||
], string='自制类型', compute='_compute_custom_made_type', store=True)
|
], string='产线类型', compute='_compute_custom_made_type', store=True)
|
||||||
|
|
||||||
supply_method = fields.Selection([
|
supply_method = fields.Selection([
|
||||||
('automation', "自动化产线加工"),
|
('automation', "自动化产线加工"),
|
||||||
@@ -360,11 +360,12 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
return action
|
return action
|
||||||
|
|
||||||
def button_action_print(self):
|
def button_action_print(self):
|
||||||
|
model_id = self.mapped('model_id')
|
||||||
return {
|
return {
|
||||||
'res_model': 'sf.demand.plan.print.wizard',
|
'res_model': 'sf.demand.plan.print.wizard',
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
'name': _("打印"),
|
'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']],
|
'views': [[self.env.ref('sf_demand_plan.action_plan_print_tree').id, 'list']],
|
||||||
'target': 'new',
|
'target': 'new',
|
||||||
}
|
}
|
||||||
@@ -577,12 +578,13 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
# programming_no = list(set(programming_mrp_production_ids))
|
# programming_no = list(set(programming_mrp_production_ids))
|
||||||
# numbers_str = "、".join(programming_no)
|
# numbers_str = "、".join(programming_no)
|
||||||
# raise ValidationError(f"编程单号:{numbers_str},请去云平台处理")
|
# raise ValidationError(f"编程单号:{numbers_str},请去云平台处理")
|
||||||
|
@api.model
|
||||||
def button_delete(self):
|
def unlink(self):
|
||||||
self.ensure_one()
|
for item in self:
|
||||||
if len(self.demand_plan_id.line_ids) == 1:
|
if item.status not in ('10', '20', '30'):
|
||||||
raise ValidationError(f"最后一条计划,不能删除!")
|
raise ValidationError(u'只能删除状态为【草稿,待确认,需求确认】的需求计划。')
|
||||||
self.unlink()
|
else:
|
||||||
|
super(SfProductionDemandPlan, item).unlink()
|
||||||
|
|
||||||
def button_batch_release_plan(self):
|
def button_batch_release_plan(self):
|
||||||
filtered_plan = self.filtered(lambda mo: mo.status == '30')
|
filtered_plan = self.filtered(lambda mo: mo.status == '30')
|
||||||
|
|||||||
@@ -39,8 +39,8 @@
|
|||||||
</group>
|
</group>
|
||||||
<notebook>
|
<notebook>
|
||||||
<page string="计划">
|
<page string="计划">
|
||||||
<field name="line_ids" attrs="{'readonly': [('state', 'in', ('40','50'))]}">
|
<field name="line_ids" attrs="{'invisible': [('state', 'in', ('40','50'))]}">
|
||||||
<tree editable="bottom" delete="false">
|
<tree editable="bottom" create="false" delete="false">
|
||||||
<field name="status"/>
|
<field name="status"/>
|
||||||
<field name="readonly_custom_made_type" invisible="1"/>
|
<field name="readonly_custom_made_type" invisible="1"/>
|
||||||
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||||
@@ -51,6 +51,7 @@
|
|||||||
<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"/>
|
||||||
|
<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"/>
|
||||||
<field name="finished_product_arrival_date"/>
|
<field name="finished_product_arrival_date"/>
|
||||||
@@ -69,10 +70,39 @@
|
|||||||
class="btn-primary"
|
class="btn-primary"
|
||||||
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
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"
|
class="btn-primary"
|
||||||
attrs="{'invisible': [('status', 'not in', ('10','20','30'))]}"
|
attrs="{'invisible': [('status', 'in', ('50','60','100'))]}"
|
||||||
confirm='是否确认删除?'/>
|
/>
|
||||||
|
<button name="button_release_production" type="object" string="下发生产"
|
||||||
|
class="btn-primary"
|
||||||
|
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
||||||
|
/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</page>
|
</page>
|
||||||
|
|||||||
@@ -9,11 +9,6 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
|||||||
_name = 'sf.demand.plan.print.wizard'
|
_name = 'sf.demand.plan.print.wizard'
|
||||||
_description = u'打印向导'
|
_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')
|
model_id = fields.Char('模型ID')
|
||||||
filename_url = fields.Char('文件名/URL')
|
filename_url = fields.Char('文件名/URL')
|
||||||
type = fields.Selection([
|
type = fields.Selection([
|
||||||
@@ -25,7 +20,7 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
|||||||
('success', '成功'),
|
('success', '成功'),
|
||||||
('fail', '失败'),
|
('fail', '失败'),
|
||||||
], string='状态', default='not_start')
|
], 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('程序单')
|
cnc_worksheet = fields.Binary('程序单')
|
||||||
|
|
||||||
@@ -44,14 +39,17 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
|||||||
# 执行打印
|
# 执行打印
|
||||||
self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
|
self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
|
||||||
record.status = 'success'
|
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(
|
||||||
t_num = int(t_part[1:])
|
[('model_id', '=', record.model_id)])
|
||||||
c_num = int(c_part)
|
for production_demand_plan in production_demand_plan_id:
|
||||||
if record.type == '1':
|
t_part, c_part = production_demand_plan.print_count.split('C')
|
||||||
t_num += 1
|
t_num = int(t_part[1:])
|
||||||
elif record.type == '2':
|
c_num = int(c_part)
|
||||||
c_num += 1
|
if record.type == '1':
|
||||||
record.demand_plan_id.print_count = f"T{t_num}C{c_num}"
|
t_num += 1
|
||||||
|
elif record.type == '2':
|
||||||
|
c_num += 1
|
||||||
|
production_demand_plan.print_count = f"T{t_num}C{c_num}"
|
||||||
success_records.append({
|
success_records.append({
|
||||||
'filename_url': record.filename_url,
|
'filename_url': record.filename_url,
|
||||||
})
|
})
|
||||||
@@ -78,18 +76,14 @@ class MrpWorkorder(models.Model):
|
|||||||
demand_plan_print = self.env['sf.demand.plan.print.wizard'].sudo().search(
|
demand_plan_print = self.env['sf.demand.plan.print.wizard'].sudo().search(
|
||||||
[('model_id', '=', record.model_id), ('type', '=', '2')])
|
[('model_id', '=', record.model_id), ('type', '=', '2')])
|
||||||
if demand_plan_print:
|
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})
|
{'cnc_worksheet': record.cnc_worksheet, 'filename_url': record.cnc_worksheet_name})
|
||||||
else:
|
else:
|
||||||
demand_plan = self.env['sf.production.demand.plan'].sudo().search(
|
wizard_vals = {
|
||||||
[('product_id', '=', record.product_id.id)])
|
'model_id': record.model_id,
|
||||||
if demand_plan:
|
'type': '2',
|
||||||
wizard_vals = {
|
'cnc_worksheet': record.cnc_worksheet,
|
||||||
'demand_plan_id': demand_plan.id,
|
'filename_url': record.cnc_worksheet_name
|
||||||
'model_id': demand_plan.model_id,
|
}
|
||||||
'type': '2',
|
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
|
||||||
'cnc_worksheet': record.cnc_worksheet,
|
|
||||||
'filename_url': record.cnc_worksheet_name
|
|
||||||
}
|
|
||||||
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
Reference in New Issue
Block a user