mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Tests and small fixes
This commit is contained in:
committed by
Dhaval Talpada
parent
143dc7aa2a
commit
c81f801deb
@@ -7,7 +7,7 @@
|
||||
"category": "Accounts",
|
||||
"license": "LGPL-3",
|
||||
"depends": ["account"],
|
||||
"data": ["views/account_move_line_view.xml"],
|
||||
"data": ["views/account_move_line_view.xml", "views/account_move_view.xml"],
|
||||
"pre_init_hook": "pre_init_hook",
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
@@ -11,10 +11,8 @@ _logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def pre_init_hook(cr):
|
||||
_logger.info(
|
||||
"Pre-creating column amount_used_currency for table " "account_move_line"
|
||||
)
|
||||
if not openupgrade.column_exists(cr, "account_move_ine", "amount_used_currency"):
|
||||
_logger.info("Pre-creating column amount_used_currency for table account_move_line")
|
||||
if not openupgrade.column_exists(cr, "account_move_line", "amount_used_currency"):
|
||||
cr.execute(
|
||||
"""
|
||||
ALTER TABLE account_move_line
|
||||
@@ -24,7 +22,7 @@ def pre_init_hook(cr):
|
||||
"""
|
||||
)
|
||||
_logger.info("Pre-creating column used_currency_id for table account_move_line")
|
||||
if not openupgrade.column_exists(cr, "account_move_ine", "used_currency_id"):
|
||||
if not openupgrade.column_exists(cr, "account_move_line", "used_currency_id"):
|
||||
cr.execute(
|
||||
"""
|
||||
ALTER TABLE account_move_line
|
||||
|
||||
@@ -4,8 +4,8 @@ This module introduces to journal items two new fields:
|
||||
|
||||
* Used Currency
|
||||
|
||||
When the jounal item is expressed in foreign currency, those fields will be
|
||||
computed with the amount in foregign currency. Otherwise the company currency
|
||||
When the journal item is expressed in foreign currency, those fields will be
|
||||
computed with the amount in foreign currency. Otherwise the company currency
|
||||
and balance in company currency is filled in.
|
||||
|
||||
Those fields are useful for reporting purposes. For example, in an
|
||||
|
||||
1
account_move_line_used_currency/tests/__init__.py
Normal file
1
account_move_line_used_currency/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_account_move_line_used_currency
|
||||
@@ -0,0 +1,118 @@
|
||||
# Copyright 2021 ForgeFlow, S.L.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
|
||||
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestAccountMoveLineCurrency(common.SavepointCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
res_users_account_manager = cls.env.ref("account.group_account_manager")
|
||||
partner_manager = cls.env.ref("base.group_partner_manager")
|
||||
cls.env.user.write(
|
||||
{"groups_id": [(6, 0, [res_users_account_manager.id, partner_manager.id])]}
|
||||
)
|
||||
|
||||
# Partner
|
||||
cls.res_partner_1 = cls.env["res.partner"].create({"name": "Wood Corner"})
|
||||
|
||||
# Products
|
||||
cls.product_1 = cls.env["product.product"].create(
|
||||
{"name": "Desk Combination", "list_price": 100}
|
||||
)
|
||||
cls.product_2 = cls.env["product.product"].create(
|
||||
{"name": "Desk Combination 2", "list_price": 100}
|
||||
)
|
||||
|
||||
# Tax
|
||||
cls.tax = cls.env["account.tax"].create(
|
||||
{"name": "Tax 15", "type_tax_use": "sale", "amount": 20}
|
||||
)
|
||||
|
||||
# Currencies
|
||||
cls.currency_euro = cls.env["res.currency"].search([("name", "=", "EUR")])
|
||||
cls.currency_usd = cls.env["res.currency"].search([("name", "=", "USD")])
|
||||
cls.currency_rate = cls.env["res.currency.rate"].create(
|
||||
{"rate": 1.30, "currency_id": cls.currency_usd.id}
|
||||
)
|
||||
|
||||
# Invoices
|
||||
cls.invoice_1 = cls.env["account.move"].create(
|
||||
[
|
||||
{
|
||||
"type": "out_invoice",
|
||||
"partner_id": cls.res_partner_1.id,
|
||||
"currency_id": cls.currency_euro.id,
|
||||
"invoice_line_ids": [
|
||||
(
|
||||
0,
|
||||
None,
|
||||
{
|
||||
"product_id": cls.product_1.id,
|
||||
"product_uom_id": cls.product_1.uom_id.id,
|
||||
"quantity": 12,
|
||||
"price_unit": 1000,
|
||||
"tax_ids": cls.tax,
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
cls.invoice_2 = cls.env["account.move"].create(
|
||||
[
|
||||
{
|
||||
"type": "out_invoice",
|
||||
"partner_id": cls.res_partner_1.id,
|
||||
"currency_id": cls.currency_usd.id,
|
||||
"invoice_line_ids": [
|
||||
(
|
||||
0,
|
||||
None,
|
||||
{
|
||||
"product_id": cls.product_2.id,
|
||||
"product_uom_id": cls.product_2.uom_id.id,
|
||||
"quantity": 10,
|
||||
"price_unit": 500,
|
||||
"tax_ids": cls.tax,
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
cls.invoice_1.action_post()
|
||||
cls.invoice_2.action_post()
|
||||
|
||||
def test_account_move_line_used_currency(self):
|
||||
self.assertEqual(
|
||||
self.invoice_1.amount_total, 14400,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
self.invoice_2.amount_total, 6000,
|
||||
)
|
||||
|
||||
item_1 = self.env["account.move.line"].browse(
|
||||
self.invoice_1.invoice_line_ids.id
|
||||
)
|
||||
self.assertEqual(
|
||||
item_1.amount_used_currency, -12000,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
item_1.used_currency_id.id, self.currency_euro.id,
|
||||
)
|
||||
|
||||
item_2 = self.env["account.move.line"].browse(
|
||||
self.invoice_2.invoice_line_ids.id
|
||||
)
|
||||
self.assertEqual(
|
||||
item_2.amount_used_currency, -5000,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
item_2.used_currency_id.id, self.currency_usd.id,
|
||||
)
|
||||
17
account_move_line_used_currency/views/account_move_view.xml
Normal file
17
account_move_line_used_currency/views/account_move_view.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="view_move_form" model="ir.ui.view">
|
||||
<field name="name">account.move.form</field>
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_move_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath
|
||||
expr="//field[@name='line_ids']/tree//field[@name='credit']"
|
||||
position="after"
|
||||
>
|
||||
<field name="amount_used_currency" optional="hide" />
|
||||
<field name="used_currency_id" optional="hide" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user