From 71a0f39ec99c704aad82de18a248612b0f703fcf Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Wed, 18 Jun 2025 10:50:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A6=82=E6=9E=9C=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E8=AE=A2=E5=8D=95=E7=B1=BB=E5=9E=8B=E4=B8=BA=E5=A7=94?= =?UTF-8?q?=E5=A4=96=E5=8A=A0=E5=B7=A5=EF=BC=8C=E5=88=99=E4=B8=8D=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=BE=9B=E5=BA=94=E5=95=86=E6=A0=A1=E9=AA=8C=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E7=94=9F=E6=88=90=E8=A1=A5=E7=BB=99=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/__init__.py | 1 + sf_manufacturing/models/bom.py | 16 ++++++++++++++++ sf_manufacturing/models/stock.py | 14 ++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 sf_manufacturing/models/bom.py diff --git a/sf_manufacturing/models/__init__.py b/sf_manufacturing/models/__init__.py index 8af783e7..c8af2d82 100644 --- a/sf_manufacturing/models/__init__.py +++ b/sf_manufacturing/models/__init__.py @@ -18,4 +18,5 @@ from . import quick_easy_order from . import purchase_order from . import quality_check from . import purchase_request_line +from . import bom # from . import stock_warehouse_orderpoint \ No newline at end of file diff --git a/sf_manufacturing/models/bom.py b/sf_manufacturing/models/bom.py new file mode 100644 index 00000000..d0a35300 --- /dev/null +++ b/sf_manufacturing/models/bom.py @@ -0,0 +1,16 @@ +from odoo import models +from odoo.osv.expression import AND + + +class MrpBom(models.Model): + _inherit = 'mrp.bom' + + def _bom_subcontract_find(self, product, picking_type=None, company_id=False, bom_type='subcontract', subcontractor=False): + domain = self._bom_find_domain(product, picking_type=picking_type, company_id=company_id, bom_type=bom_type) + if self.env.context.get('stock_picking') == 'outsourcing': + return self.search(domain, order='sequence, product_id, id', limit=1) + if subcontractor: + domain = AND([domain, [('subcontractor_ids', 'parent_of', subcontractor.ids)]]) + return self.search(domain, order='sequence, product_id, id', limit=1) + else: + return self.env['mrp.bom'] diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 4134de94..05943e83 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -1216,6 +1216,20 @@ class ReStockMove(models.Model): res['lot_id'] = self.subcontract_workorder_id.production_id.move_raw_ids.move_line_ids[0].lot_id.id return res + def _get_subcontract_bom(self): + self.ensure_one() + purchase_type = getattr(self.picking_id.purchase_id, 'purchase_type', False) + if purchase_type: + self = self.with_context(stock_picking=purchase_type) + bom = self.env['mrp.bom'].sudo()._bom_subcontract_find( + self.product_id, + picking_type=self.picking_type_id, + company_id=self.company_id.id, + bom_type='subcontract', + subcontractor=self.picking_id.partner_id + ) + return bom + class ReStockQuant(models.Model): _inherit = 'stock.quant'