Skip to content

Commit

Permalink
[FIX] purchase_last_price_info: Adapt tests according to company curr…
Browse files Browse the repository at this point in the history
…ency

Depending on the installed modules, the company currency may be USD or EUR, affecting the
result of these tests. With this PR, the results are adjusted for both cases.
  • Loading branch information
victoralmau authored and pedrobaeza committed Dec 19, 2023
1 parent f23bc96 commit 805d245
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions purchase_last_price_info/tests/test_purchase_last_price_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
class TestPurchaseLastPriceInfo(common.TransactionCase):
def setUp(self):
super().setUp()
self.currency_usd = self.env.ref("base.USD")
self.currency_eur = self.env.ref("base.EUR")
usd = self.env.ref("base.USD")
eur = self.env.ref("base.EUR")
self.currency = self.env.ref("base.main_company").currency_id
self.currency_extra = eur if self.currency == usd else usd
self.purchase_model = self.env["purchase.order"]
self.purchase_line_model = self.env["purchase.order.line"]
self.product = self.env.ref("product.consu_delivery_01")
self.partner = self.env.ref("base.res_partner_1")
# Create custom rates to USD + EUR
self._create_currency_rate(self.currency_usd, "2000-01-01", 1.0)
self._create_currency_rate(self.currency_eur, "2000-01-01", 2.0)
# Create custom rates to currency + currency_extra
self._create_currency_rate(self.currency, "2000-01-01", 1.0)
self._create_currency_rate(self.currency_extra, "2000-01-01", 2.0)

def _create_currency_rate(self, currency_id, name, rate):
self.env["res.currency.rate"].create(
Expand All @@ -27,7 +29,7 @@ def _create_currency_rate(self, currency_id, name, rate):
def test_purchase_last_price_info_demo(self):
purchase_order = self.env.ref("purchase.purchase_order_6")
purchase_order.write(
{"date_order": "2000-01-01", "currency_id": self.currency_usd.id}
{"date_order": "2000-01-01", "currency_id": self.currency.id}
)
purchase_order.button_confirm()
purchase_lines = self.purchase_line_model.search(
Expand All @@ -51,14 +53,14 @@ def test_purchase_last_price_info_demo(self):
self.assertEqual(
first_purchase_line.currency_id, self.product.last_purchase_currency_id
)
self.assertEqual(self.product.last_purchase_currency_id, self.currency_usd)
self.assertEqual(self.product.last_purchase_currency_id, self.currency)
self.assertEqual(self.product.last_purchase_price_currency, 1.0)

def test_purchase_last_price_info_new_order(self):
purchase_order = self.purchase_model.create(
{
"date_order": "2000-01-01",
"currency_id": self.currency_eur.id,
"currency_id": self.currency_extra.id,
"partner_id": self.partner.id,
"order_line": [
(
Expand All @@ -83,8 +85,11 @@ def test_purchase_last_price_info_new_order(self):
)
first_order_line = fields.first(purchase_order.order_line)
self.assertEqual(first_order_line.price_unit, self.product.last_purchase_price)
self.assertEqual(first_order_line.price_unit, self.product.last_purchase_price)
self.assertEqual(self.product.last_purchase_currency_id, self.currency_eur)
self.assertEqual(
first_order_line.currency_id,
self.product.last_purchase_currency_id,
)
self.assertEqual(self.product.last_purchase_currency_id, self.currency_extra)
self.assertEqual(self.product.last_purchase_price_currency, 2.0)
self.assertEqual(self.partner, self.product.last_purchase_supplier_id)
purchase_order.button_cancel()
Expand Down

0 comments on commit 805d245

Please sign in to comment.