diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index a3ad4bcd..9c3d5a77 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -796,7 +796,7 @@ class MrpProduction(models.Model): # 返工 def button_scrap_new(self): - cloud_programming = self._cron_get_programming_state() + # cloud_programming = self._cron_get_programming_state() return { 'name': _('报废'), 'type': 'ir.actions.act_window', @@ -805,7 +805,8 @@ class MrpProduction(models.Model): 'target': 'new', 'context': { 'default_production_id': self.id, - 'default_programming_state': cloud_programming['programming_state'] + 'default_is_reprogramming': False, + 'default_programming_state': '已下发' } } @@ -943,8 +944,14 @@ class MrpProduction(models.Model): productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company( self.company_id).create( values) + # moves_values = [{''}] + # 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 scarp_process_parameter_workorder = self.env['mrp.workorder'].search( [('surface_technics_parameters_id', '!=', False), ('production_id', '=', self.id), @@ -1015,10 +1022,6 @@ class MrpProduction(models.Model): else: productions.programming_state = '编程中' - 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() for production in productions: origin_production = production.move_dest_ids and production.move_dest_ids[ 0].raw_material_production_id or False @@ -1065,6 +1068,7 @@ class MrpProduction(models.Model): def create_production1_values(self, production): production_values_str = {'origin': production.origin, 'product_id': production.product_id.id, + 'programming_state': '已编程', 'product_description_variants': production.product_description_variants, 'product_qty': production.product_qty, 'product_uom_id': production.product_uom_id.id, diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index ca080f11..dbfcd023 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -68,6 +68,7 @@ class StockRule(models.Model): @api.model def _run_pull(self, procurements): + logging.info(procurements) moves_values_by_company = defaultdict(list) mtso_products_by_locations = defaultdict(list) @@ -176,6 +177,7 @@ 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) # Since action_confirm launch following procurement_group we should activate it. moves._action_confirm() diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index 5df3ebf2..201ce3e5 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -522,7 +522,7 @@ + readonly="0"> diff --git a/sf_manufacturing/wizard/production_wizard.py b/sf_manufacturing/wizard/production_wizard.py index 35f3fa01..ee4dc658 100644 --- a/sf_manufacturing/wizard/production_wizard.py +++ b/sf_manufacturing/wizard/production_wizard.py @@ -2,6 +2,8 @@ # Part of YiZuo. See LICENSE file for full copyright and licensing details. import logging from odoo.exceptions import UserError, ValidationError +from collections import defaultdict, namedtuple +from odoo.addons.stock.models.stock_rule import ProcurementException from datetime import datetime from odoo import models, api, fields, _ @@ -11,7 +13,7 @@ class ProductionWizard(models.TransientModel): _description = '制造订单向导' production_id = fields.Many2one('mrp.production', string='制造订单号') - is_reprogramming = fields.Boolean(string='申请重新编程', default=True) + is_reprogramming = fields.Boolean(string='申请重新编程', default=False) is_remanufacture = fields.Boolean(string='重新生成制造订单', default=True) programming_state = fields.Selection( [('待编程', '待编程'), ('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发'), @@ -69,7 +71,37 @@ class ProductionWizard(models.TransientModel): '%Y-%m-%d %H:%M:%S') } ret['programming_list'].append(vals) - new_production = self.production_id.recreateManufacturing(ret) + 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.production_id.product_id.route_ids[1], + 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.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.id, + # 'partner_id': self.production_id.partner_id, + 'product_description_variants': '', + 'company_id': self.production_id.company_id.id, + # 'product_packaging_id': product.packaging(), + 'sequence': 10, + 'priority': '0' + }, + ) + list2.append(tuple(s)) + list2.append(self.production_id.product_id.route_ids[1]) + actions_to_run = defaultdict(list2) + self.env['stock.rule']._run_pull(actions_to_run) + # 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(