Skip to content

Commit

Permalink
[MIG] sale_order_invoice_amount: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MeritxellAForgeFlow committed Feb 7, 2025
1 parent 1d8ccef commit a6465b4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion sale_order_invoice_amount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Sale Order Invoice Amount",
"version": "16.0.1.0.1",
"version": "17.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"category": "Sales",
Expand Down
6 changes: 3 additions & 3 deletions sale_order_invoice_amount/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def _update_amounts(cr):
_update_amounts_for_non_cancel_invoices(cr)


def pre_init_hook(cr):
def pre_init_hook(env):
"""
Add columns to avoid Memory error on an existing Odoo instance with lots of data
"""
_add_new_columns(cr)
_update_amounts(cr)
_add_new_columns(env.cr)
_update_amounts(env.cr)
2 changes: 1 addition & 1 deletion sale_order_invoice_amount/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _compute_invoice_amount(self):
and rec.currency_id != invoice.company_currency_id
):
rec.invoiced_amount += invoice.currency_id._convert(
invoice.amount_total_signed,
invoice.amount_total_in_currency_signed,
rec.currency_id,
invoice.company_id,
invoice.invoice_date or fields.Date.today(),
Expand Down
32 changes: 22 additions & 10 deletions sale_order_invoice_amount/tests/test_sale_order_invoice_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,26 @@ def setUpClass(cls):
{"name": "Repair Services", "type": "service"}
)
cls.currency_eur = cls.env.ref("base.EUR")
cls.currency_eur.active = True
cls.currency_cad = cls.env.ref("base.CAD")
cls.currency_cad.active = True
cls.env["res.currency.rate"].search(
[("currency_id", "in", [cls.currency_eur.id, cls.currency_cad.id])]
).unlink()
cls.env["res.currency.rate"].create(
[
{
"name": fields.Date.from_string("2024-01-01"),
"rate": 1.500000, # Fixing the rate for test support.
"currency_id": cls.currency_eur.id,
},
{
"name": fields.Date.from_string("2024-01-01"),
"rate": 2.00000, # Fixing the rate for test support.
"currency_id": cls.currency_cad.id,
},
]
)
cls.res_partner_2 = cls.env["res.partner"].create({"name": "Partner 12"})
# Sale Order
cls.tax = cls.env["account.tax"].create(
Expand Down Expand Up @@ -149,6 +168,7 @@ def test_02_sale_order_invoiced_amount_different_currencies_invoice(self):
"Invoiced Amount should be 0.0",
)
self.sale_order_1.action_confirm()

price_foreign_currency_1 = self.sale_order_1.currency_id._convert(
10.0,
self.currency_eur,
Expand Down Expand Up @@ -310,11 +330,7 @@ def test_03_sale_order_invoiced_amount_different_currencies_sale(self):
}
)
test_invoice.action_post()
self.assertAlmostEqual(
self.sale_order_1.invoiced_amount,
242.0,
delta=40,
)
self.assertAlmostEqual(self.sale_order_1.invoiced_amount, 242.0, delta=0.2)
self.assertEqual(
self.sale_order_1.uninvoiced_amount,
121.0,
Expand Down Expand Up @@ -386,11 +402,7 @@ def test_03_sale_order_invoiced_amount_different_currencies_sale(self):
]
)
test_invoice.action_post()
self.assertAlmostEqual(
self.sale_order_1.invoiced_amount,
363.0,
delta=100,
)
self.assertAlmostEqual(self.sale_order_1.invoiced_amount, 363.0, delta=0.2)
self.assertEqual(
self.sale_order_1.uninvoiced_amount,
0.0,
Expand Down

0 comments on commit a6465b4

Please sign in to comment.