From 4902fc5d9a777d53a8641511a62d999c566ba78a Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Tue, 31 Dec 2024 10:56:07 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E9=87=87=E8=B4=AD=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E5=85=B3=E8=81=94=E9=94=80=E5=94=AE=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=BB=8E=E9=94=80=E5=94=AE=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=90=AC=E8=BF=81=E5=88=B0=E5=88=B6=E9=80=A0=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AAmany2many?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AD=97=E6=AE=B5=EF=BC=8C=E4=B8=94=E5=AF=B9?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=9A=84=E8=87=AA=E5=8A=A8=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E8=BF=9B=E8=A1=8C=E4=BC=98=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/purchase_order.py | 41 ++++++++++++++++--- .../views/purchase_order_view.xml | 7 ++++ sf_sale/models/sale_order.py | 17 -------- sf_sale/views/purchase_order_view.xml | 5 --- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/sf_manufacturing/models/purchase_order.py b/sf_manufacturing/models/purchase_order.py index fc8a96b1..71e4e045 100644 --- a/sf_manufacturing/models/purchase_order.py +++ b/sf_manufacturing/models/purchase_order.py @@ -10,10 +10,11 @@ from odoo.tools import OrderedSet # _get_surface_technics_purchase_ids class PurchaseOrder(models.Model): _inherit = 'purchase.order' + production_count = fields.Integer( "关联制造订单", compute='_compute_workorder_count', - ) + ) def action_view_production(self): origins = [order.name for order in self.picking_ids] @@ -37,17 +38,17 @@ class PurchaseOrder(models.Model): }) return action - def _compute_workorder_count(self): for purchase in self: origins = [order.name for order in purchase.picking_ids] production_id = self.env['mrp.production'].search([('origin', 'in', origins)]) purchase.production_count = len(production_id) + def button_confirm(self): super().button_confirm() - workorders = self.env['mrp.workorder'].search([('purchase_id', '=', self.id),('state', '!=', 'cancel')]) + workorders = self.env['mrp.workorder'].search([('purchase_id', '=', self.id), ('state', '!=', 'cancel')]) for workorder in workorders: - if workorder.routing_type == '表面工艺' and workorder.is_subcontract is True: + if workorder.routing_type == '表面工艺' and workorder.is_subcontract is True: move_out = workorder.move_subcontract_workorder_ids[1] # move_out = self.env['stock.move'].search( # [('location_id', '=', self.env['stock.location'].search( @@ -61,10 +62,39 @@ class PurchaseOrder(models.Model): if not mo.move_line_ids: self.env['stock.move.line'].create(mo.get_move_line(workorder.production_id, workorder)) return True + + origin_sale_id = fields.Many2one('sale.order', string='销售订单号', store=True, compute='_compute_origin_sale_id') + origin_sale_ids = fields.Many2many('sale.order', string='销售订单号(多个)', store=True, + compute='_compute_origin_sale_id') + + @api.depends('origin') + def _compute_origin_sale_id(self): + for purchase in self: + if not purchase.origin: + continue + elif 'MO' in purchase.origin: + mp_name_list = [name.strip() for name in purchase['origin'].split(',')] + os_ids = list({mp_id.sale_order_id.id for mp_id in self.env['mrp.production'].sudo().search([ + ('name', 'in', mp_name_list)])}) + if len(os_ids) == 1: + purchase.origin_sale_id = os_ids[0] + elif len(os_ids) >= 2: + purchase.origin_sale_ids = os_ids + elif 'S' in purchase.origin: + os_name_list = [name.strip() for name in purchase['origin'].split(',')] + os_ids = self.env['sale.order'].sudo().search([('name', 'in', os_name_list)]) + if len(os_ids) == 1: + purchase.origin_sale_id = os_ids.id + elif len(os_ids) >= 2: + purchase.origin_sale_ids = os_ids.ids + + class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' part_number = fields.Char('零件图号', related='product_id.part_number', readonly=True) - related_product = fields.Many2one('product.product',compute='_compute_related_product', string='关联产品',help='经此产品工艺加工成的成品') + related_product = fields.Many2one('product.product', compute='_compute_related_product', string='关联产品', + help='经此产品工艺加工成的成品') + @api.depends('order_id.origin') def _compute_related_product(self): for record in self: @@ -73,4 +103,3 @@ class PurchaseOrderLine(models.Model): record.related_product = production_id.product_id if production_id else False else: record.related_product = False - diff --git a/sf_manufacturing/views/purchase_order_view.xml b/sf_manufacturing/views/purchase_order_view.xml index 83562f2c..3b1518fb 100644 --- a/sf_manufacturing/views/purchase_order_view.xml +++ b/sf_manufacturing/views/purchase_order_view.xml @@ -22,6 +22,13 @@ + + + + + diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index c9c06b9b..ac246da9 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -285,8 +285,6 @@ class RePurchaseOrder(models.Model): [('standard', '标准采购'), ('consignment', '工序外协'), ('outsourcing', '委外加工'), ('outside', '外购订单')], string='采购类型', default='standard', store=True, compute='_compute_purchase_type') - origin_sale_id = fields.Many2one('sale.order', string='销售订单号', compute='_compute_origin_sale_id') - # 合同编号 contract_number = fields.Char(string='合同编号', size=20) # 合同概况 @@ -311,21 +309,6 @@ class RePurchaseOrder(models.Model): purchase.purchase_type = 'outsourcing' break - @api.depends('order_line.move_dest_ids.group_id.mrp_production_ids', - 'order_line.move_ids.move_dest_ids.group_id.mrp_production_ids', 'origin') - def _compute_origin_sale_id(self): - for purchase in self: - productions_ids = purchase._get_mrp_productions() - if productions_ids: - if productions_ids[0].sale_order_id: - purchase.origin_sale_id = productions_ids[0].sale_order_id.id - continue - order_id = self.env['sale.order'].sudo().search([('name', '=', purchase.origin)]) - if order_id: - purchase.origin_sale_id = order_id.id - continue - purchase.origin_sale_id = False - delivery_warning = fields.Selection([('normal', '正常'), ('warning', '预警'), ('overdue', '已逾期')], string='交期状态', default='normal', tracking=True) diff --git a/sf_sale/views/purchase_order_view.xml b/sf_sale/views/purchase_order_view.xml index eec616f4..ecc061fa 100644 --- a/sf_sale/views/purchase_order_view.xml +++ b/sf_sale/views/purchase_order_view.xml @@ -190,11 +190,6 @@ - - - - - 1