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'