diff --git a/sf_manufacturing/models/sf_technology_design.py b/sf_manufacturing/models/sf_technology_design.py index 392aa021..02b844be 100644 --- a/sf_manufacturing/models/sf_technology_design.py +++ b/sf_manufacturing/models/sf_technology_design.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from collections import Counter + from odoo import fields, models, api, _ from odoo.exceptions import ValidationError @@ -6,7 +8,7 @@ from odoo.exceptions import ValidationError class sf_technology_design(models.Model): _name = 'sf.technology.design' _description = "工艺设计" - + group_uniq_id = fields.Integer('同一制造订单唯一id',default=0) sequence = fields.Integer('序号') route_id = fields.Many2one('mrp.routing.workcenter', '工序') process_parameters_id = fields.Many2one('sf.production.process.parameter', string='表面工艺参数') @@ -17,6 +19,11 @@ class sf_technology_design(models.Model): is_auto = fields.Boolean('是否自动生成', default=False) active = fields.Boolean('有效', default=True) + # @api.depends('production_id') + # def _compute_group_uniq_id(self): + # for record in self: + + def json_technology_design_str(self, k, route, i, process_parameter): workorders_values_str = [0, '', { 'route_id': route.id if route.routing_type in ['表面工艺'] else route.route_workcenter_id.id, @@ -28,6 +35,9 @@ class sf_technology_design(models.Model): 'is_auto': True}] return workorders_values_str + def write(self, vals): + print('qwfojkqwfkio') + return super(sf_technology_design, self).write(vals) def unlink_technology_design(self): self.active = False @@ -37,4 +47,63 @@ class sf_technology_design(models.Model): for vals in vals_list: if not vals.get('route_id'): raise ValidationError(_("工序不能为空")) - return super(sf_technology_design, self).create(vals_list) + result = super(sf_technology_design, self).create(vals_list) + for res in result: + record = self.search([('production_id', '=', res.production_id.id), ('active', 'in', [True, False])], order='group_uniq_id desc', limit=1) + res.group_uniq_id=record.group_uniq_id + 1 + return result + def get_duplicates_with_inactive(self,technology_designs): + # 统计每个 'sequence' 出现的次数 + sequence_count = Counter(technology_design.sequence for technology_design in technology_designs) + + # 筛选出 'sequence' 重复且 'active' 为 False 的元素 + result = [ + technology_design for technology_design in technology_designs + if sequence_count[technology_design.sequence] > 1 and technology_design.active is False + ] + + return result + # def rearrange_numbering(self,self_technology_designs): + # inactive_designs = self.get_duplicates_with_inactive(self_technology_designs) + # if inactive_designs: + # max_design = max(self_technology_designs, key=lambda x: x.sequence) + # max_sequence = max_design.sequence if max_design else 0 + # for designs in inactive_designs: + # max_sequence += 1 + # designs.sequence = max_sequence + # self_technology_designs.sorted(key=lambda techology_design:techology_design.sequence) + # return self_technology_designs + + def get_technology_design(self): + return { + 'sequence':self.sequence, + 'route_id': self.route_id.id, + 'process_parameters_id': self.process_parameters_id.id, + 'panel': self.panel, + 'routing_tag': self.routing_tag, + 'time_cycle_manual': self.time_cycle_manual, + 'is_auto': self.is_auto, + 'active': self.active, + 'group_uniq_id':self.group_uniq_id, + } + def sync_technology_designs(self,production_technology_designs, self_technology_designs): + production_id = production_technology_designs[0].production_id.id + self_technology_design_dict = {item.group_uniq_id:item for item in self_technology_designs} + production_technology_designs_dict = {item.group_uniq_id:item for item in production_technology_designs} + for technology_design in production_technology_designs: + if not self_technology_design_dict.get(technology_design.group_uniq_id): + technology_design.write({'production_id': False}) + else: + technology_design.write(self_technology_design_dict.get(technology_design.group_uniq_id).get_technology_design()) + for technology_design in self_technology_designs: + if not production_technology_designs_dict.get(technology_design.group_uniq_id): + technology_design = technology_design.get_technology_design() + technology_design.update({'production_id': production_id}) + self.env['sf.technology.design'].create(technology_design) + + + + def unified_procedure_multiple_work_orders(self,self_technology_designs,production_item): + technology_designs = self.env['sf.technology.design'].sudo().search( + [('production_id', '=', production_item.id), ('active', 'in', [True, False])]) + self.sync_technology_designs(self_technology_designs=self_technology_designs,production_technology_designs=technology_designs) \ No newline at end of file diff --git a/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py b/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py index efc0e449..5bd32b8c 100644 --- a/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py +++ b/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py @@ -10,7 +10,7 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel): production_id = fields.Many2one('mrp.production', string='制造订单号') origin = fields.Char(string='源单据') - is_technology_re_adjust = fields.Boolean(default=False) + is_technology_re_adjust = fields.Boolean(default=True) def confirm(self): if self.is_technology_re_adjust is True: @@ -24,38 +24,39 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel): for production_item in productions: # 该制造订单的其他同一销售订单的制造订单的工艺设计处理 if production_item != self.production_id: - for td_other in production_item.technology_design_ids: - if td_other.is_auto is False: - td_del = technology_designs.filtered(lambda tdo: tdo.route_id.id == td_other.route_id.id) - if not td_del or td_del.active is False: - td_other.write({'active': False}) - for td_main in technology_designs: - route_other = production_item.technology_design_ids.filtered( - lambda td: td.route_id.id == td_main.route_id.id) - if not route_other and td_main.active is True: - production_item.write({'technology_design_ids': [(0, 0, { - 'route_id': td_main.route_id.id, - 'process_parameters_id': False if td_main.process_parameters_id is False else - self.env[ - 'sf.production.process.parameter'].search( - [('id', '=', td_main.process_parameters_id.id)]).id, - 'sequence': td_main.sequence, - 'is_auto': td_main.is_auto})]}) - else: - for ro in route_other: - domain = [('production_id', '=', self.production_id.id), - ('active', 'in', [True, False]), - ('route_id', '=', ro.route_id.id)] - if ro.route_id.routing_type == '表面工艺': - domain += [('process_parameters_id', '=', ro.process_parameters_id.id)] - elif ro.route_id.routing_tag == 'special' and ro.is_auto is False: - # display_name = ro.route_id.display_name - domain += [('id', '=', ro.id)] - elif ro.panel is not False: - domain += [('panel', '=', ro.panel)] - td_upd = self.env['sf.technology.design'].sudo().search(domain) - if td_upd: - ro.write({'sequence': td_upd.sequence, 'active': td_upd.active}) + self.env['sf.technology.design'].sudo().unified_procedure_multiple_work_orders(technology_designs, production_item) + # for td_other in production_item.technology_design_ids: + # # if td_other.is_auto is False: + # # td_del = technology_designs.filtered(lambda tdo: tdo.route_id.id == td_other.route_id.id) + # # if not td_del or td_del.active is False: + # # td_other.write({'active': False}) + # for td_main in technology_designs: + # route_other = production_item.technology_design_ids.filtered( + # lambda td: td.route_id.id == td_main.route_id.id) + # if not route_other and td_main.active is True: + # production_item.write({'technology_design_ids': [(0, 0, { + # 'route_id': td_main.route_id.id, + # 'process_parameters_id': False if td_main.process_parameters_id is False else + # self.env[ + # 'sf.production.process.parameter'].search( + # [('id', '=', td_main.process_parameters_id.id)]).id, + # 'sequence': td_main.sequence, + # 'is_auto': td_main.is_auto})]}) + # else: + # for ro in route_other: + # domain = [('production_id', '=', self.production_id.id), + # ('active', 'in', [True, False]), + # ('route_id', '=', ro.route_id.id)] + # if ro.route_id.routing_type == '表面工艺': + # domain += [('process_parameters_id', '=', ro.process_parameters_id.id)] + # elif ro.route_id.routing_tag == 'special' and ro.is_auto is False: + # # display_name = ro.route_id.display_name + # domain += [('id', '=', ro.id)] + # elif ro.panel is not False: + # domain += [('panel', '=', ro.panel)] + # td_upd = self.env['sf.technology.design'].sudo().search(domain) + # if td_upd: + # ro.write({'sequence': td_upd.sequence, 'active': td_upd.active}) special_design = self.env['sf.technology.design'].sudo().search( [('routing_tag', '=', 'special'), ('production_id', '=', production_item.id), ('is_auto', '=', False), ('active', 'in', [True, False])]) @@ -124,3 +125,4 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel): if workorders[ 0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程': workorders[0].state = 'waiting' + diff --git a/sf_manufacturing/wizard/production_technology_wizard.py b/sf_manufacturing/wizard/production_technology_wizard.py index 6e91e053..e16e853c 100644 --- a/sf_manufacturing/wizard/production_technology_wizard.py +++ b/sf_manufacturing/wizard/production_technology_wizard.py @@ -11,7 +11,7 @@ class ProductionTechnologyWizard(models.TransientModel): production_id = fields.Many2one('mrp.production', string='制造订单号') origin = fields.Char(string='源单据') - is_technology_confirm = fields.Boolean(default=False) + is_technology_confirm = fields.Boolean(default=True) def confirm(self): if self.is_technology_confirm is True and self.production_id.product_id.categ_id.type in ['成品', '坯料']: @@ -19,40 +19,44 @@ class ProductionTechnologyWizard(models.TransientModel): ('product_id', '=', self.production_id.product_id.id)] else: domain = [('id', '=', self.production_id.id)] - technology_designs = self.production_id.technology_design_ids + technology_designs = self.env['sf.technology.design'].sudo().search( + [('production_id', '=', self.production_id.id), ('active', 'in', [True, False])]) + # technology_designs = self.production_id.technology_design_ids productions = self.env['mrp.production'].search(domain) for production in productions: if production != self.production_id: - for td_other in production.technology_design_ids: - if td_other.is_auto is False: - td_del = technology_designs.filtered(lambda tdo: tdo.route_id.id == td_other.route_id.id) - if not td_del or td_del.active is False: - td_other.write({'active': False}) - for td_main in technology_designs: - route_other = production.technology_design_ids.filtered( - lambda td: td.route_id.id == td_main.route_id.id) - if not route_other and td_main.active is True: - production.write({'technology_design_ids': [(0, 0, { - 'route_id': td_main.route_id.id, - 'process_parameters_id': False if td_main.process_parameters_id is False else self.env[ - 'sf.production.process.parameter'].search( - [('id', '=', td_main.process_parameters_id.id)]).id, - 'sequence': td_main.sequence})]}) - else: - for ro in route_other: - domain = [('production_id', '=', self.production_id.id), - ('active', 'in', [True, False]), - ('route_id', '=', ro.route_id.id)] - if ro.route_id.routing_type == '表面工艺': - domain += [('process_parameters_id', '=', ro.process_parameters_id.id)] - elif ro.route_id.routing_tag == 'special' and ro.is_auto is False: - # display_name = ro.route_id.display_name - domain += [('id', '=', ro.id)] - elif ro.panel is not False: - domain += [('panel', '=', ro.panel)] - td_upd = self.env['sf.technology.design'].sudo().search(domain) - if td_upd: - ro.write({'sequence': td_upd.sequence, 'active': td_upd.active}) + self.env['sf.technology.design'].sudo().unified_procedure_multiple_work_orders(technology_designs, + production) + # for td_other in production.technology_design_ids: + # if td_other.is_auto is False: + # td_del = technology_designs.filtered(lambda tdo: tdo.route_id.id == td_other.route_id.id) + # if not td_del or td_del.active is False: + # td_other.write({'active': False}) + # for td_main in technology_designs: + # route_other = production.technology_design_ids.filtered( + # lambda td: td.route_id.id == td_main.route_id.id) + # if not route_other and td_main.active is True: + # production.write({'technology_design_ids': [(0, 0, { + # 'route_id': td_main.route_id.id, + # 'process_parameters_id': False if td_main.process_parameters_id is False else self.env[ + # 'sf.production.process.parameter'].search( + # [('id', '=', td_main.process_parameters_id.id)]).id, + # 'sequence': td_main.sequence})]}) + # else: + # for ro in route_other: + # domain = [('production_id', '=', self.production_id.id), + # ('active', 'in', [True, False]), + # ('route_id', '=', ro.route_id.id)] + # if ro.route_id.routing_type == '表面工艺': + # domain += [('process_parameters_id', '=', ro.process_parameters_id.id)] + # elif ro.route_id.routing_tag == 'special' and ro.is_auto is False: + # # display_name = ro.route_id.display_name + # domain += [('id', '=', ro.id)] + # elif ro.panel is not False: + # domain += [('panel', '=', ro.panel)] + # td_upd = self.env['sf.technology.design'].sudo().search(domain) + # if td_upd: + # ro.write({'sequence': td_upd.sequence, 'active': td_upd.active}) special_design = self.env['sf.technology.design'].sudo().search( [('routing_tag', '=', 'special'), ('production_id', '=', production.id), ('is_auto', '=', False), ('active', 'in', [True, False])])