回退工艺外协代码

This commit is contained in:
胡尧
2025-05-15 11:07:22 +08:00
parent 5446ef18e2
commit c80e12d731
16 changed files with 430 additions and 406 deletions

View File

@@ -70,21 +70,21 @@ class ResMrpWorkOrder(models.Model):
delivery_warning = fields.Selection([('normal', '正常'), ('warning', '告警'), ('overdue', '逾期')], string='时效',
tracking=True)
back_button_display = fields.Boolean(default=False, compute='_compute_back_button_display', store=True)
pr_mp_count = fields.Integer('采购申请单数量', compute='_compute_pr_mp_count', store=True)
# pr_mp_count = fields.Integer('采购申请单数量', compute='_compute_pr_mp_count', store=True)
@api.depends('state')
def _compute_pr_mp_count(self):
for item in self:
if not item.is_subcontract:
item.pr_mp_count = 0
continue
pr_ids = self.env['purchase.request'].sudo().search(
[('origin', 'like', item.production_id.name), ('is_subcontract', '=', 'True'),
('state', '!=', 'rejected')])
if pr_ids:
item.pr_mp_count = len(pr_ids)
else:
item.pr_mp_count = 0
# @api.depends('state')
# def _compute_pr_mp_count(self):
# for item in self:
# if not item.is_subcontract:
# item.pr_mp_count = 0
# continue
# pr_ids = self.env['purchase.request'].sudo().search(
# [('origin', 'like', item.production_id.name), ('is_subcontract', '=', 'True'),
# ('state', '!=', 'rejected')])
# if pr_ids:
# item.pr_mp_count = len(pr_ids)
# else:
# item.pr_mp_count = 0
@api.depends('state')
def _compute_back_button_display(self):
@@ -444,11 +444,11 @@ class ResMrpWorkOrder(models.Model):
def _compute_surface_technics_purchase_ids(self):
for order in self:
if order.routing_type == '表面工艺' and order.state not in ['cancel']:
# domain = [('group_id', '=', self.production_id.procurement_group_id.id),
# ('purchase_type', '=', 'consignment'), ('state', '!=', 'cancel')]
domain = [('purchase_type', '=', 'consignment'),
('origin', 'like', '%' + self.production_id.name + '%'),
('state', '!=', 'cancel')]
domain = [('group_id', '=', self.production_id.procurement_group_id.id),
('purchase_type', '=', 'consignment'), ('state', '!=', 'cancel')]
# domain = [('purchase_type', '=', 'consignment'),
# ('origin', 'like', '%' + self.production_id.name + '%'),
# ('state', '!=', 'cancel')]
purchase = self.env['purchase.order'].search(domain)
order.surface_technics_purchase_count = 0
if not purchase:
@@ -461,30 +461,30 @@ class ResMrpWorkOrder(models.Model):
else:
order.surface_technics_purchase_count = 0
def action_view_pr_mrp_workorder(self):
"""
采购请求
"""
self.ensure_one()
pr_ids = self.env['purchase.request'].sudo().search(
[('origin', 'like', self.production_id.name), ('is_subcontract', '=', 'True'),
('state', '!=', 'rejected')])
action = {
'res_model': 'purchase.request',
'type': 'ir.actions.act_window',
}
if len(pr_ids) == 1:
action.update({
'view_mode': 'form',
'res_id': pr_ids[0].id,
})
else:
action.update({
'name': _("%s生成采购请求单", self.name),
'domain': [('id', 'in', pr_ids)],
'view_mode': 'tree,form',
})
return action
# def action_view_pr_mrp_workorder(self):
# """
# 采购请求
# """
# self.ensure_one()
# pr_ids = self.env['purchase.request'].sudo().search(
# [('origin', 'like', self.production_id.name), ('is_subcontract', '=', 'True'),
# ('state', '!=', 'rejected')])
# action = {
# 'res_model': 'purchase.request',
# 'type': 'ir.actions.act_window',
# }
# if len(pr_ids) == 1:
# action.update({
# 'view_mode': 'form',
# 'res_id': pr_ids[0].id,
# })
# else:
# action.update({
# 'name': _("从 %s生成采购请求单", self.name),
# 'domain': [('id', 'in', pr_ids)],
# 'view_mode': 'tree,form',
# })
# return action
def action_view_surface_technics_purchase(self):
self.ensure_one()
@@ -1245,12 +1245,12 @@ class ResMrpWorkOrder(models.Model):
}]
return workorders_values_str
def check_lot_exists(self, picking_id, lot_id):
return bool(
picking_id.move_ids.move_line_ids.filtered(
lambda line: line.lot_id.id == lot_id
)
)
# def check_lot_exists(self, picking_id, lot_id):
# return bool(
# picking_id.move_ids.move_line_ids.filtered(
# lambda line: line.lot_id.id == lot_id
# )
# )
def _process_compute_state(self):
sorted_workorders = sorted(self, key=lambda x: x.sequence)
@@ -1292,10 +1292,10 @@ class ResMrpWorkOrder(models.Model):
purchase_orders_id = self._get_surface_technics_purchase_ids()
if purchase_orders_id.state == 'purchase':
workorder.state = 'ready'
picking_id = workorder.production_id.picking_ids.filtered(
lambda wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区')
move_out = picking_id.move_ids
# move_out = workorder.move_subcontract_workorder_ids[1]
# picking_id = workorder.production_id.picking_ids.filtered(
# lambda wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区')
# move_out = picking_id.move_ids
move_out = workorder.move_subcontract_workorder_ids[1]
for mo in move_out:
if mo.state != 'done':
mo.write({'state': 'assigned', 'production_id': False})
@@ -1334,10 +1334,11 @@ class ResMrpWorkOrder(models.Model):
if purchase_orders_id:
if purchase_orders_id.state == 'purchase':
workorder.state = 'ready'
picking_id = workorder.production_id.picking_ids.filtered(
lambda
wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区')
move_out = picking_id.move_ids
move_out = workorder.move_subcontract_workorder_ids[1]
# picking_id = workorder.production_id.picking_ids.filtered(
# lambda
# wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区')
# move_out = picking_id.move_ids
for mo in move_out:
if mo.state != 'done':
mo.write({'state': 'assigned', 'production_id': False})
@@ -1411,9 +1412,10 @@ class ResMrpWorkOrder(models.Model):
# 表面工艺外协出库单
if self.routing_type == '表面工艺':
if self.is_subcontract is True:
picking_id = self.production_id.picking_ids.filtered(
lambda wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区')
move_out = picking_id.move_ids
move_out = self.move_subcontract_workorder_ids[1]
# picking_id = self.production_id.picking_ids.filtered(
# lambda wk: wk.location_id.name == '制造前' and wk.location_dest_id.name == '外协加工区')
# move_out = picking_id.move_ids
# move_out = self.move_subcontract_workorder_ids[1]
# move_out = self.env['stock.move'].search(
# [('location_id', '=', self.env['stock.location'].search(