添加退回调整

This commit is contained in:
jinling.yang
2024-11-12 17:53:17 +08:00
parent d646019c93
commit ff072a32bb
10 changed files with 246 additions and 139 deletions

View File

@@ -257,51 +257,49 @@ class MrpProduction(models.Model):
if production.tool_state == '2':
production.state = 'rework'
# 退回调整
def technology_back_adjust(self):
special_design = self.technology_design_ids.filtered(
lambda a: a.routing_tag == 'special' and a.is_auto is False and a.active in [True, False])
workorders_values = []
for item in special_design:
if item.active is False:
domain = [('production_id', '=', self.id)]
if item.surface_technics_parameters_id:
domain += [('surface_technics_parameters_id', '=', item.process_parameters_id)]
else:
domain += [('name', '=', item.route_id.name)]
workorder = self.env['mrp.workorder'].search(domain)
if workorder:
workorder.write({'state': 'cancel'})
else:
workorder = self.env['mrp.workorder'].search([('name', '=', item.route_id.name)])
if not workorder:
if item.route_id.routing_type == '表面工艺':
product_production_process = self.env['product.template'].search(
[('server_product_process_parameters_id', '=', item.process_parameters_id.id)])
workorders_values.append(
self.env[
'mrp.workorder']._json_workorder_surface_process_str(self, item,
product_production_process.seller_ids[
0].partner_id.id))
else:
workorders_values.append(
self.env['mrp.workorder'].json_workorder_str(self, item))
if workorders_values:
self.write({'workorder_ids': workorders_values})
self._reset_work_order_sequence()
domain = [('state', '=', 'confirmed')]
if self.production_type == '自动化产线加工':
cloud_programming = self._cron_get_programming_state()
if cloud_programming['send_state'] == 'sending':
raise UserError(_("编程文件正在下发中,请稍后重试"))
domain += [('programming_no', '=', self.programming_no)]
# 带排程的制造订单
production_confirmed = self.env['mrp.production'].search(domain)
if production_confirmed:
return {
'name': _('退回调整'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'sf.production.technology.re_adjust.wizard',
'target': 'new',
'context': {
'default_production_id': self.id,
'default_origin': self.origin,
}}
# 工艺确认
def technology_confirm(self):
process_parameters = []
account_moves = []
special_design = self.technology_design_ids.filtered(
lambda a: a.routing_tag == 'special' and a.process_parameters_id is not False)
lambda a: a.routing_tag == 'special' and a.active in [True, False] and special.is_auto is False)
for special in special_design:
if special.process_parameters_id:
if special.process_parameters_id and special.active is True:
product_production_process = self.env['product.template'].search(
[('server_product_process_parameters_id', '=', special.process_parameters_id.id)])
if not product_production_process:
if special.process_parameters_id not in process_parameters:
process_parameters.append(special.process_parameters_id.display_name)
if special.active is False:
purchase = self.env['purchase.order'].search([('origin', '=', special.production_id.name)])
account = self.env['account.move'].search([('id', 'in', purchase.invoice_ids)])
if account.state != 'cancel':
if purchase.name not in account_moves:
account_moves.append(purchase.name)
if account_moves:
raise UserError(_("请联系工厂生产经理对采购订单为%s生成的账单进行取消", ", ".join(account_moves)))
if process_parameters:
raise UserError(_("【工艺设计】-【参数】为%s的在【产品】中不存在,请先创建", ", ".join(process_parameters)))
# 判断同一个加工面的标准工序的顺序是否依次排序

View File

