diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 6c7bd9d6..9e8720ca 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -6,6 +6,8 @@ import os import re import requests from itertools import groupby +from datetime import datetime +from collections import defaultdict, namedtuple from odoo import api, fields, models, SUPERUSER_ID, _ from odoo.exceptions import UserError, ValidationError from odoo.addons.sf_base.commons.common import Common @@ -123,6 +125,7 @@ class MrpProduction(models.Model): manual_quotation = fields.Boolean('人工编程', default=False, readonly=True) is_scrap = fields.Boolean('是否报废', default=False) + is_remanufacture = fields.Boolean('是否重新制造', default=False) @api.depends( 'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state', 'tool_state', @@ -934,7 +937,8 @@ class MrpProduction(models.Model): logging.info('get_new_program error:%s' % e) raise UserError("从云平台获取最新程序失败,请联系管理员") - def recreateManufacturing(self, item, procurement, rule): + + def recreateManufacturing(self, item): """ 重新生成制造订单 """ @@ -942,56 +946,65 @@ class MrpProduction(models.Model): procurement_requests = [] sale_order = self.env['sale.order'].sudo().search([('name', '=', self.origin)]) values = self.env['mrp.production'].create_production1_values(self) - productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company( - self.company_id).create( - values) + # productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company( + # self.company_id).create( + # values) # 查询出库移动记录 out_picking = self.env['stock.picking'].search( - [('logistics_way', '!=', False), ('origin', '=', sale_order.name), ('name', 'ilike', 'WH/OUT/')]) - for move in out_picking.move_ids: - values = move._prepare_procurement_values() - origin = move._prepare_procurement_origin() - procurement_requests.append(self.env['procurement.group'].Procurement( - move.product_id, move.product_uom_qty, move.product_uom, - move.location_id, move.rule_id and move.rule_id.name or "/", - origin, move.company_id, values)) + [('origin', '=', sale_order.name), ('name', 'ilike', 'WH/OUT/')]) + move = out_picking.move_ids.filtered(lambda pd: pd.product_id == self.product_id) + 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, + '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 "/", + origin, move.company_id, move_values)) self.env['procurement.group'].run(procurement_requests, raise_user_error=not self.env.context.get('from_orderpoint')) - for procurement, rule in procurements: - if not rule.location_src_id: - msg = _('No source location defined on stock rule: %s!') % (rule.name,) - raise ProcurementException([(procurement, msg)]) - - if rule.procure_method == 'mts_else_mto': - mtso_products_by_locations[rule.location_src_id].append(procurement.product_id.id) - # out_picking.move_ids._action_confirm() - # self.env['stock.move'].search([('')]) - # for - move_values = rule._get_stock_move_values(*procurement) - move_values['procure_method'] = 'make_to_order' - moves_values_by_company[procurement.company_id.id].append(move_values) - # moves_values = [{'name': ,''}] - for company_id, moves_values in moves_values_by_company.items(): - 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() - # moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(moves_values) - # self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) - 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.programming_no = self.programming_no + # 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') + for mo in move: + print(mo.id) + if mo.name in ['/', '拉']: + if mo.name == '/': + domain = [('barcode', '=', 'WH-PC'), ('sequence_code', '=', 'PC')] + elif mo.name == '拉': + domain = [('barcode', '=', 'WH-INTERNAL'), ('sequence_code', '=', 'INT')] + picking_type = self.env['stock.picking.type'].search(domain) + mo.picking_type_id = picking_type.id + mo._assign_picking() + mo.reference = mo.picking_id.name + 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)])}) scarp_process_parameter_workorder = self.env['mrp.workorder'].search( [('surface_technics_parameters_id', '!=', False), ('production_id', '=', self.id), ('is_subcontract', '=', True)]) if scarp_process_parameter_workorder: production_programming = self.env['mrp.production'].search( - [('programming_no', '=', self.production_id.programming_no)], order='name asc') + [('programming_no', '=', self.programming_no)], order='name asc') production_list = [production.name for production in production_programming] purchase_orders = self.env['purchase.order'].search([('origin', '=', ','.join(production_list))]) for purchase_item in purchase_orders.order_line: @@ -1054,7 +1067,6 @@ class MrpProduction(models.Model): production_item) else: productions.programming_state = '编程中' - for production in productions: origin_production = production.move_dest_ids and production.move_dest_ids[ 0].raw_material_production_id or False diff --git a/sf_manufacturing/wizard/production_wizard.py b/sf_manufacturing/wizard/production_wizard.py index 695a48c9..638d6ac7 100644 --- a/sf_manufacturing/wizard/production_wizard.py +++ b/sf_manufacturing/wizard/production_wizard.py @@ -72,54 +72,7 @@ class ProductionWizard(models.TransientModel): } ret['programming_list'].append(vals) - actions_to_run = defaultdict(list) - list2 = [] - Procurement = namedtuple('Procurement', ['product_id', 'product_qty', - 'product_uom', 'location_id', 'name', 'origin', - 'company_id', - 'values']) - s = Procurement(product_id=self.production_id.product_id, product_qty=1.0, - product_uom=self.production_id.product_uom_id, - location_id=self.env['stock.location'].search([('usage', '=', 'customer')]), - name=self.production_id.product_id.display_name, - origin=self.production_id.origin, - company_id=self.production_id.company_id, - values={ - 'group_id': self.production_id.procurement_group_id, - 'sale_line_id': False, - 'date_planned': fields.Date.today(), - 'date_deadline': fields.Date.today(), - # 'route_ids': stock.route(), - 'warehouse_id': self.production_id.warehouse_id, - # 'partner_id': self.production_id.partner_id, - 'product_description_variants': '', - 'company_id': self.production_id.company_id, - # 'product_packaging_id': product.packaging(), - 'sequence': 10, - 'priority': '0' - }, - ) - rule = self.env['procurement.group']._get_rule(s.product_id, s.location_id,s.values) - list2.append(s) - # for procurement in list2: - # rule = self.env['procurement.group']._get_rule(procurement.product_id, procurement.location_id, - # procurement.values) - # action = 'pull' - # actions_to_run[action].append((procurement, rule)) - # # list2.append(tuple(s)) - # # list2.append(self.production_id.product_id.route_ids[1]) - # for action, procurements in actions_to_run.items(): - # bb = action - # aa = procurements - # if hasattr(self.env['stock.rule'], '_run_%s' % action): - # try: - # getattr(self.env['stock.rule'], '_run_%s' % action)(procurements) - # except ProcurementException as e: - # procurement_errors += e.procurement_exceptions - # else: - # _logger.error("The method _run_%s doesn't exist on the procurement rules" % action) - # self.env['stock.rule']._run_pull(actions_to_run) - new_production = self.production_id.recreateManufacturing(ret, s, rule) + new_production = self.production_id.recreateManufacturing(ret) if self.is_reprogramming is False: for panel in new_production.product_id.model_processing_panel.split(','): scrap_cnc_workorder = max(