Skip to content

Commit

Permalink
[MIG] account_invoice_pricelist: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomacr committed Nov 29, 2022
1 parent 91ce88b commit ac8ece0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion account_invoice_pricelist/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{
"name": "Account - Pricelist on Invoices",
"version": "14.0.1.0.0",
"version": "15.0.1.0.0",
"summary": "Add partner pricelist on invoices",
"category": "Accounting & Finance",
"author": "GRAP," "Therp BV," "Tecnativa," "Odoo Community Association (OCA)",
Expand Down
58 changes: 28 additions & 30 deletions account_invoice_pricelist/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,31 @@ def _onchange_product_id_account_invoice_pricelist(self):

@api.onchange("product_uom_id")
def _onchange_uom_id(self):
for sel in self:
if (
sel.move_id.is_invoice()
and sel.move_id.state == "draft"
and sel.move_id.pricelist_id
):
price_unit = sel._get_computed_price_unit()
taxes = sel._get_computed_taxes()
if taxes and sel.move_id.fiscal_position_id:
price_subtotal = sel._get_price_total_and_subtotal(
price_unit=price_unit, taxes=taxes
)["price_subtotal"]
accounting_vals = sel._get_fields_onchange_subtotal(
price_subtotal=price_subtotal,
currency=self.move_id.company_currency_id,
)
amount_currency = accounting_vals["amount_currency"]
price_unit = sel._get_fields_onchange_balance(
amount_currency=amount_currency
).get("price_unit", price_unit)
sel.with_context(check_move_validity=False).update(
{"price_unit": price_unit}
if (
self.move_id.is_invoice()
and self.move_id.state == "draft"
and self.move_id.pricelist_id
):
price_unit = self._get_computed_price_unit()
taxes = self._get_computed_taxes()
if taxes and self.move_id.fiscal_position_id:
price_subtotal = self._get_price_total_and_subtotal(
price_unit=price_unit, taxes=taxes
)["price_subtotal"]
accounting_vals = self._get_fields_onchange_subtotal(
price_subtotal=price_subtotal,
currency=self.move_id.company_currency_id,
)
else:
super(AccountMoveLine, self)._onchange_uom_id()
amount_currency = accounting_vals["amount_currency"]
price_unit = self._get_fields_onchange_balance(
amount_currency=amount_currency
).get("price_unit", price_unit)
self.with_context(check_move_validity=False).update(
{"price_unit": price_unit}
)
return
else:
return super(AccountMoveLine, self)._onchange_uom_id()

def _get_real_price_currency(self, product, rule_id, qty, uom, pricelist_id):
PricelistItem = self.env["product.pricelist.item"]
Expand Down Expand Up @@ -188,19 +188,17 @@ def _get_price_with_pricelist(self):
)
self.with_context(check_move_validity=False).discount = 0.0
else:
product_context = dict(
self.env.context,
final_price, rule_id = self.move_id.pricelist_id.with_context(
partner_id=self.move_id.partner_id.id,
date=self.move_id.invoice_date or fields.Date.today(),
uom=self.product_uom_id.id,
)
final_price, rule_id = self.move_id.pricelist_id.with_context(
product_context
).get_product_price_rule(
self.product_id, self.quantity or 1.0, self.move_id.partner_id
)
base_price, currency = self.with_context(
product_context
partner_id=self.move_id.partner_id.id,
date=self.move_id.invoice_date or fields.Date.today(),
uom=self.product_uom_id.id,
)._get_real_price_currency(
self.product_id,
rule_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hashlib
import inspect

from odoo.exceptions import UserError
from odoo.tests import common

from odoo.addons.sale.models.sale import SaleOrderLine as upstream
Expand Down Expand Up @@ -125,6 +126,7 @@ def setUpClass(cls):
}
)
cls.euro_currency = cls.env["res.currency"].search([("name", "=", "EUR")])
cls.usd_currency = cls.env["res.currency"].search([("name", "=", "USD")])
cls.sale_pricelist_with_discount_in_euros = cls.ProductPricelist.create(
{
"name": "Test Sale pricelist - 4",
Expand Down Expand Up @@ -316,3 +318,10 @@ def test_upstream_file_hash(self):
func = inspect.getsource(upstream._get_real_price_currency).encode()
func_hash = hashlib.md5(func).hexdigest()
self.assertIn(func_hash, VALID_HASHES)

def test_check_currency(self):
with self.assertRaises(UserError):
self.invoice.currency_id = self.usd_currency.id
self.invoice.write(
{"pricelist_id": self.sale_pricelist_with_discount_in_euros.id}
)

0 comments on commit ac8ece0

Please sign in to comment.