diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 65a01e68..f7a8cbd9 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -131,9 +131,9 @@ class StockRule(models.Model): if num > 1: for no in range(1, num + 1): Procurement = namedtuple('Procurement', ['product_id', 'product_qty', - 'product_uom', 'location_id', 'name', 'origin', - 'company_id', - 'values']) + 'product_uom', 'location_id', 'name', 'origin', + 'company_id', + 'values']) s = Procurement(product_id=item[0].product_id, product_qty=1.0, product_uom=item[0].product_uom, location_id=item[0].location_id, name=item[0].name, @@ -324,12 +324,15 @@ class StockRule(models.Model): for k in (production_item.product_id.model_processing_panel.split(',')): if production_item.production_type == '自动化产线加工': product_routing_workcenter = self.env['sf.product.model.type.routing.sort'].search( - [('product_model_type_id', '=', production_item.product_id.product_model_type_id.id)], + [('product_model_type_id', '=', + production_item.product_id.product_model_type_id.id)], order='sequence asc' ) else: - product_routing_workcenter = self.env['sf.manual.product.model.type.routing.sort'].search( - [('manual_product_model_type_id', '=', production_item.product_id.product_model_type_id.id)], + product_routing_workcenter = self.env[ + 'sf.manual.product.model.type.routing.sort'].search( + [('manual_product_model_type_id', '=', + production_item.product_id.product_model_type_id.id)], order='sequence asc' ) for route in product_routing_workcenter: @@ -592,18 +595,18 @@ class StockPicking(models.Model): for move_id in item.move_ids: move_ids.append(move_id.product_id.id) boms = self.env['mrp.bom'].sudo().search([('bom_line_ids.product_id', 'in', move_ids)]) - default_codes = '' if boms: + codes_list = [] for bom in boms: if bom.product_tmpl_id.default_code: - code = bom.product_tmpl_id.default_code.split('-')[-1] - default_code = bom.product_tmpl_id.default_code.split(f'-{code}')[0] - if default_code not in default_codes: - if default_codes == '': - default_codes = default_code - else: - default_codes = default_codes + ',' + default_code - item.retrospect_ref = default_codes + code_list = bom.product_tmpl_id.default_code.split('-') + if len(code_list) >= 4: + code = '-'.join(code_list[:4]) + if code not in codes_list: + codes_list.append(code) + else: + raise ValidationError('坯料成品的内部参考值格式错误') + item.retrospect_ref = ','.join(codes_list) elif item.picking_type_id.sequence_code in ['INT', 'PC']: pass @@ -946,7 +949,7 @@ class ReStockMove(models.Model): move_lines_commands.append((0, 0, move_line_cmd)) qty_by_location[loc.id] += 1 return move_lines_commands - + def _merge_moves_fields(self): """ 合并制造订单的完成move单据 @@ -954,19 +957,20 @@ class ReStockMove(models.Model): res = super(ReStockMove, self)._merge_moves_fields() res = self._single_manufactuing_mo_generate_origin(res) return res - + def _get_new_picking_values(self): res = super(ReStockMove, self)._get_new_picking_values() res = self._single_manufactuing_mo_generate_origin(res) return res - + def _single_manufactuing_mo_generate_origin(self, res): """ 单个制造订单的完成move单据修改来源为该制造订单关联的销售订单下所有成品相同的制造订单 """ if self[0].origin and self.picking_type_id.name in ['生产发料', '内部调拨']: production = self.env['mrp.production'].search([('name', '=', self[0].origin)], limit=1, order='id asc') - productions = self.env['mrp.production'].search([('origin', '=', production.origin), ('product_id', '=', production.product_id.id)]) + productions = self.env['mrp.production'].search( + [('origin', '=', production.origin), ('product_id', '=', production.product_id.id)]) res['origin'] = ','.join(productions.mapped('name')) return res