@@ -183,23 +183,37 @@ class ResMrpWorkOrder(models.Model):
for order in self:
if order.routing_type == '表面工艺':
production_programming = self.env['mrp.production'].search(
[('programming_no', '=', order.production_id.programming_no)], order='name asc')
[('origin', '=', order.production_id.origin)], order='name asc')
production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
production_list = [production.name for production in production_programming]
purchase = self.env['purchase.order'].search([('origin', '=', ','.join(production_list))])
technology_design = self.env['sf.technology.design'].search(
[('process_parameters_id', '=', order.surface_technics_parameters_id.id),
('production_id', '=', order.production_id.id)])
if technology_design.is_auto is False:
domain = [('origin', '=', order.production_id.name)]
else:
domain = [('origin', '=', ','.join(production_list))]
purchase = self.env['purchase.order'].search(domain)
for line in purchase.order_line:
if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id and line.product_qty == len(
production_no_remanufacture):
order.surface_technics_purchase_count = len(purchase)
if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id:
if (line.product_qty == len(production_no_remanufacture)) or technology_design.is_auto is False:
order.surface_technics_purchase_count = len(purchase)
else:
order.surface_technics_purchase_count = 0
def action_view_surface_technics_purchase(self):
self.ensure_one()
production_programming = self.env['mrp.production'].search(
[('programming_no', '=', self.production_id.programming_no)], order='name asc')
[('origin', '=', self.production_id.origin)], order='name asc')
production_list = [production.name for production in production_programming]
purchase_orders = self.env['purchase.order'].search([('origin', '=', ','.join(production_list))])
technology_design = self.env['sf.technology.design'].search(
[('process_parameters_id', '=', self.surface_technics_parameters_id.id),
('production_id', '=', self.production_id.id)])
if technology_design.is_auto is False:
domain = [('origin', '=', self.production_id.name)]
else:
domain = [('origin', '=', ','.join(production_list))]
purchase_orders = self.env['purchase.order'].search(domain)
result = {
"type": "ir.actions.act_window",
"res_model": "purchase.order",

View File

@@ -16,13 +16,13 @@ class sf_technology_design(models.Model):
is_auto = fields.Boolean('是否自动生成', default=False)
active = fields.Boolean('有效', default=True)
def json_technology_design_str(self, k, route, i):
def json_technology_design_str(self, k, route, i, process_parameter):
workorders_values_str = [0, '', {
'route_id': route.id,
'panel': k,
'process_parameters_id': False if route.routing_type != '表面工艺' else self.env[
'sf.production.process.parameter'].search(
[('process_id', '=', route.surface_technics_id.id)]).id,
[('id', '=', process_parameter.id)]).id,
'sequence': i,
'is_auto': True}]
return workorders_values_str

View File

@@ -372,7 +372,7 @@ class StockRule(models.Model):
for route in product_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(k, route, i))
self.env['sf.technology.design'].json_technology_design_str(k, route, i, False))
elif production.product_id.categ_id.type == '坯料':
embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
[('embryo_model_type_id', '=', production.product_id.embryo_model_type_id.id)],
@@ -381,26 +381,17 @@ class StockRule(models.Model):
for route_embryo in embryo_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str('', route_embryo, i))
self.env['sf.technology.design'].json_technology_design_str(False, route_embryo, i,
False))
surface_technics_arr = []
route_workcenter_arr = []
aa = production.product_id.model_process_parameters_ids.ids
aa1 = tuple(production.product_id.model_process_parameters_ids.ids)
aa2 = production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids.filtered(
lambda st: st.id == 12)
for process_param in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids.filtered(
lambda st: st.id in (12,16)):
# if item.route_workcenter_id.surface_technics_id.id:
# for process_param in production.product_id.model_process_parameters_ids:
logging.info('process_param:%s%s' % (process_param.id, process_param.name))
if item.route_workcenter_id.surface_technics_id == process_param.process_id:
logging.info(
'surface_technics_id:%s%s' % (
item.route_workcenter_id.surface_technics_id.id,
item.route_workcenter_id.surface_technics_id.name))
surface_technics_arr.append(
item.route_workcenter_id.surface_technics_id.id)
route_workcenter_arr.append(item.route_workcenter_id.id)
for item in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
if item.route_workcenter_id.surface_technics_id.id:
for process_param in production.product_id.model_process_parameters_ids:
if item.route_workcenter_id.surface_technics_id == process_param.process_id:
surface_technics_arr.append(
item.route_workcenter_id.surface_technics_id.id)
route_workcenter_arr.append(item.route_workcenter_id.id)
if surface_technics_arr:
production_process = self.env['sf.production.process'].search(
[('id', 'in', surface_technics_arr)],
@@ -410,9 +401,6 @@ class StockRule(models.Model):
logging.info('production_process:%s' % p.name)
process_parameter = production.product_id.model_process_parameters_ids.filtered(
lambda pm: pm.process_id.id == p.id)
product_production_process = self.env['product.template'].search(
[('server_product_process_parameters_id', '=',
process_parameter.id)])
if process_parameter:
i += 1
route_production_process = self.env[
@@ -420,21 +408,21 @@ class StockRule(models.Model):
[('surface_technics_id', '=', p.id),
('id', 'in', route_workcenter_arr)])
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(k,
self.env['sf.technology.design'].json_technology_design_str(False,
route_production_process,
product_production_process,
i))
i,
process_parameter))
productions.technology_design_ids = technology_design_values
# 同一个产品多个制造订单对应一个编程单和模型库
# 只调用一次fetchCNC并将所有生产订单的名称作为字符串传递
if not production_item.programming_no and production.production_type == '自动化产线加工':
if not production_programming.programming_no:
production_item.fetchCNC(
', '.join(product_id_to_production_names[production_item.product_id.id]))
else:
production_item.write({'programming_no': production_programming.programming_no,
'programming_state': '编程中'})
# if not production_item.programming_no and production.production_type == '自动化产线加工':
# if not production_programming.programming_no:
# production_item.fetchCNC(
# ', '.join(product_id_to_production_names[production_item.product_id.id]))
# else:
# production_item.write({'programming_no': production_programming.programming_no,
# 'programming_state': '编程中'})
return True