From 82dcfb50189f633d65db84eb4497334900672b31 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Thu, 20 Apr 2023 19:39:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=8A=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E8=A1=A8=E9=9D=A2=E5=B7=A5=E8=89=BA=E5=A4=96=E5=8D=8F=E5=87=BA?= =?UTF-8?q?=E5=85=A5=E5=BA=93=E5=8D=95=EF=BC=8C=E2=80=98=E8=83=9A=E6=96=99?= =?UTF-8?q?=E2=80=99=E4=BF=AE=E6=94=B9=E4=B8=BA=E2=80=98=E5=9D=AF=E6=96=99?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/models/common.py | 2 +- sf_bf_connect/controllers/controllers.py | 14 +- sf_bf_connect/models/process_status.py | 37 ----- sf_dlm/data/product_data.xml | 10 +- sf_dlm/models/product_template.py | 22 +-- sf_dlm/models/product_workorder.py | 6 +- sf_dlm/views/product_template_view.xml | 4 +- sf_manufacturing/models/model_type.py | 8 +- sf_manufacturing/models/mrp_production.py | 112 +++++++++---- .../models/mrp_routing_workcenter.py | 2 +- sf_manufacturing/models/mrp_workorder.py | 5 +- sf_manufacturing/models/stock.py | 148 +++--------------- sf_manufacturing/views/model_type_view.xml | 2 +- 13 files changed, 142 insertions(+), 230 deletions(-) diff --git a/sf_base/models/common.py b/sf_base/models/common.py index e6efad84..23933054 100644 --- a/sf_base/models/common.py +++ b/sf_base/models/common.py @@ -120,7 +120,7 @@ class MrsProductionProcessParameter(models.Model): code = fields.Char("编码") name = fields.Char('名称') gain_way = fields.Selection([("自加工", "自加工"), ("外协", "外协")], default="", string="获取方式") - is_check = fields.Boolean(default=True) + is_check = fields.Boolean(default=False) # price = fields.Float('单价') process_id = fields.Many2one('sf.production.process', string='表面工艺') materials_model_ids = fields.Many2many('sf.materials.model', 'applicable_material', string='适用材料') diff --git a/sf_bf_connect/controllers/controllers.py b/sf_bf_connect/controllers/controllers.py index 471fc152..3a48d16f 100644 --- a/sf_bf_connect/controllers/controllers.py +++ b/sf_bf_connect/controllers/controllers.py @@ -11,7 +11,7 @@ class Sf_Bf_Connect(http.Controller): cors="*") def get_bfm_process_order_list(self, **kw): """ - 接收业务平台加工订单分配工厂时传送来的订单数据并生成销售订单和产品及胚料 + 接收业务平台加工订单分配工厂时传送来的订单数据并生成销售订单和产品及坯料 :param kw: :return: """ @@ -52,16 +52,16 @@ class Sf_Bf_Connect(http.Controller): bom.with_user(request.env.ref("base.user_admin")).bom_create_line_has(bom_data) else: if product.materials_type_id.gain_way == '自加工': - # 创建胚料 + # 创建坯料 self_machining_embryo = request.env['product.template'].sudo().no_bom_product_create( self_machining_id, item, order_id, 'self_machining', i) - # 创建胚料的bom + # 创建坯料的bom self_machining_bom = request.env['mrp.bom'].with_user( request.env.ref("base.user_admin")).bom_create( self_machining_embryo, 'normal', False) - # 创建胚料里bom的组件 + # 创建坯料里bom的组件 self_machining_bom_line = self_machining_bom.with_user( request.env.ref("base.user_admin")).bom_create_line( self_machining_embryo) @@ -77,17 +77,17 @@ class Sf_Bf_Connect(http.Controller): product_bom_self_machining.with_user(request.env.ref("base.user_admin")).bom_create_line_has( self_machining_embryo) elif product.materials_type_id.gain_way == '外协': - # 创建胚料 + # 创建坯料 outsource_embryo = request.env['product.template'].sudo().no_bom_product_create(outsource_id, item, order_id, 'subcontract', i) - # 创建胚料的bom + # 创建坯料的bom outsource_bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create( outsource_embryo, 'subcontract', True) - # 创建胚料的bom的组件 + # 创建坯料的bom的组件 outsource_bom_line = outsource_bom.with_user( request.env.ref("base.user_admin")).bom_create_line(outsource_embryo) if outsource_bom_line == False: diff --git a/sf_bf_connect/models/process_status.py b/sf_bf_connect/models/process_status.py index 8404e9ce..2a4aa0e3 100644 --- a/sf_bf_connect/models/process_status.py +++ b/sf_bf_connect/models/process_status.py @@ -35,44 +35,7 @@ class StatusChange(models.Model): context = self._context.copy() context.pop('default_name', None) logging.info('函数已经执行=============4') - self.with_context(context)._action_confirm() - self.env.cr.commit() - print(self.mrp_production_ids) - # 判断外协工序是否连续有多个外协工序为同一个供应商(产品为表面工艺服务的供应商), - # 如果有的话,则将连续的多个外协工序(ID),绑定同一张外协出入库单,单独的供应商工序则生成单独的外协出入库单 - # 如果没有连续的外协工序为同一个供应商,则根据规则生成多张外协出入库单,并绑定不同的工序ID - - #以下代码可转移至生成工单的该行代码production.workorder_ids = workorders_values前后左右 - for item in self.mrp_production_ids: - process_parameter_workorder = self.env['mrp.workorder'].search( - [('surface_technics_parameters_id', '!=', False), ('production_id', '=', 83)]) - if process_parameter_workorder: - consecutive_workorders = [] - m =0 - sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.id) - for i in range(len(sorted_workorders) - 1): - if sorted_workorders[i].supplier_id == sorted_workorders[i + 1].supplier_id and \ - sorted_workorders[i].id == sorted_workorders[i + 1].id - 1: - consecutive_workorders.append(sorted_workorders[i]) - consecutive_workorders.append(sorted_workorders[i + 1]) - m+1 - else: - - if m != len(sorted_workorders): - if consecutive_workorders: - self.env['stock.move'].create_outcontract_stock_move(consecutive_workorders,item) - # 当前面的连续工序生成对应的外协出入库单再生成当前工序的外协出入库单,并将前面的consecutive_workorders和m置为初始值 - consecutive_workorders = [] - m =0 - self.env['stock.move'].create_outcontract_stock_move(consecutive_workorders, item) - if m == len(sorted_workorders): - self.env['stock.move'].create_outcontract_stock_move(consecutive_workorders, item) - - - - - if self.env.user.has_group('sale.group_auto_done_setting'): logging.info('函数已经执行=============5') self.action_done() diff --git a/sf_dlm/data/product_data.xml b/sf_dlm/data/product_data.xml index 04e16c70..54a468ad 100644 --- a/sf_dlm/data/product_data.xml +++ b/sf_dlm/data/product_data.xml @@ -2,8 +2,8 @@ - 胚料 - 胚料 + 坯料 + 坯料 成品 @@ -37,7 +37,7 @@ false - 胚料自加工模板 + 坯料自加工模板 - 胚料外协加工模板 + 坯料外协加工模板 false - 胚料采购模板 + 坯料采购模板 ', product.length), ('width', '>', product.width), ('height', '>', product.height), ('is_bfm', '=', False) ], @@ -343,7 +343,7 @@ class ResProductCategory(models.Model): _inherit = "product.category" type = fields.Selection( - [("成品", "成品"), ("胚料", "胚料"), ("原材料", "原材料"), ("表面工艺", "表面工艺"), ("服务", "服务")], + [("成品", "成品"), ("坯料", "坯料"), ("原材料", "原材料"), ("表面工艺", "表面工艺")], default="", string="类型") # @api.constrains('type') diff --git a/sf_dlm/models/product_workorder.py b/sf_dlm/models/product_workorder.py index 2f825d4e..bcdc5d86 100644 --- a/sf_dlm/models/product_workorder.py +++ b/sf_dlm/models/product_workorder.py @@ -5,8 +5,8 @@ class ResMrpWorkOrder(models.Model): _inherit = 'mrp.workorder' _order = 'sequence' - product_tmpl_id_length = fields.Float(related='production_id.product_tmpl_id.length', readonly=True, store=True, check_company=True, string="胚料长度(mm)") - product_tmpl_id_width = fields.Float(related='production_id.product_tmpl_id.width', readonly=True, store=True, check_company=True, string="胚料宽度(mm)") - product_tmpl_id_height = fields.Float(related='production_id.product_tmpl_id.height', readonly=True, store=True, check_company=True, string="胚料高度(mm)") + product_tmpl_id_length = fields.Float(related='production_id.product_tmpl_id.length', readonly=True, store=True, check_company=True, string="坯料长度(mm)") + product_tmpl_id_width = fields.Float(related='production_id.product_tmpl_id.width', readonly=True, store=True, check_company=True, string="坯料宽度(mm)") + product_tmpl_id_height = fields.Float(related='production_id.product_tmpl_id.height', readonly=True, store=True, check_company=True, string="坯料高度(mm)") product_tmpl_id_materials_id = fields.Many2one(related='production_id.product_tmpl_id.materials_id', readonly=True, store=True, check_company=True, string="材料") product_tmpl_id_materials_type_id = fields.Many2one(related='production_id.product_tmpl_id.materials_type_id', readonly=True, store=True, check_company=True, string="型号") diff --git a/sf_dlm/views/product_template_view.xml b/sf_dlm/views/product_template_view.xml index c071f40b..efcab98d 100644 --- a/sf_dlm/views/product_template_view.xml +++ b/sf_dlm/views/product_template_view.xml @@ -21,7 +21,7 @@ + attrs="{'invisible': ['|',('categ_type', '!=', '坯料'),('categ_type', '=', False)]}"/> - + diff --git a/sf_manufacturing/models/model_type.py b/sf_manufacturing/models/model_type.py index c37711ed..14315148 100644 --- a/sf_manufacturing/models/model_type.py +++ b/sf_manufacturing/models/model_type.py @@ -6,11 +6,11 @@ class ModelType(models.Model): _description = '模型类型' name = fields.Char('名称') - embryo_tolerance = fields.Integer('胚料容余') + embryo_tolerance = fields.Integer('坯料容余') product_routing_tmpl_ids = fields.One2many('sf.product.model.type.routing.sort', 'product_model_type_id', '成品工序模板') embryo_routing_tmpl_ids = fields.One2many('sf.embryo.model.type.routing.sort', 'embryo_model_type_id', - '胚料工序模板') + '坯料工序模板') surface_technics_routing_tmpl_ids = fields.One2many('sf.surface_technics.model.type.routing.sort', 'surface_technics_model_type_id', '表面工艺工序模板') @@ -41,7 +41,7 @@ class ProductModelTypeRoutingSort(models.Model): class EmbryoModelTypeRoutingSort(models.Model): _name = 'sf.embryo.model.type.routing.sort' - _description = '胚料工序排序' + _description = '坯料工序排序' sequence = fields.Integer('Sequence') route_workcenter_id = fields.Many2one('mrp.routing.workcenter') @@ -58,7 +58,7 @@ class EmbryoModelTypeRoutingSort(models.Model): embryo_model_type_id = fields.Many2one('sf.model.type') _sql_constraints = [ - ('route_model_type_uniq', 'unique (route_workcenter_id,embryo_model_type_id)', '胚料工序不能重复!') + ('route_model_type_uniq', 'unique (route_workcenter_id,embryo_model_type_id)', '坯料工序不能重复!') ] diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index b090c130..ad4dab6b 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -138,31 +138,35 @@ class MrpProduction(models.Model): surface_technics_arr.append(item.route_workcenter_id.surface_technics_id.id) route_workcenter_arr.append(item.route_workcenter_id.id) if surface_technics_arr: - production_process = self.env['sf.production.process.category'].search( + production_process_category = self.env['sf.production.process.category'].search( [('production_process_ids.id', 'in', surface_technics_arr)], order='sequence asc' ) - if production_process: - for p in production_process: - for pitem in p.production_process_ids: - if pitem.id in surface_technics_arr: - for param in production.product_id.model_process_parameters_ids: - process_parameter = self.env['sf.production.process.parameter'].search( - [('process_id.id', '=', pitem.id), ('id', '=', param.id)]) - # 产品为表面工艺服务的供应商 - product_production_process = self.env['product.template'].search( - [('server_product_process_parameters_id', '=', process_parameter.id)]) - if process_parameter: - for ritem in route_workcenter_arr: - route_production_process = self.env['mrp.routing.workcenter'].search( - [('surface_technics_id', '=', pitem.id), ('id', '=', ritem)]) - if route_production_process: - workorders_values.append( - self.env['mrp.workorder']._json_workorder_surface_process_str( - production, route_production_process, - process_parameter, - product_production_process.seller_ids[0].id)) - elif production.product_id.categ_id.type == '胚料': + #用filter刷选表面工艺id'是否存在工艺类别对象里 + if production_process_category: + for p in production_process_category: + production_process = p.production_process_ids.filtered( + lambda pp: pp.id in surface_technics_arr) + if production_process: + process_parameter = production.product_id.model_process_parameters_ids.filtered( + lambda pm: pm.process_id.id == production_process.id) + if process_parameter: + # 产品为表面工艺服务的供应商 + product_production_process = self.env['product.template'].search( + [('server_product_process_parameters_id', '=', process_parameter.id)]) + if product_production_process: + route_production_process = self.env[ + 'mrp.routing.workcenter'].search( + [('surface_technics_id', '=', production_process.id), + ('id', 'in', route_workcenter_arr)]) + if route_production_process: + workorders_values.append( + self.env[ + 'mrp.workorder']._json_workorder_surface_process_str( + production, route_production_process, + process_parameter, + product_production_process.seller_ids[0].partner_id.id)) + elif production.product_id.categ_id.type == '坯料': embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search( [('embryo_model_type_id', '=', production.product_id.embryo_model_type_id.id)], order='sequence asc' @@ -171,23 +175,49 @@ class MrpProduction(models.Model): workorders_values.append( self.env['mrp.workorder'].json_workorder_str('', production, route)) production.workorder_ids = workorders_values - aa = self.env['mrp.workorder'].get_no_data(production.id) - if aa: - consecutive_workorders = [] - m =0 - sorted_workorders = sorted(aa, key=lambda w: w.id) - for i in range(len(sorted_workorders) - 1): - if sorted_workorders[i].supplier_id == sorted_workorders[i + 1].supplier_id and \ - sorted_workorders[i].id == sorted_workorders[i + 1].id - 1: - consecutive_workorders.append(sorted_workorders[i]) - consecutive_workorders.append(sorted_workorders[i + 1]) - m+1 process_parameter_workorder = self.env['mrp.workorder'].search( [('surface_technics_parameters_id', '!=', False), ('production_id', '=', production.id)]) + if process_parameter_workorder: + is_pick = False + consecutive_workorders = [] + m = 0 + sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.id) + for i in range(len(sorted_workorders) - 1): + if m == 0: + is_pick = False + # if sorted_workorders[i].id in consecutive_workorders: + # consecutive_workorders = [x for x in consecutive_workorders if x not in sorted_workorders[i].id] + # continue + if sorted_workorders[i].supplier_id == sorted_workorders[i + 1].supplier_id and \ + sorted_workorders[i].id == sorted_workorders[i + 1].id - 1: + if sorted_workorders[i] not in consecutive_workorders: + consecutive_workorders.append(sorted_workorders[i]) + consecutive_workorders.append(sorted_workorders[i + 1]) + m += 1 + continue + else: + if m == len(consecutive_workorders)-1 and m != 0: + self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production) + if sorted_workorders[i] in consecutive_workorders: + is_pick = True + consecutive_workorders = [] + m = 0 + # 当前面的连续工序生成对应的外协出入库单再生成当前工序的外协出入库单 + if is_pick is False: + self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production) + if m == len(consecutive_workorders)-1 and m != 0: + self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production) + if sorted_workorders[i] in consecutive_workorders: + is_pick = True + consecutive_workorders = [] + m = 0 + if m == len(consecutive_workorders) - 1 and m != 0: + self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production) + if is_pick is False: + self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production) for workorder in production.workorder_ids: workorder.duration_expected = workorder._get_duration_expected() - # 在之前的销售单上重新生成制造订单 def create_production1_values(self, production): production_values_str = {'origin': production.origin, @@ -210,6 +240,20 @@ class MrpProduction(models.Model): 'user_id': production.user_id.id} return production_values_str + def _get_stock_move_values_Res(self,item,location_src_id,location_dest_id): + move_values = { + 'name': item.name if item.name else '/', + 'company_id': item.company_id.id, + 'product_id': item.bom_id.bom_line_ids.product_id.id, + 'product_uom': item.bom_id.bom_line_ids.product_uom_id.id, + 'product_uom_qty': 1.0, + 'location_id': location_src_id, + 'location_dest_id': location_dest_id, + 'origin': item.origin, + 'picking_type_id': self.picking_type_id.id, + } + return move_values + # 工单排序 def _reset_work_order_sequence1(self, k): sequen = 0 diff --git a/sf_manufacturing/models/mrp_routing_workcenter.py b/sf_manufacturing/models/mrp_routing_workcenter.py index 1ab52f61..27324e40 100644 --- a/sf_manufacturing/models/mrp_routing_workcenter.py +++ b/sf_manufacturing/models/mrp_routing_workcenter.py @@ -28,7 +28,7 @@ class ResMrpRoutingWorkcenter(models.Model): company_id = fields.Many2one('res.company', compute="get_company_id", related=False) - # 排产的时候, 根据胚料的长宽高比对一下机床的最大加工尺寸.不符合就不要分配给这个加工中心(机床). + # 排产的时候, 根据坯料的长宽高比对一下机床的最大加工尺寸.不符合就不要分配给这个加工中心(机床). # 工单对应的工作中心,根据工序中的工作中心去匹配, # 如果只配置了一个工作中心,则默认采用该工作中心; # 如果有多个工作中心, diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 06b7911c..389fd9a7 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -54,7 +54,7 @@ class ResMrpWorkOrder(models.Model): programming_state = fields.Char('编程状态') cnc_worksheet = fields.Binary( '工作指令', readonly=True) - material_center_point = fields.Char(string='胚料中心点') + material_center_point = fields.Char(string='坯料中心点') X1_axis = fields.Float(default=0) Y1_axis = fields.Float(default=0) Z1_axis = fields.Float(default=0) @@ -93,7 +93,8 @@ class ResMrpWorkOrder(models.Model): glb_file = fields.Binary("glb模型文件") is_subcontract = fields.Boolean(string='是否外协') surface_technics_parameters_id = fields.Many2one('sf.production.process.parameter', string="表面工艺可选参数") - picking_id = fields.Many2one('stock.picking', string='外协出入库单') + picking_in_id = fields.Many2one('stock.picking', string='外协入库单') + picking_out_id = fields.Many2one('stock.picking', string='外协出库单') supplier_id = fields.Integer('供应商Id') def get_no_data(self, production_id): diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 6525983b..e7772fe3 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -12,13 +12,6 @@ from odoo.exceptions import UserError class StockRule(models.Model): _inherit = 'stock.rule' - # @api.model - # def _run_pull(self, procurements): - # res = super(StockRule, self)._run_pull(procurements) - # # process_parameter_workorder = self.env['mrp.workorder'].search( - # # [('surface_technics_parameters_id', '!=', False), ('production_id', '=', self.production_id)]) - # stock_move = self.env['stock.move'].search([('raw_material_production_id', '=', self.id)]) - @api.model def _run_pull(self, procurements): moves_values_by_company = defaultdict(list) @@ -190,54 +183,6 @@ class StockRule(models.Model): subtype_id=self.env.ref('mail.mt_note').id) return True - def create_outcontract_stock_move(self, sorted_workorders, item): - outcontract_stock_move = self.env['stock.move'].search( - [('workorder_id', '=', sorted_workorders.id), ('production_id', '=', item.id)]) - if not outcontract_stock_move: - location_id = self.env.ref( - 'sf_manufacturing.stock_location_locations_virtual_outcontract').id, - location_dest_id = self.env['stock.location'].search( - [('barcode', '=', 'WH-PREPRODUCTION')]).id, - outcontract_picking_in = self.env['stock.rule'].create_outcontract_picking(item, - location_id, - location_dest_id) - outcontract_picking_in.write({'workorder_id': outcontract_picking_in.id}) - outcontract_picking_out = self.env['stock.rule'].create_outcontract_picking(item, - location_dest_id, - location_id) - outcontract_picking_out.write({'workorder_id': outcontract_picking_out.id}) - - # 生成外协出入库单 - def create_outcontract_picking(self, item, location_src_id, location_dest_id): - moves_values_by_company = defaultdict(list) - list2 = [] - Procurement = namedtuple('Procurement', ['product_id', 'product_qty', - 'product_uom', 'location_id', 'location_dest_id', 'name', 'origin', - 'company_id', - 'values']) - s = Procurement(product_id=item.bom_id.product_id, product_qty=1.0, product_uom=item.product_uom, - location_id=location_src_id, - location_dest_id=location_dest_id, - name=item.name, - origin=item.origin, - company_id=item.company_id, - values=item.values, - ) - item1 = list(item) - item1[0] = s - list2.append(tuple(item1)) - for procurement in list2: - move_values = self.env['stock.rule']._get_stock_move_values(*procurement) - moves_values_by_company[procurement.company_id.id].append(move_values) - for company_id, moves_values in moves_values_by_company.items(): - moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( - moves_values) - new_picking = True - picking = self.env['stock.picking'].create(moves._get_new_picking_values()) - moves.write({'picking_id': picking.id}) - moves._assign_picking_post_process(new=new_picking) - return picking - class ProductionLot(models.Model): _inherit = 'stock.lot' @@ -288,72 +233,31 @@ class ProductionLot(models.Model): class ResStockPicking(models.Model): _inherit = 'stock.picking' - workorder_id = fields.One2many('mrp.workorder', 'picking_id') + workorder_in_id = fields.One2many('mrp.workorder', 'picking_in_id') + workorder_out_id = fields.One2many('mrp.workorder', 'picking_out_id') + def create_outcontract_picking(self, sorted_workorders_arr, item): + m = 0 + for sorted_workorders in sorted_workorders_arr: + if m == 0: + outcontract_stock_move = self.env['stock.move'].search( + [('workorder_id', '=', sorted_workorders.id), ('production_id', '=', item.id)]) + if not outcontract_stock_move: + location_id = self.env.ref( + 'sf_manufacturing.stock_location_locations_virtual_outcontract').id, + location_dest_id = self.env['stock.location'].search( + [('barcode', '=', 'WH-PREPRODUCTION')]).id, + moves_in = self.env['stock.move'].sudo().create( + item._get_stock_move_values_Res(item, location_id, location_dest_id)) + moves_out = self.env['stock.move'].sudo().create( + item._get_stock_move_values_Res(item, location_dest_id, location_id)) + new_picking = True + picking_in = self.env['stock.picking'].create(moves_in._get_new_picking_values()) + picking_out = self.env['stock.picking'].create(moves_out._get_new_picking_values()) + moves_in.write({'picking_id': picking_in.id}) + moves_out.write({'picking_id': picking_out.id}) + moves_in._assign_picking_post_process(new=new_picking) + moves_out._assign_picking_post_process(new=new_picking) + m += 1 + sorted_workorders.write({'picking_in_id': picking_in.id, 'picking_out_id': picking_out.id}) -class ResPurchaseOrder(models.Model): - _inherit = 'purchase.order' - - # 外协出库、入库单 - def _prepare_picking_outcontract(self, sequence_code): - # if not self.group_id: - # self.group_id = self.group_id.create({ - # 'name': self.name, - # 'partner_id': self.partner_id.id - # }) - # if not self.partner_id.property_stock_supplier.id: - # raise UserError(_("You must set a Vendor Location for this partner %s", self.partner_id.name)) - - picking_type_id_oc = self.env['stock.picking.type'].search([('sequence_code', '=', sequence_code)]) - return { - 'picking_type_id': picking_type_id_oc.id if picking_type_id_oc else self.picking_type_id.id, - 'partner_id': self.partner_id.id, - 'user_id': False, - 'date': self.date_order, - 'origin': self.name, - 'location_dest_id': self._get_destination_location(), - 'location_id': self.partner_id.property_stock_supplier.id, - 'company_id': self.company_id.id, - } - - def _create_picking_outcontract(self): - StockPicking = self.env['stock.picking'] - for order in self.filtered(lambda po: po.state in ('purchase', 'done')): - if any(product.type in ['product', 'consu'] for product in order.order_line.product_id): - order = order.with_company(order.company_id) - pickings = order.picking_ids.filtered(lambda x: x.state not in ('done', 'cancel')) - if not pickings: - res = order._prepare_picking_outcontract() - picking = StockPicking.with_user(SUPERUSER_ID).create(res) - pickings = picking - else: - picking = pickings[0] - moves = order.order_line._create_stock_moves(picking) - moves = moves.filtered(lambda x: x.state not in ('done', 'cancel'))._action_confirm() - seq = 0 - for move in sorted(moves, key=lambda move: move.date): - seq += 5 - move.sequence = seq - moves._action_assign() - # Get following pickings (created by push rules) to confirm them as well. - forward_pickings = self.env['stock.picking']._get_impacted_pickings(moves) - (pickings | forward_pickings).action_confirm() - picking.message_post_with_view('mail.message_origin_link', - values={'self': picking, 'origin': order}, - subtype_id=self.env.ref('mail.mt_note').id) - return True - - -class ResPurchaseOrderLine(models.Model): - _inherit = 'purchase.order.line' - - def _create_stock_moves(self, picking): - values = [] - for line in self.filtered(lambda l: not l.display_type): - for val in line._prepare_stock_moves(picking): - # val['production_id'] = 10 - val['is_subcontract'] = True - values.append(val) - line.move_dest_ids.created_purchase_line_id = False - - return self.env['stock.move'].create(values) diff --git a/sf_manufacturing/views/model_type_view.xml b/sf_manufacturing/views/model_type_view.xml index e827e1df..7c3f18de 100644 --- a/sf_manufacturing/views/model_type_view.xml +++ b/sf_manufacturing/views/model_type_view.xml @@ -31,7 +31,7 @@
- +