diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 322dff15..e5d82e45 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -131,6 +131,31 @@ class MrpProduction(models.Model): manual_quotation = fields.Boolean('人工编程', default=False, compute=_compute_manual_quotation, store=True) is_scrap = fields.Boolean('是否报废', default=False) is_remanufacture = fields.Boolean('是否重新制造', default=False) + remanufacture_count = fields.Integer("重新制造订单数量", compute='_compute_remanufacture_production_ids') + remanufacture_production_id = fields.Many2one('mrp.production', string='') + + @api.depends('remanufacture_production_id') + def _compute_remanufacture_production_ids(self): + for production in self: + if production.remanufacture_production_id: + remanufacture_production = self.env['mrp.production'].search( + [('id', '=', production.remanufacture_production_id.id)]) + if remanufacture_production: + production.remanufacture_count = len(remanufacture_production) + else: + production.remanufacture_count = 0 + + def action_view_remanufacture_productions(self): + self.ensure_one() + mrp_production = self.env['mrp.production'].search( + [('id', '=', self.remanufacture_production_id.id)]) + action = { + 'res_model': 'mrp.production', + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_id': mrp_production.id, + } + return action @api.depends( 'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state', 'tool_state', @@ -813,8 +838,8 @@ class MrpProduction(models.Model): 'target': 'new', 'context': { 'default_production_id': self.id, - 'default_programming_state': '编程中' if cloud_programming[ - 'programming_state'] != '已下发' else '已下发', + 'default_reprogramming_num': cloud_programming['reprogramming_num'], + 'default_programming_states': cloud_programming['programming_state'], 'default_is_reprogramming': True if cloud_programming['programming_state'] in ['已下发'] else False } } @@ -961,32 +986,19 @@ class MrpProduction(models.Model): move_values = {'product_description_variants': '', 'date_planned': datetime.now(), 'date_deadline': datetime.now(), - # 'move_dest_ids': self.env['stock.move'].search([('id', '=', move.id)]), 'move_dest_ids': move, - 'group_id': False, + 'group_id': move.group_id, 'route_ids': [], 'warehouse_id': self.warehouse_id, 'priority': 0, 'orderpoint_id': False, 'product_packaging_id': False} - rule = self.env['stock.rule'].search( - [('action', '=', 'pull'), ('procure_method', '=', 'mts_else_mto'), ( - 'location_dest_id', '=', self.env['stock.location'].search([('parent_path', '=', '2/5/')]).id), - ('location_src_id', '=', self.env['stock.location'].search( - [('barcode', '=', 'CP')]).id)]) - # origin = move._prepare_procurement_origin() procurement_requests.append(self.env['procurement.group'].Procurement( move.product_id, 1.0, move.product_uom, - self.env['stock.location'].search([('barcode', '=', 'CP')]), - rule and rule.name or "/", + move.location_id, move.rule_id and move.rule_id.name or "/", sale_order.name, move.company_id, move_values)) self.env['procurement.group'].run(procurement_requests, raise_user_error=not self.env.context.get('from_orderpoint')) - # self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) - # productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \ - # ( - # p.move_dest_ids.procure_method != 'make_to_order' and - # not p.move_raw_ids and not p.workorder_ids)).action_confirm() productions = self.env['mrp.production'].sudo().search( [('origin', '=', self.origin)], order='id desc', limit=1) move = self.env['stock.move'].search([('origin', '=', productions.name)], order='id desc') @@ -1014,8 +1026,29 @@ class MrpProduction(models.Model): 'picking_id': sfp_move.picking_id.id, 'picking_type_id': sfp_move.picking_type_id.id, 'production_id': False}) productions.write({'programming_no': self.programming_no, 'is_remanufacture': True}) - productions.procurement_group_id.mrp_production_ids.move_dest_ids.write( - {'group_id': self.env['procurement.group'].search([('name', '=', sale_order.name)])}) + # productions.procurement_group_id.mrp_production_ids.move_dest_ids.write( + # {'group_id': self.env['procurement.group'].search([('name', '=', sale_order.name)])}) + stock_picking = None + pc_picking = self.env['stock.picking'].search( + [('origin', '=', productions.name), ('name', 'ilike', 'WH/PC/')]) + stock_picking = pc_picking + int_picking = self.env['stock.picking'].search( + [('origin', '=', productions.name), ('name', 'ilike', 'WH/INT/')]) + stock_picking |= int_picking + for pick in stock_picking: + if pick.move_ids: + product_type_id = pick.move_ids[0].product_id.categ_id + if product_type_id.name == '坯料': + location_id = self.env['stock.location'].search([('name', '=', '坯料存货区')]) + if not location_id: + logging.info(f'没有搜索到【坯料存货区】: {location_id}') + break + if pick.picking_type_id.name == '内部调拨': + if pick.location_dest_id.product_type != product_type_id: + pick.location_dest_id = location_id.id + elif pick.picking_type_id.name == '生产发料': + if pick.location_id.product_type != product_type_id: + pick.location_id = location_id.id scarp_process_parameter_workorder = self.env['mrp.workorder'].search( [('surface_technics_parameters_id', '!=', False), ('production_id', '=', self.id), ('is_subcontract', '=', True)]) diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index f53d7056..27ce925a 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -169,7 +169,6 @@ class StockRule(models.Model): else: forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id] -= qty_needed procure_method = 'make_to_stock' - move_values = rule._get_stock_move_values(*procurement) move_values['procure_method'] = procure_method moves_values_by_company[procurement.company_id.id].append(move_values) @@ -177,13 +176,10 @@ class StockRule(models.Model): for company_id, moves_values in moves_values_by_company.items(): # create the move as SUPERUSER because the current user may not have the rights to do it (mto product # launched by a sale for example) - logging.info(moves_values) moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( moves_values) - logging.info(moves) # Since action_confirm launch following procurement_group we should activate it. moves._action_confirm() - return True @api.model diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml index 99d27576..6fa14a6f 100644 --- a/sf_manufacturing/views/mrp_production_addional_change.xml +++ b/sf_manufacturing/views/mrp_production_addional_change.xml @@ -127,7 +127,7 @@ confirm="是否确认更新程序" attrs="{'invisible': ['|',('state', '!=', 'rework'),('programming_state', '!=', '已编程未下发')]}"/> + +