Skip to content

Commit

Permalink
[IMP] product_pack: support pack components fixed price by pricelist
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-zanotti authored and augusto-weiss committed Jan 11, 2024
1 parent 9beff73 commit 3408c93
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
19 changes: 13 additions & 6 deletions product_pack/models/product_pack_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,20 @@ def _check_recursion(self):
)
pack_lines = pack_lines.mapped("product_id.pack_line_ids")

def price_compute(
def _pack_line_price_compute(
self, price_type, uom=False, currency=False, company=False, date=False
):
pack_line_prices = self.product_id.price_compute(
price_type, uom, currency, company, date
)
for line in self:
pack_line_prices[line.product_id.id] *= line.quantity
pack_line_prices = {}
if self._context.get("pricelist"):
for line in self:
pack_line_prices[line.product_id.id] = line.with_context({
"quantity": line.quantity,
}).product_id._get_contextual_price()
else:
pack_line_prices = self.product_id.price_compute(
price_type, uom, currency, company, date
)
for line in self:
pack_line_prices[line.product_id.id] *= line.quantity

return pack_line_prices
2 changes: 1 addition & 1 deletion product_pack/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def price_compute(
)
# TODO:@bruno-zanotti prefetch_fields=False still necessary?
for product in packs.with_context(prefetch_fields=False):
pack_line_prices = product.sudo().pack_line_ids.price_compute(
pack_line_prices = product.sudo().pack_line_ids._pack_line_price_compute(
price_type, uom, currency, company, date
)
prices[product.id] = sum(pack_line_prices.values())
Expand Down
4 changes: 2 additions & 2 deletions sale_product_pack/models/product_pack_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def get_sale_order_line_vals(self, line, order):

return vals

def price_compute(
def _pack_line_price_compute(
self, price_type, uom=False, currency=False, company=False, date=False
):
pack_line_prices = super().price_compute(
pack_line_prices = super()._pack_line_price_compute(
price_type, uom, currency, company, date
)
for line in self:
Expand Down
5 changes: 5 additions & 0 deletions sale_product_pack/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ def _get_update_prices_lines(self):
lambda line: not line.pack_parent_line_id
or line.pack_parent_line_id.pack_component_price == "detailed"
)

def action_update_prices(self):
super(
SaleOrder, self.with_context(pricelist=self.pricelist_id.id)
).action_update_prices()

0 comments on commit 3408c93

Please sign in to comment.