[MOV] account_tax_cash_basis: split account models and views into their own files
This commit is contained in:
committed by
Thibault Delavallée
parent
b113f1cb58
commit
f28f35fa15
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",)
|
||||
@@ -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.")
|
||||
+16
-43
@@ -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
|
||||
|
||||
@@ -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')
|
||||
@@ -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")
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record model="ir.ui.view" id="view_account_config_cash_basis_inherit_form">
|
||||
<field name="name">view.account.config.cash.basis.form.inherit</field>
|
||||
<field name="inherit_id" ref="account.view_account_config_settings"/>
|
||||
<field name="model">account.config.settings</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//p[@id='journal_config_message']" position="replace">
|
||||
<div>
|
||||
<label for="tax_cash_basis_journal_id"/>
|
||||
<field name="tax_cash_basis_journal_id" class="oe_inline"/>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
-14
@@ -14,19 +14,5 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_account_config_cash_basis_inherit_form">
|
||||
<field name="name">view.account.config.cash.basis.form.inherit</field>
|
||||
<field name="inherit_id" ref="account.view_account_config_settings"/>
|
||||
<field name="model">account.config.settings</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//p[@id='journal_config_message']" position="replace">
|
||||
<div>
|
||||
<label for="tax_cash_basis_journal_id"/>
|
||||
<field name="tax_cash_basis_journal_id" class="oe_inline"/>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user