diff --git a/addons/account_tax_cash_basis/__openerp__.py b/addons/account_tax_cash_basis/__openerp__.py index c6de2ca37a6..92d8644e561 100644 --- a/addons/account_tax_cash_basis/__openerp__.py +++ b/addons/account_tax_cash_basis/__openerp__.py @@ -13,7 +13,8 @@ 'website': 'https://www.odoo.com/page/accounting', 'depends' : ['account'], 'data': [ - 'views/tax_cash_basis_view.xml', + 'views/account_tax_views.xml', + 'views/account_config_setting_views.xml', ], 'installable': True, 'auto_install': False, diff --git a/addons/account_tax_cash_basis/models/__init__.py b/addons/account_tax_cash_basis/models/__init__.py index e6b78dead08..79092458d54 100644 --- a/addons/account_tax_cash_basis/models/__init__.py +++ b/addons/account_tax_cash_basis/models/__init__.py @@ -1,4 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import tax_cash_basis +import account_config_settings +import account_move +import account_partial_reconcile +import account_tax +import res_company diff --git a/addons/account_tax_cash_basis/models/account_config_settings.py b/addons/account_tax_cash_basis/models/account_config_settings.py new file mode 100644 index 00000000000..5c2f71ecfff --- /dev/null +++ b/addons/account_tax_cash_basis/models/account_config_settings.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields + + +class AccountConfigSettings(models.TransientModel): + _inherit = 'account.config.settings' + + tax_cash_basis_journal_id = fields.Many2one( + 'account.journal', + related='company_id.tax_cash_basis_journal_id', + string="Tax Cash Basis Journal",) diff --git a/addons/account_tax_cash_basis/models/account_move.py b/addons/account_tax_cash_basis/models/account_move.py new file mode 100644 index 00000000000..1fac8221343 --- /dev/null +++ b/addons/account_tax_cash_basis/models/account_move.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields + + +class AccountMoveCashBasis(models.Model): + _inherit = 'account.move' + + tax_cash_basis_rec_id = fields.Many2one( + 'account.partial.reconcile', + string='Tax Cash Basis Entry of', + help="Technical field used to keep track of the tax cash basis reconciliation." + "This is needed when cancelling the source: it will post the inverse journal entry to cancel that part too.") diff --git a/addons/account_tax_cash_basis/models/tax_cash_basis.py b/addons/account_tax_cash_basis/models/account_partial_reconcile.py similarity index 61% rename from addons/account_tax_cash_basis/models/tax_cash_basis.py rename to addons/account_tax_cash_basis/models/account_partial_reconcile.py index 8f45ab3e3a9..bb6bff7f53c 100644 --- a/addons/account_tax_cash_basis/models/tax_cash_basis.py +++ b/addons/account_tax_cash_basis/models/account_partial_reconcile.py @@ -1,64 +1,37 @@ # -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. -from openerp import models, fields, api, _ -from openerp.exceptions import UserError - -class AccountTaxCashBasis(models.Model): - _inherit = 'account.tax' - - use_cash_basis = fields.Boolean('Use Cash Basis', help='Select this if the tax should use cash basis, which will \ - create an entry for this tax on a given account during reconciliation') - cash_basis_account = fields.Many2one('account.account', string='Tax Received Account', domain=[('deprecated', '=', False)], help='Account use when \ - creating entry for tax cash basis') - - -class AccountMoveCashBasis(models.Model): - _inherit = 'account.move' - - tax_cash_basis_rec_id = fields.Many2one('account.partial.reconcile', string='Tax Cash Basis Entry of', help="Technical field used to keep track of the tax cash basis reconciliation. This is needed when cancelling the source: it will post the inverse journal entry to cancel that part too.") - - -class AccountConfigSettings(models.TransientModel): - _inherit = 'account.config.settings' - - tax_cash_basis_journal_id = fields.Many2one('account.journal', - related='company_id.tax_cash_basis_journal_id', - string="Tax Cash Basis Journal",) - - -class ResCompany(models.Model): - _inherit = 'res.company' - - tax_cash_basis_journal_id = fields.Many2one('account.journal', string="Tax Cash Basis Journal") +from odoo import api, models, _ +from odoo.exceptions import UserError class AccountPartialReconcileCashBasis(models.Model): _inherit = 'account.partial.reconcile' def create_tax_cash_basis_entry(self, value_before_reconciliation): - #Search in account_move if we have any taxes account move lines + # Search in account_move if we have any taxes account move lines tax_group = {} total_by_cash_basis_account = {} for move in (self.debit_move_id.move_id, self.credit_move_id.move_id): for line in move.line_ids: if line.tax_line_id and line.tax_line_id.use_cash_basis: - #amount to write is the current cash_basis amount minus the one before the reconciliation + # amount to write is the current cash_basis amount minus the one before the reconciliation matched_percentage = value_before_reconciliation[move.id] amount = (line.credit_cash_basis - line.debit_cash_basis) - (line.credit - line.debit) * matched_percentage - #group by line account + # group by line account acc = line.account_id.id if tax_group.get(acc, False): tax_group[acc] += amount else: tax_group[acc] = amount - #Group by cash basis account + # Group by cash basis account acc = line.tax_line_id.cash_basis_account.id if total_by_cash_basis_account.get(acc, False): total_by_cash_basis_account[acc] += amount else: total_by_cash_basis_account[acc] = amount line_to_create = [] - for k,v in tax_group.items(): + for k, v in tax_group.items(): line_to_create.append((0, 0, { 'name': '/', 'debit': v if v > 0 else 0.0, @@ -66,8 +39,8 @@ class AccountPartialReconcileCashBasis(models.Model): 'account_id': k, })) - #Create counterpart vals - for k,v in total_by_cash_basis_account.items(): + # Create counterpart vals + for k, v in total_by_cash_basis_account.items(): line_to_create.append((0, 0, { 'name': '/', 'debit': abs(v) if v < 0 else 0.0, @@ -75,9 +48,9 @@ class AccountPartialReconcileCashBasis(models.Model): 'account_id': k, })) - #Create move + # Create move if len(line_to_create) > 0: - #Check if company_journal for cash basis is set if not, raise exception + # Check if company_journal for cash basis is set if not, raise exception if not self.company_id.tax_cash_basis_journal_id: raise UserError(_('There is no tax cash basis journal defined ' \ 'for this company: "%s" \nConfigure it in Accounting/Configuration/Settings') % \ @@ -86,7 +59,7 @@ class AccountPartialReconcileCashBasis(models.Model): 'journal_id': self.company_id.tax_cash_basis_journal_id.id, 'line_ids': line_to_create, 'tax_cash_basis_rec_id': self.id}) - #post move + # post move move.post() @api.model @@ -96,15 +69,15 @@ class AccountPartialReconcileCashBasis(models.Model): aml.append(vals['debit_move_id']) if vals.get('credit_move_id', False): aml.append(vals['credit_move_id']) - #Get value of matched percentage from both move before reconciliating + # Get value of matched percentage from both move before reconciliating lines = self.env['account.move.line'].browse(aml) value_before_reconciliation = {} for line in lines: if not value_before_reconciliation.get(line.move_id.id, False): value_before_reconciliation[line.move_id.id] = line.move_id.matched_percentage - #Reconcile + # Reconcile res = super(AccountPartialReconcileCashBasis, self).create(vals) - #eventually create a tax cash basis entry + # eventually create a tax cash basis entry res.create_tax_cash_basis_entry(value_before_reconciliation) return res diff --git a/addons/account_tax_cash_basis/models/account_tax.py b/addons/account_tax_cash_basis/models/account_tax.py new file mode 100644 index 00000000000..aac809c20b2 --- /dev/null +++ b/addons/account_tax_cash_basis/models/account_tax.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields + + +class AccountTax(models.Model): + _inherit = 'account.tax' + + use_cash_basis = fields.Boolean( + 'Use Cash Basis', + help="Select this if the tax should use cash basis," + "which will create an entry for this tax on a given account during reconciliation") + cash_basis_account = fields.Many2one( + 'account.account', + string='Tax Received Account', + domain=[('deprecated', '=', False)], + help='Account use when creating entry for tax cash basis') diff --git a/addons/account_tax_cash_basis/models/res_company.py b/addons/account_tax_cash_basis/models/res_company.py new file mode 100644 index 00000000000..cbf55554f43 --- /dev/null +++ b/addons/account_tax_cash_basis/models/res_company.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields + + +class ResCompany(models.Model): + _inherit = 'res.company' + + tax_cash_basis_journal_id = fields.Many2one('account.journal', string="Tax Cash Basis Journal") diff --git a/addons/account_tax_cash_basis/views/account_config_setting_views.xml b/addons/account_tax_cash_basis/views/account_config_setting_views.xml new file mode 100644 index 00000000000..fb503fd13b1 --- /dev/null +++ b/addons/account_tax_cash_basis/views/account_config_setting_views.xml @@ -0,0 +1,16 @@ + + + + view.account.config.cash.basis.form.inherit + + account.config.settings + + +
+
+
+
+
+
\ No newline at end of file diff --git a/addons/account_tax_cash_basis/views/tax_cash_basis_view.xml b/addons/account_tax_cash_basis/views/account_tax_views.xml similarity index 52% rename from addons/account_tax_cash_basis/views/tax_cash_basis_view.xml rename to addons/account_tax_cash_basis/views/account_tax_views.xml index 001ca958973..4c661afdbc8 100644 --- a/addons/account_tax_cash_basis/views/tax_cash_basis_view.xml +++ b/addons/account_tax_cash_basis/views/account_tax_views.xml @@ -14,19 +14,5 @@ - - view.account.config.cash.basis.form.inherit - - account.config.settings - - -
-
-
-
-
-