From 81de156e1466862584dfdad5eccf5c361a2ea744 Mon Sep 17 00:00:00 2001 From: manu Date: Thu, 16 Jan 2025 12:15:34 +0100 Subject: [PATCH] [FIX]account_spread_cost_revenue: Total amount different currency --- account_spread_cost_revenue/README.rst | 1 + .../models/account_spread.py | 2 +- .../readme/CONTRIBUTORS.rst | 1 + .../static/description/index.html | 2 +- .../tests/test_account_invoice_spread.py | 36 ++++++++++++++++++- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/account_spread_cost_revenue/README.rst b/account_spread_cost_revenue/README.rst index e5ca11b3f..5b00a30c1 100644 --- a/account_spread_cost_revenue/README.rst +++ b/account_spread_cost_revenue/README.rst @@ -203,6 +203,7 @@ Contributors * Andrea Stirpe * Kitti U. * Saran Lim. +* Manuel Regidor Other credits ~~~~~~~~~~~~~ diff --git a/account_spread_cost_revenue/models/account_spread.py b/account_spread_cost_revenue/models/account_spread.py index 8f8b6ec76..d749272c5 100644 --- a/account_spread_cost_revenue/models/account_spread.py +++ b/account_spread_cost_revenue/models/account_spread.py @@ -191,7 +191,7 @@ class AccountSpread(models.Model): posted_amount = sum(spread_line.amount for spread_line in lines_posted) total_amount = spread.estimated_amount if spread.invoice_line_id: - total_amount = spread.invoice_line_id.currency_id._convert( + total_amount = spread.invoice_line_id.company_currency_id._convert( spread.invoice_line_id.balance, spread.currency_id, spread.company_id, diff --git a/account_spread_cost_revenue/readme/CONTRIBUTORS.rst b/account_spread_cost_revenue/readme/CONTRIBUTORS.rst index 926463864..adcc8d0bb 100644 --- a/account_spread_cost_revenue/readme/CONTRIBUTORS.rst +++ b/account_spread_cost_revenue/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Andrea Stirpe * Kitti U. * Saran Lim. +* Manuel Regidor diff --git a/account_spread_cost_revenue/static/description/index.html b/account_spread_cost_revenue/static/description/index.html index f32873202..e2eb8219f 100644 --- a/account_spread_cost_revenue/static/description/index.html +++ b/account_spread_cost_revenue/static/description/index.html @@ -1,4 +1,3 @@ - @@ -551,6 +550,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
  • Andrea Stirpe <a.stirpe@onestein.nl>
  • Kitti U. <kittiu@ecosoft.co.th>
  • Saran Lim. <saranl@ecosoft.co.th>
  • +
  • Manuel Regidor <manuel.regidor@sygel.es>
  • diff --git a/account_spread_cost_revenue/tests/test_account_invoice_spread.py b/account_spread_cost_revenue/tests/test_account_invoice_spread.py index 24bd3bd2c..89fa6751b 100644 --- a/account_spread_cost_revenue/tests/test_account_invoice_spread.py +++ b/account_spread_cost_revenue/tests/test_account_invoice_spread.py @@ -1,4 +1,5 @@ # Copyright 2018-2020 Onestein () +# Copyright 2025 Sygel () # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). import datetime @@ -9,7 +10,9 @@ from odoo.tests import Form, common class TestAccountInvoiceSpread(common.TransactionCase): - def create_account_invoice(self, invoice_type, quantity=1.0, price_unit=1000.0): + def create_account_invoice( + self, invoice_type, quantity=1.0, price_unit=1000.0, currency=False + ): """Create an invoice as in a view by triggering its onchange methods""" invoice_form = Form( @@ -18,6 +21,8 @@ class TestAccountInvoiceSpread(common.TransactionCase): invoice_form.partner_id = self.env["res.partner"].create( {"name": "Partner Name"} ) + if currency: + invoice_form.currency_id = currency with invoice_form.invoice_line_ids.new() as line: line.name = "product that costs " + str(price_unit) line.quantity = quantity @@ -805,3 +810,32 @@ class TestAccountInvoiceSpread(common.TransactionCase): reversal = move_reversal.reverse_moves() refund = self.env["account.move"].browse(reversal["res_id"]) self.assertFalse(refund.invoice_line_ids.mapped("spread_id")) + + def test_16_wizard_different_currency(self): + company_currency = self.env.company.currency_id + other_currency = self.env["res.currency"].search( + [("name", "!=", company_currency.name)], limit=1 + ) + self.env["res.currency.rate"].create( + { + "name": fields.Date.today(), + "currency_id": other_currency.id, + "company_rate": 2, + } + ) + vendor_bill = self.create_account_invoice("in_invoice", currency=other_currency) + bill_line = vendor_bill["invoice_line_ids"][0] + + Wizard = self.env["account.spread.invoice.line.link.wizard"] + wizard1 = Wizard.with_context( + default_invoice_line_id=bill_line.id, + default_company_id=self.env.company.id, + allow_spread_planning=True, + ).create({}) + self.assertEqual(wizard1.spread_action_type, "link") + + wizard1.spread_account_id = self.account_receivable + wizard1.spread_journal_id = self.expenses_journal + wizard1.spread_id = self.spread + wizard1.confirm() + self.assertEqual(self.spread.total_amount, bill_line.balance)