diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/mrp_subcontracting/models/mrp_bom.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/mrp_subcontracting/models/mrp_bom.py')
| -rw-r--r-- | addons/mrp_subcontracting/models/mrp_bom.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/addons/mrp_subcontracting/models/mrp_bom.py b/addons/mrp_subcontracting/models/mrp_bom.py new file mode 100644 index 00000000..e3b9c0a7 --- /dev/null +++ b/addons/mrp_subcontracting/models/mrp_bom.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError +from odoo.osv.expression import AND + +class MrpBom(models.Model): + _inherit = 'mrp.bom' + + type = fields.Selection(selection_add=[ + ('subcontract', 'Subcontracting') + ], ondelete={'subcontract': lambda recs: recs.write({'type': 'normal', 'active': False})}) + subcontractor_ids = fields.Many2many('res.partner', 'mrp_bom_subcontractor', string='Subcontractors', check_company=True) + + def _bom_subcontract_find(self, product_tmpl=None, product=None, picking_type=None, company_id=False, bom_type='subcontract', subcontractor=False): + domain = self._bom_find_domain(product_tmpl=product_tmpl, product=product, picking_type=picking_type, company_id=company_id, bom_type=bom_type) + if subcontractor: + domain = AND([domain, [('subcontractor_ids', 'parent_of', subcontractor.ids)]]) + return self.search(domain, order='sequence, product_id', limit=1) + else: + return self.env['mrp.bom'] + + @api.constrains('operation_ids', 'type') + def _check_subcontracting_no_operation(self): + if self.filtered_domain([('type', '=', 'subcontract'), ('operation_ids', '!=', False)]): + raise ValidationError(_('You can not set a Bill of Material with operations as subcontracting.')) |
