product.py 1.2 KB

123456789101112131415161718192021222324252627
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, fields, models
  4. class SupplierInfo(models.Model):
  5. _inherit = 'product.supplierinfo'
  6. is_subcontractor = fields.Boolean('Subcontracted', compute='_compute_is_subcontractor', help="Choose a vendor of type subcontractor if you want to subcontract the product")
  7. @api.depends('partner_id', 'product_id', 'product_tmpl_id')
  8. def _compute_is_subcontractor(self):
  9. for supplier in self:
  10. boms = supplier.product_id.variant_bom_ids
  11. boms |= supplier.product_tmpl_id.bom_ids.filtered(lambda b: not b.product_id or b.product_id in (supplier.product_id or supplier.product_tmpl_id.product_variant_ids))
  12. supplier.is_subcontractor = supplier.partner_id in boms.subcontractor_ids
  13. class ProductProduct(models.Model):
  14. _inherit = 'product.product'
  15. def _prepare_sellers(self, params=False):
  16. if params and params.get('subcontractor_ids'):
  17. return super()._prepare_sellers(params=params).filtered(lambda s: s.partner_id in params.get('subcontractor_ids'))
  18. return super()._prepare_sellers(params=params)