Skip to content

Commit

Permalink
Merge pull request #1 from legalsylvain/12.0-imp-product_pack_overloa…
Browse files Browse the repository at this point in the history
…dable

[IMP] possibility to overload product_pack
  • Loading branch information
pedrobaeza committed Sep 18, 2019
2 parents 0016676 + e1e5ad9 commit 4bb6278
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions product_pack/models/product_product.py
Expand Up @@ -20,6 +20,13 @@ class ProductProduct(models.Model):
help='Packs where product is used.'
)

@api.multi
def get_pack_lines(self):
"""Returns the content (lines) of the packs.
By default, return all the pack_line_ids, but that function
can be overloaded to introduce filtering function by date, etc..."""
return self.mapped('pack_line_ids')

@api.multi
def split_pack_products(self):
"""Split products and the pack in 2 separate recordsets.
Expand All @@ -37,7 +44,7 @@ def split_pack_products(self):
packs |= self.filtered(
lambda p: p.pack_ok and p.pack_type == 'components_price')

no_packs = (self | self.mapped('pack_line_ids.product_id')) - packs
no_packs = (self | self.get_pack_lines().mapped('product_id')) - packs
return packs, no_packs

@api.multi
Expand All @@ -48,7 +55,7 @@ def price_compute(self, price_type, uom=False, currency=False,
price_type, uom, currency, company)
for product in packs.with_context(prefetch_fields=False):
pack_price = 0.0
for pack_line in product.pack_line_ids:
for pack_line in product.get_pack_lines():
product_line_price = pack_line.product_id.price
pack_price += (product_line_price * pack_line.quantity)
prices[product.id] = pack_price
Expand Down

0 comments on commit 4bb6278

Please sign in to comment.