Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion product_pricelist_supplierinfo/models/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@ def _compute_price_rule(self, products_qty_partner, date=False, uom_id=False):
for product, qty, _partner in products_qty_partner:
rule = rule_obj.browse(result[product.id][1])
if rule.compute_price == "formula" and rule.base == "supplierinfo":
result[product.id] = (
qty_uom_id = self._context.get("uom") or product.uom_id.id
price_uom = self.env["uom.uom"].browse([qty_uom_id])
price = rule._compute_price(
product.sudo()._get_supplierinfo_pricelist_price(
rule,
date=date or context.get("date", fields.Date.today()),
quantity=qty,
),
price_uom,
product,
quantity=qty,
partner=_partner,
)
result[product.id] = (
price,
rule.id,
)
return result
Expand Down
24 changes: 1 addition & 23 deletions product_pricelist_supplierinfo/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from datetime import datetime

from odoo import fields, models, tools
from odoo import fields, models


class ProductTemplate(models.Model):
Expand Down Expand Up @@ -51,35 +51,13 @@ def _get_supplierinfo_pricelist_price(
price, rule.currency_id, seller.company_id, convert_date
)

# We have to replicate this logic in this method as pricelist
# method are atomic and we can't hack inside.
# Verbatim copy of part of product.pricelist._compute_price_rule.
qty_uom_id = self._context.get("uom") or self.uom_id.id
price_uom = self.env["uom.uom"].browse([qty_uom_id])

# We need to convert the price to the uom used on the sale, if the
# uom on the seller is a different one that the one used there.
if seller and seller.product_uom != price_uom:
price = seller.product_uom._compute_price(price, price_uom)
price_limit = price
price = (price - (price * (rule.price_discount / 100))) or 0.0
if rule.price_round:
price = tools.float_round(price, precision_rounding=rule.price_round)
if rule.price_surcharge:
price_surcharge = self.uom_id._compute_price(
rule.price_surcharge, price_uom
)
price += price_surcharge
if rule.price_min_margin:
price_min_margin = self.uom_id._compute_price(
rule.price_min_margin, price_uom
)
price = max(price, price_limit + price_min_margin)
if rule.price_max_margin:
price_max_margin = self.uom_id._compute_price(
rule.price_max_margin, price_uom
)
price = min(price, price_limit + price_max_margin)
return price

def price_compute(self, price_type, uom=False, currency=False, company=False):
Expand Down
Loading