[IMP] account: Accounts m2o behavior
There are inconsistencies in the m2o accounts create & edit behavior. New off-balance account type was not correctly filtered This change correct those two issues Task ID: #2288757 closes odoo/odoo#54626 Related: odoo/enterprise#11920 Signed-off-by: Cedric Snauwaert (csn) <csn@openerp.com>
This commit is contained in:
@@ -35,7 +35,7 @@ class AccountAccountType(models.Model):
|
||||
class AccountAccount(models.Model):
|
||||
_name = "account.account"
|
||||
_description = "Account"
|
||||
_order = "code, company_id"
|
||||
_order = "is_off_balance, code, company_id"
|
||||
_check_company_auto = True
|
||||
|
||||
@api.constrains('internal_type', 'reconcile')
|
||||
@@ -84,6 +84,8 @@ class AccountAccount(models.Model):
|
||||
opening_credit = fields.Monetary(string="Opening Credit", compute='_compute_opening_debit_credit', inverse='_set_opening_credit', help="Opening credit value for this account.")
|
||||
opening_balance = fields.Monetary(string="Opening Balance", compute='_compute_opening_debit_credit', help="Opening balance value for this account.")
|
||||
|
||||
is_off_balance = fields.Boolean(compute='_compute_is_off_balance', default=False, store=True, readonly=True)
|
||||
|
||||
_sql_constraints = [
|
||||
('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !')
|
||||
]
|
||||
@@ -242,6 +244,11 @@ class AccountAccount(models.Model):
|
||||
record.opening_credit = res['credit']
|
||||
record.opening_balance = res['balance']
|
||||
|
||||
@api.depends('internal_group')
|
||||
def _compute_is_off_balance(self):
|
||||
for account in self:
|
||||
account.is_off_balance = account.internal_group == "off_balance"
|
||||
|
||||
def _set_opening_debit(self):
|
||||
self._set_opening_debit_credit(self.opening_debit, 'debit')
|
||||
|
||||
|
||||
@@ -53,10 +53,10 @@ class AccountJournal(models.Model):
|
||||
"Select 'Purchase' for vendor bills journals.\n"\
|
||||
"Select 'Cash' or 'Bank' for journals that are used in customer or vendor payments.\n"\
|
||||
"Select 'General' for miscellaneous operations journals.")
|
||||
type_control_ids = fields.Many2many('account.account.type', 'journal_account_type_control_rel', 'journal_id', 'type_id', string='Account Types Allowed')
|
||||
account_control_ids = fields.Many2many('account.account', 'journal_account_control_rel', 'journal_id', 'account_id', string='Accounts Allowed',
|
||||
type_control_ids = fields.Many2many('account.account.type', 'journal_account_type_control_rel', 'journal_id', 'type_id', string='Allowed account types')
|
||||
account_control_ids = fields.Many2many('account.account', 'journal_account_control_rel', 'journal_id', 'account_id', string='Allowed accounts',
|
||||
check_company=True,
|
||||
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]")
|
||||
domain="[('deprecated', '=', False), ('company_id', '=', company_id), ('is_off_balance', '=', False)]")
|
||||
default_account_type = fields.Many2one('account.account.type', compute="_compute_default_account_type")
|
||||
default_account_id = fields.Many2one(
|
||||
comodel_name='account.account', check_company=True, copy=False, ondelete='restrict',
|
||||
|
||||
@@ -2699,7 +2699,7 @@ class AccountMoveLine(models.Model):
|
||||
country_id = fields.Many2one(comodel_name='res.country', related='move_id.company_id.country_id')
|
||||
account_id = fields.Many2one('account.account', string='Account',
|
||||
index=True, ondelete="cascade",
|
||||
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
|
||||
domain="[('deprecated', '=', False), ('company_id', '=', 'company_id'),('is_off_balance', '=', False)]",
|
||||
check_company=True,
|
||||
tracking=True)
|
||||
account_internal_type = fields.Selection(related='account_id.user_type_id.type', string="Internal Type", readonly=True)
|
||||
|
||||
@@ -38,7 +38,7 @@ class AccountReconcileModelLine(models.Model):
|
||||
company_id = fields.Many2one(related='model_id.company_id', store=True, default=lambda self: self.env.company)
|
||||
sequence = fields.Integer(required=True, default=10)
|
||||
account_id = fields.Many2one('account.account', string='Account', ondelete='cascade',
|
||||
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
|
||||
domain="[('deprecated', '=', False), ('company_id', '=', company_id), ('is_off_balance', '=', False)]",
|
||||
required=True, check_company=True)
|
||||
journal_id = fields.Many2one('account.journal', string='Journal', ondelete='cascade',
|
||||
domain="[('type', '=', 'general'), ('company_id', '=', company_id)]",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
ACCOUNT_DOMAIN = "['&', '&', ('deprecated', '=', False), ('internal_type','=','other'), ('company_id', '=', current_company_id)]"
|
||||
ACCOUNT_DOMAIN = "['&', '&', '&', ('deprecated', '=', False), ('internal_type','=','other'), ('company_id', '=', current_company_id), ('is_off_balance', '=', False)]"
|
||||
|
||||
class ProductCategory(models.Model):
|
||||
_inherit = "product.category"
|
||||
|
||||
@@ -34,7 +34,7 @@ class AccountingTestTemplConsistency(TransactionCase):
|
||||
self.check_fields_consistency(
|
||||
'account.account.template', 'account.account', exceptions=['chart_template_id', 'nocreate'])
|
||||
self.check_fields_consistency(
|
||||
'account.account', 'account.account.template', exceptions=['company_id', 'deprecated', 'opening_debit', 'opening_credit', 'allowed_journal_ids', 'group_id', 'root_id'])
|
||||
'account.account', 'account.account.template', exceptions=['company_id', 'deprecated', 'opening_debit', 'opening_credit', 'allowed_journal_ids', 'group_id', 'root_id', 'is_off_balance'])
|
||||
|
||||
def test_account_tax_fields(self):
|
||||
'''Test fields consistency for ('account.tax', 'account.tax.template')
|
||||
|
||||
@@ -44,25 +44,25 @@
|
||||
<group string="Accounting information">
|
||||
<field name="default_account_type" invisible="1"/>
|
||||
<!-- Bank -->
|
||||
<field name="default_account_id" options="{'no_create': True}" string="Bank Account"
|
||||
<field name="default_account_id" string="Bank Account"
|
||||
attrs="{'required': [('id', '!=', False)], 'invisible': [('type', '!=', 'bank')]}"
|
||||
groups="account.group_account_readonly"/>
|
||||
<!-- Cash -->
|
||||
<field name="default_account_id" options="{'no_create': True}" string="Cash Account"
|
||||
<field name="default_account_id" string="Cash Account"
|
||||
attrs="{'required': [('id', '!=', False)], 'invisible': [('type', '!=', 'cash')]}"
|
||||
groups="account.group_account_readonly"/>
|
||||
|
||||
<field name="suspense_account_id" options="{'no_create': True}"
|
||||
attrs="{'required': [('id', '!=', False), ('type', 'in', ('bank', 'cash'))], 'invisible': [('type', 'not in', ('bank', 'cash'))]}"
|
||||
<field name="suspense_account_id"
|
||||
attrs="{'required': [('type', 'in', ('bank', 'cash'))], 'invisible': [('type', 'not in', ('bank', 'cash'))]}"
|
||||
groups="account.group_account_readonly"/>
|
||||
<field name="profit_account_id" options="{'no_create': True}" attrs="{'invisible': [('type', '!=', 'cash')]}"/>
|
||||
<field name="loss_account_id" options="{'no_create': True}" attrs="{'invisible': [('type', '!=', 'cash')]}"/>
|
||||
<field name="profit_account_id" attrs="{'invisible': [('type', '!=', 'cash')]}"/>
|
||||
<field name="loss_account_id" attrs="{'invisible': [('type', '!=', 'cash')]}"/>
|
||||
<!-- Sales -->
|
||||
<field name="default_account_id" options="{'no_create': True}" string="Default Income Account"
|
||||
<field name="default_account_id" string="Default Income Account"
|
||||
attrs="{'required': [('id', '!=', False)], 'invisible': [('type', '!=', 'sale')]}"
|
||||
groups="account.group_account_readonly"/>
|
||||
<!-- Purchase -->
|
||||
<field name="default_account_id" options="{'no_create': True}" string="Default Expense Account"
|
||||
<field name="default_account_id" string="Default Expense Account"
|
||||
attrs="{'required': [('id', '!=', False)], 'invisible': [('type', '!=', 'purchase')]}"
|
||||
groups="account.group_account_readonly"/>
|
||||
<field name="refund_sequence" attrs="{'invisible': [('type', 'not in', ['sale', 'purchase'])]}"/>
|
||||
@@ -79,14 +79,14 @@
|
||||
<page name="journal_entries" string="Payments Configuration" attrs="{'invisible': [('type', 'in', ['sale', 'purchase', 'general'])]}">
|
||||
<group>
|
||||
<group string="Incoming Payments">
|
||||
<field name="payment_debit_account_id" options="{'no_create': True}"
|
||||
<field name="payment_debit_account_id"
|
||||
attrs="{'required': [('id', '!=', False), ('type', 'in', ('bank', 'cash'))], 'invisible': [('type', 'not in', ('bank', 'cash'))]}"
|
||||
groups="account.group_account_readonly"/>
|
||||
<field name="inbound_payment_method_ids" string="Methods" widget="many2many_checkboxes" attrs="{'invisible': [('type', 'not in', ['bank', 'cash'])]}"/>
|
||||
</group>
|
||||
<group string="Outgoing Payments">
|
||||
<field name="id" invisible="1"/>
|
||||
<field name="payment_credit_account_id" options="{'no_create': True}"
|
||||
<field name="payment_credit_account_id"
|
||||
attrs="{'required': [('id', '!=', False), ('type', 'in', ('bank', 'cash'))], 'invisible': [('type', 'not in', ('bank', 'cash'))]}"
|
||||
groups="account.group_account_readonly"/>
|
||||
<field name="currency_id" options="{'no_create': True}" groups="base.group_multi_currency"/>
|
||||
|
||||
@@ -715,7 +715,8 @@
|
||||
<field name="name" widget="section_and_note_text" attrs="{'required': [('parent.move_type', 'not in', ('in_invoice', 'in_refund','in_receipt'))]}"/>
|
||||
<field name="account_id"
|
||||
groups="account.group_account_readonly"
|
||||
domain="[('deprecated', '=', False), ('user_type_id.type', 'not in', ('receivable', 'payable')), ('company_id', '=', parent.company_id)]"
|
||||
options="{'no_create': True}"
|
||||
domain="[('deprecated', '=', False), ('user_type_id.type', 'not in', ('receivable', 'payable')), ('company_id', '=', parent.company_id), ('is_off_balance', '=', False)]"
|
||||
attrs="{'required': [('display_type', '=', False)]}"/>
|
||||
<field name="analytic_account_id"
|
||||
domain="['|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]"
|
||||
|
||||
@@ -199,6 +199,7 @@
|
||||
<field name="partner_id" context="{'default_is_company': True}"
|
||||
attrs="{'readonly': ['|', ('state', '!=', 'draft'), ('is_internal_transfer', '=', True)]}"/>
|
||||
<field name="destination_account_id"
|
||||
options="{'no_create': True}"
|
||||
attrs="{'readonly': ['|', ('state', '!=', 'draft'), ('is_internal_transfer', '=', True)]}"/>
|
||||
<field name="is_internal_transfer"
|
||||
attrs="{'readonly': [('state', '!=', 'draft')]}"/>
|
||||
|
||||
@@ -14,8 +14,10 @@ class TaxAdjustments(models.TransientModel):
|
||||
reason = fields.Char(string='Justification', required=True)
|
||||
journal_id = fields.Many2one('account.journal', string='Journal', required=True, default=_get_default_journal, domain=[('type', '=', 'general')])
|
||||
date = fields.Date(required=True, default=fields.Date.context_today)
|
||||
debit_account_id = fields.Many2one('account.account', string='Debit account', required=True, domain=[('deprecated', '=', False)])
|
||||
credit_account_id = fields.Many2one('account.account', string='Credit account', required=True, domain=[('deprecated', '=', False)])
|
||||
debit_account_id = fields.Many2one('account.account', string='Debit account', required=True,
|
||||
domain="[('deprecated', '=', False), ('is_off_balance', '=', False)]")
|
||||
credit_account_id = fields.Many2one('account.account', string='Credit account', required=True,
|
||||
domain="[('deprecated', '=', False), ('is_off_balance', '=', False)]")
|
||||
amount = fields.Monetary(currency_field='company_currency_id', required=True)
|
||||
adjustment_type = fields.Selection([('debit', 'Applied on debit journal item'), ('credit', 'Applied on credit journal item')], string="Adjustment Type", required=True)
|
||||
tax_report_line_id = fields.Many2one(string="Report Line", comodel_name='account.tax.report.line', required=True, help="The report line to make an adjustment for.")
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
<field name="adjustment_type"/>
|
||||
</group>
|
||||
<group string="Accounts">
|
||||
<field name="debit_account_id" options="{'no_create': True}"/>
|
||||
<field name="credit_account_id" options="{'no_create': True}"/>
|
||||
<field name="debit_account_id"/>
|
||||
<field name="credit_account_id"/>
|
||||
</group>
|
||||
<group string="Options">
|
||||
<field name="journal_id"/>
|
||||
|
||||
@@ -87,7 +87,7 @@ class ResPartnerBank(models.Model):
|
||||
bank_bic = fields.Char(related='bank_id.bic', readonly=False)
|
||||
sequence = fields.Integer(default=10)
|
||||
currency_id = fields.Many2one('res.currency', string='Currency')
|
||||
company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company, ondelete='cascade')
|
||||
company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company, ondelete='cascade', readonly=True)
|
||||
|
||||
_sql_constraints = [
|
||||
('unique_number', 'unique(sanitized_acc_number, company_id)', 'Account Number must be unique'),
|
||||
|
||||
Reference in New Issue
Block a user