forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct_template.py
More file actions
72 lines (64 loc) · 3 KB
/
product_template.py
File metadata and controls
72 lines (64 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Copyright 2018 Tecnativa - Vicent Cubells
# Copyright 2018 Tecnativa - Pedro M. Baeza
# Copyright 2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import datetime
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
def _get_supplierinfo_pricelist_price(
self, rule, date=None, quantity=None, product_id=None
):
"""Method for getting the price from supplier info."""
self.ensure_one()
price = 0.0
product = self.product_variant_id
if product_id:
product = product.browse(product_id)
if rule.no_supplierinfo_min_quantity:
# No matter which minimum qty, we'll get every seller. We set a
# number absurdidly high
quantity = 1e9
# The product_variant_id returns empty recordset if template is not
# active, so we must ensure variant exists or _select_seller fails.
if product:
if type(date) == datetime:
date = date.date()
seller = product.with_context(
override_min_qty=rule.no_supplierinfo_min_quantity
)._select_seller(
# For a public user this record could be not accessible, but we
# need to get the price anyway
partner_id=self.env.context.get(
"force_filter_supplier_id", rule.sudo().filter_supplier_id
),
quantity=quantity,
date=date,
)
if seller:
price = seller._get_supplierinfo_pricelist_price()
if price:
# We need to convert the price if the pricelist and seller have
# different currencies so the price have the pricelist currency
if rule.currency_id != seller.currency_id:
convert_date = date or self.env.context.get("date", fields.Date.today())
price = seller.currency_id._convert(
price, rule.currency_id, seller.company_id, convert_date
)
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)
return price
def price_compute(self, price_type, uom=False, currency=False, company=False):
"""Return dummy not falsy prices when computation is done from supplier
info for avoiding error on super method. We will later fill these with
correct values.
"""
if price_type == "supplierinfo":
return dict.fromkeys(self.ids, 1.0)
return super().price_compute(
price_type, uom=uom, currency=currency, company=company
)