From 20d9e469f5699267c760c325078b79c8fb8dd3fc Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Wed, 29 Mar 2023 17:48:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E9=9D=A2=E5=B7=A5=E8=89=BA=E7=B1=BB?= =?UTF-8?q?=E5=88=AB=E6=8B=96=E5=8A=A8=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/models/common.py | 15 +- sf_base/views/common_view.xml | 32 ++++- sf_dlm/views/product_template_view.xml | 6 +- sf_manufacturing/models/mrp_production.py | 4 + sf_manufacturing/models/mrp_workorder.py | 18 +++ sf_manufacturing/models/stock.py | 165 +++++++++++----------- sf_mrs_connect/models/sync_common.py | 6 +- 7 files changed, 147 insertions(+), 99 deletions(-) diff --git a/sf_base/models/common.py b/sf_base/models/common.py index 2a4fce98..02d1237b 100644 --- a/sf_base/models/common.py +++ b/sf_base/models/common.py @@ -45,6 +45,7 @@ class MrsProductionProcessCategory(models.Model): name = fields.Char('名称') code = fields.Char("编码") + sequence = fields.Integer('排序') production_process_ids = fields.One2many('sf.production.process', 'category_id', string="表面工艺") active = fields.Boolean('有效', default=True) @@ -61,9 +62,8 @@ class MrsProductionProcess(models.Model): partner_process_ids = fields.Many2many('res.partner', 'process_ids', '加工工厂') active = fields.Boolean('有效', default=True) parameter_ids = fields.One2many('sf.production.process.parameter', 'process_id', string='可选参数') - gain_way = fields.Selection([("自加工", "自加工"), ("外协", "外协")], default="", string="获取方式") category_id = fields.Many2one('sf.production.process.category') - workcenter_ids = fields.Many2many('mrp.workcenter', 'rel_workcenter_process', required=True) + # workcenter_ids = fields.Many2many('mrp.workcenter', 'rel_workcenter_process', required=True) @@ -112,12 +112,15 @@ class SupplierSort(models.Model): ('supplier_sort_uniq', 'unique (partner_id,materials_model_id)', '排序不能重复!') ] + class MrsProductionProcessParameter(models.Model): _name = 'sf.production.process.parameter' _description = '可选参数' - name = fields.Char('参数名') - active = fields.Boolean('有效', default=True) - price = fields.Float('单价') + + code = fields.Char("编码") + name = fields.Char('名称') + gain_way = fields.Selection([("自加工", "自加工"), ("外协", "外协")], default="", string="获取方式") + # price = fields.Float('单价') process_id = fields.Many2one('sf.production.process', string='表面工艺') materials_model_ids = fields.Many2many('sf.materials.model', 'applicable_material', string='适用材料') - code = fields.Char("编码") \ No newline at end of file + active = fields.Boolean('有效', default=True) \ No newline at end of file diff --git a/sf_base/views/common_view.xml b/sf_base/views/common_view.xml index 89d6df00..82e1e918 100644 --- a/sf_base/views/common_view.xml +++ b/sf_base/views/common_view.xml @@ -49,6 +49,7 @@ + @@ -74,8 +75,9 @@ sf.production.process.category - - + + + @@ -112,22 +114,38 @@ - - - - - + + +
+ + + + + + + + + + + + + + + + + +
diff --git a/sf_dlm/views/product_template_view.xml b/sf_dlm/views/product_template_view.xml index aeb4ee63..75345845 100644 --- a/sf_dlm/views/product_template_view.xml +++ b/sf_dlm/views/product_template_view.xml @@ -26,7 +26,11 @@ + > + + + + diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index a8b8b0eb..b371fd29 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -127,6 +127,10 @@ class MrpProduction(models.Model): if i == processing_panel_len and route.routing_type == '解除装夹': workorders_values.append( self.env['mrp.workorder'].json_workorder_str(k, production, route)) + # 表面工艺 + # for item in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids: + # workorders_values.append( + # self.env['mrp.workorder']._json_workorder_surface_process_str(production, item)) 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)], diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index f858c88d..6b0d5b2a 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -157,6 +157,24 @@ class ResMrpWorkOrder(models.Model): }] return workorders_values_str + # 拼接工单对象属性值(表面工艺) + def _json_workorder_surface_process_str(self, production, route): + workorders_values_str = [0, '', { + 'product_uom_id': production.product_uom_id.id, + 'qty_producing': 0, + 'operation_id': False, + 'name': route.name, + 'processing_panel': '', + 'routing_type': '绑定表面工艺', + 'work_state': '', + 'workcenter_id': '', + 'date_planned_start': False, + 'date_planned_finished': False, + 'duration_expected': 60, + 'duration': 0 + }] + return workorders_values_str + # 维修模块按钮 def button_maintenance_req(self): self.ensure_one() diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index abd7fad8..ef1805eb 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -229,85 +229,86 @@ class ProductionLot(models.Model): return "%s-%03d" % (product.name, 1) -# class ResPurchaseOrder(models.Model): -# _inherit = 'purchase.order' -# -# # def button_approve(self, force=False): -# # result = super().button_approve(force=force) -# # self._create_picking_RES() -# # return result -# -# # @api.depends('order_line.move_ids') -# # def _compute_subcontracting_resupply_picking_count(self): -# # for purchase in self: -# # purchase.subcontracting_resupply_picking_count = len(purchase._get_subcontracting_resupplies_new()) -# # -# # def _get_subcontracting_resupplies_new(self): -# # moves_subcontracted = self.order_line.move_ids.filtered(lambda m: m.is_subcontract) -# # # subcontracted_productions = moves_subcontracted.move_orig_ids.production_id -# # return moves_subcontracted.picking_id -# -# def _prepare_picking_RES(self): -# 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_res = self.env['stock.picking.type'].search( -# [('sequence_code', '=', 'RES'), ('barcode', '=', 'WH-RESUPPLY')]) -# return { -# 'picking_type_id': picking_type_id_res.id if picking_type_id_res 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(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: -# if order.order_line.product_id.categ_type == '胚料': -# res = order._prepare_picking_RES() -# else: -# res = order._prepare_picking() -# 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 -# values.append(val) -# line.move_dest_ids.created_purchase_line_id = False -# -# return self.env['stock.move'].create(values) +class ResPurchaseOrder(models.Model): + _inherit = 'purchase.order' + + # def button_approve(self, force=False): + # result = super().button_approve(force=force) + # self._create_picking_RES() + # return result + + # @api.depends('order_line.move_ids') + # def _compute_subcontracting_resupply_picking_count(self): + # for purchase in self: + # purchase.subcontracting_resupply_picking_count = len(purchase._get_subcontracting_resupplies_new()) + # + # def _get_subcontracting_resupplies_new(self): + # moves_subcontracted = self.order_line.move_ids.filtered(lambda m: m.is_subcontract) + # # subcontracted_productions = moves_subcontracted.move_orig_ids.production_id + # return moves_subcontracted.picking_id + + def _prepare_picking_RES(self): + 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_res = self.env['stock.picking.type'].search( + [('sequence_code', '=', 'RES'), ('barcode', '=', 'WH-RESUPPLY')]) + return { + 'picking_type_id': picking_type_id_res.id if picking_type_id_res 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(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: + if order.order_line.product_id.categ_type == '胚料': + res = order._prepare_picking_RES() + else: + res = order._prepare_picking() + 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_mrs_connect/models/sync_common.py b/sf_mrs_connect/models/sync_common.py index d751a090..5d97dbe6 100644 --- a/sf_mrs_connect/models/sync_common.py +++ b/sf_mrs_connect/models/sync_common.py @@ -1037,13 +1037,13 @@ class sfProductionProcessParameter(models.Model): brand.name = item['name'], brand.code = item['code'], brand.active = item['active'], - brand.price = item['price'], + # brand.price = item['price'], else: self.env['sf.production.process.parameter'].create({ "name": item['name'], "code": item['code'], "active": item['active'], - "price": item['price'], + # "price": item['price'], "process_id": self.env['sf.production.process'].search( [('process_encode', '=', item['process_id_code'])]).id, 'materials_model_ids': self.env['sf.materials.model'].search( @@ -1073,7 +1073,7 @@ class sfProductionProcessParameter(models.Model): self.env['sf.production.process.parameter'].create({ "name": item['name'], "code": item['code'], - "price": item['price'], + # "price": item['price'], "active": item['active'], "process_id": self.env['sf.production.process'].search( [('process_encode', '=', item['process_id_code'])]).id,