Skip to content

Commit

Permalink
[FIX] l10n_it_riba: Company consistency in RiBa configuration
Browse files Browse the repository at this point in the history
Co-authored-by: SirAionTech <[email protected]>
  • Loading branch information
odooNextev and SirAionTech committed Jan 22, 2024
1 parent ee9f282 commit 4c70d05
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 7 deletions.
29 changes: 22 additions & 7 deletions l10n_it_riba/models/riba_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class RibaConfiguration(models.Model):

_name = "riba.configuration"
_description = "Configuration parameters for RiBa"
_check_company_auto = True

name = fields.Char("Description", size=64, required=True)
type = fields.Selection(
Expand All @@ -25,17 +26,20 @@ class RibaConfiguration(models.Model):
"res.partner.bank",
"Bank Account",
required=True,
check_company=True,
help="Bank account used for RiBa issuing.",
)
acceptance_journal_id = fields.Many2one(
"account.journal",
"Acceptance Journal",
domain=[("type", "=", "bank")],
check_company=True,
domain="[('company_id', '=', company_id), ('type', '=', 'bank')]",
help="Journal used when RiBa is accepted by the bank.",
)
acceptance_account_id = fields.Many2one(
"account.account",
"Acceptance Account",
check_company=True,
help="Account used when RiBa is accepted by the bank.",
)
company_id = fields.Many2one(
Expand All @@ -47,38 +51,49 @@ class RibaConfiguration(models.Model):
credit_journal_id = fields.Many2one(
"account.journal",
"Credit Journal",
domain=[("type", "=", "bank")],
check_company=True,
domain="[('company_id', '=', company_id), ('type', '=', 'bank')]",
help="Journal used when RiBa amount is credited by the bank.",
)
credit_account_id = fields.Many2one(
"account.account",
"RiBa Account",
check_company=True,
help="Account used when RiBa amount is credited by the bank.",
domain=[("account_type", "!=", "liability_credit_card")],
domain="["
"('company_id', '=', company_id), "
"('account_type', '!=', 'liability_credit_card'), "
"]",
)
bank_account_id = fields.Many2one(
"account.account",
"A/C Bank Account",
domain=[("account_type", "=", "asset_cash")],
check_company=True,
domain="[('company_id', '=', company_id), ('account_type', '=', 'asset_cash')]",
)
bank_expense_account_id = fields.Many2one("account.account", "Bank Fees Account")
past_due_journal_id = fields.Many2one(
"account.journal",
"Past Due Journal",
domain=[("type", "=", "bank")],
check_company=True,
domain="[('company_id', '=', company_id), ('type', '=', 'bank')]",
help="Journal used when RiBa is past due.",
)
overdue_effects_account_id = fields.Many2one(
"account.account",
"Past Due Bills Account",
domain=[("account_type", "=", "asset_receivable")],
check_company=True,
domain="[('company_id', '=', company_id), ('account_type', '=', 'asset_receivable')]",
)
protest_charge_account_id = fields.Many2one(
"account.account", "Protest Fee Account"
"account.account",
"Protest Fee Account",
check_company=True,
)
settlement_journal_id = fields.Many2one(
"account.journal",
"Settlement Journal",
check_company=True,
help="Journal used when customers finally pay the invoice to bank.",
)

Expand Down
12 changes: 12 additions & 0 deletions l10n_it_riba/tests/riba_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def setUp(self):
],
}
)
self.company2 = self.env["res.company"].create(
{
"name": "company 2",
}
)
self.service_due_cost = self._create_service_due_cost()
self.account_model = self.env["account.account"]
self.move_line_model = self.env["account.move.line"]
Expand Down Expand Up @@ -144,6 +149,13 @@ def setUp(self):
}
)
self.company_bank = self.env.ref("l10n_it_riba.company_bank")
self.company2_bank = self.env["res.partner.bank"].create(
{
"acc_number": "IT000000000000000000",
"partner_id": self.company2.partner_id.id,
"company_id": self.company2.id,
}
)
self.riba_config = self.create_config()
self.account_payment_term_riba = self.env.ref(
"l10n_it_riba.account_payment_term_riba"
Expand Down
27 changes: 27 additions & 0 deletions l10n_it_riba/tests/test_riba.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import base64
import os

from odoo.exceptions import UserError
from odoo.tools import config

from . import riba_common
Expand Down Expand Up @@ -533,3 +534,29 @@ def test_riba_presentation(self):
self.env["account.move.line"].search(domain).mapped("amount_residual")
)
self.assertTrue(total_amount - total_issue_amount >= 0)

def test_riba_bank_multicompany(self):
"""Configuration parameters for RiBa
can only be created with data of current company."""
current_company = self.env.company
company_2 = self.company2
partner_bank = self.company2_bank
partner_bank.company_id = company_2
# pre-condition
self.assertEqual(partner_bank.company_id, company_2)
self.assertNotEqual(current_company, company_2)

# Act
with self.assertRaises(UserError) as ue:
self.env["riba.configuration"].create(
{
"name": "Subject To Collection",
"type": "incasso",
"bank_id": partner_bank.id,
}
)

# Assert
exc_message = ue.exception.args[0]
self.assertIn(current_company.name, exc_message)
self.assertIn(partner_bank.display_name, exc_message)
19 changes: 19 additions & 0 deletions l10n_it_riba/views/configuration_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
groups="base.group_multi_company"
readonly="1"
/>
<field
name="company_id"
groups="!base.group_multi_company"
invisible="True"
/>
</group>

<group string="Acceptance" attrs="{'invisible': [('type','!=','sbf')]}">
Expand Down Expand Up @@ -61,6 +66,20 @@
</field>
</record>

<!-- ====================================================== -->
<!-- CONFIGURAZIONE RIBA TREE -->
<!-- ====================================================== -->
<record model="ir.ui.view" id="view_riba_configuration_tree">
<field name="name">riba.configuration.tree</field>
<field name="model">riba.configuration</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="company_id" groups="base.group_multi_company" />
</tree>
</field>
</record>

<!-- ====================================================== -->
<!-- CONFIGURAZIONE RIBA ACTION -->
<!-- ====================================================== -->
Expand Down

0 comments on commit 4c70d05

Please sign in to comment.