[ADD] account_tax_cash_basis module

This commit is contained in:
Cédric Snauwaert
2015-09-02 14:53:38 +02:00
committed by qdp-odoo
parent 87ab8eadb1
commit fb1c52778d
8 changed files with 180 additions and 46 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ class AccountMove(models.Model):
for partial_line in (line.matched_debit_ids + line.matched_credit_ids):
total_reconciled += partial_line.amount
if total_amount == 0.0:
move.matched_percentage = 100.0
move.matched_percentage = 1.0
else:
move.matched_percentage = total_reconciled / total_amount
+2
View File
@@ -84,6 +84,8 @@ class AccountConfigSettings(models.TransientModel):
'Once the master budgets and the budgets are defined, '
'the project managers can set the planned amount on each analytic account.\n'
'-This installs the module account_budget.')
module_account_tax_cash_basis = fields.Boolean(string="Allow Tax Cash Basis",
help='Generate tax cash basis entrie when reconciliating entries')
group_proforma_invoices = fields.Boolean(string='Allow pro-forma invoices',
implied_group='account.group_proforma_invoices',
help="Allows you to put invoices in pro-forma state.")
+1 -45
View File
@@ -925,50 +925,6 @@
<field name="amount_type" />
<field name="amount" />
</tree>
<form string="Account Tax">
<group>
<group>
<field name="name"/>
</group>
<group>
<field name="type_tax_use"/>
</group>
</group>
<notebook>
<page string="Definition">
<group>
<group>
<field name="amount_type" />
<label for="amount" attrs="{'invisible':[('amount_type','not in', ('fixed', 'percent', 'division'))]}"/>
<div attrs="{'invisible':[('amount_type','not in', ('fixed', 'percent', 'division'))]}">
<field name="amount" class="oe_inline" />
<label string="%" class="oe_inline" attrs="{'invisible':[('amount_type','=','fixed')]}" />
</div>
<field name="tax_group_id"/>
</group>
<group attrs="{'invisible':[('amount_type','not in', ('fixed', 'percent', 'division'))]}">
<field name="account_id"/>
<field name="refund_account_id"/>
</group>
</group>
</page>
<page string="Advanced Options">
<group>
<group>
<field name="description" attrs="{'invisible':[('amount_type','=', 'group')]}"/>
<field name="tag_ids" domain="[('applicability', '!=', 'accounts')]" widget="many2many_tags" context="{'default_applicability': 'taxes'}"/>
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
<field name="active" groups="base.group_no_one"/>
</group>
<group>
<field name="price_include" attrs="{'invisible':[('amount_type','=', 'group')]}" />
<field name="include_base_amount" attrs="{'invisible':[('amount_type','=', 'group')]}" />
<field name="analytic" attrs="{'invisible':[('amount_type','=', 'group')]}" groups="analytic.group_analytic_accounting" />
</group>
</group>
</page>
</notebook>
</form>
</field>
</page>
<page string="Advanced Options">
@@ -981,7 +937,7 @@
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
<field name="active" groups="base.group_no_one"/>
</group>
<group>
<group name="advanced_booleans">
<field name="price_include" attrs="{'invisible':[('amount_type','=', 'group')]}" />
<field name="include_base_amount" attrs="{'invisible':[('amount_type','=', 'group')]}" />
</group>
+4
View File
@@ -131,6 +131,10 @@
<field name="module_account_budget" class="oe_inline"/>
<label for="module_account_budget"/>
</div>
<div>
<field name="module_account_tax_cash_basis" class="oe_inline"/>
<label for="module_account_tax_cash_basis" />
</div>
</div>
</group>
<separator string="eInvoicing &amp; Payments"/>
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import tax_cash_basis
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name' : 'Account Tax Cash Basis',
'version' : '1.1',
'author' : 'OpenERP SA',
'summary': 'Allow to have cash basis on tax',
'sequence': 4,
'description': """
Add an option on tax to allow them to be cash based, meaning that during reconciliation, if there is a tax with
cash basis involved, a new journal entry will be create containing those taxes value.
""",
'category' : 'Accounting & Finance',
'website': 'https://www.odoo.com/page/accounting',
'depends' : ['account'],
'data': [
'views/tax_cash_basis_view.xml',
],
'installable': True,
'auto_install': False,
}
@@ -0,0 +1,115 @@
# -*- coding: utf-8 -*-
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")
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
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
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
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
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():
line_to_create.append((0, 0, {
'name': '/',
'debit': v if v > 0 else 0.0,
'credit': abs(v) if v < 0 else 0.0,
'account_id': k,
}))
#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,
'credit': v if v > 0 else 0.0,
'account_id': k,
}))
#Create move
if len(line_to_create) > 0:
#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') % \
(self.company_id.name))
move = self.env['account.move'].create({
'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
move.post()
@api.model
def create(self, vals):
aml = []
if vals.get('debit_move_id', False):
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
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
res = super(AccountPartialReconcileCashBasis, self).create(vals)
#eventually create a tax cash basis entry
res.create_tax_cash_basis_entry(value_before_reconciliation)
return res
@api.multi
def unlink(self):
move = self.env['account.move'].search([('tax_cash_basis_rec_id', 'in', self._ids)])
move.reverse_moves()
super(AccountPartialReconcileCashBasis, self).unlink()
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_tax_form_cash_basis_inherit" model="ir.ui.view">
<field name="name">tax.form.cash.basis.inherit</field>
<field name="model">account.tax</field>
<field name="inherit_id" ref="account.view_tax_form"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='advanced_booleans']" position="inside">
<field name="use_cash_basis" attrs="{'invisible':[('amount_type','=', 'group')]}"/>
<field name="cash_basis_account" attrs="{'invisible': [('use_cash_basis', '=', False)], 'required': [('use_cash_basis', '=', True)]}"/>
</xpath>
</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="//div[@name='account_config']/div[last()]" position="after">
<div>
<label for="tax_cash_basis_journal_id"/>
<field name="tax_cash_basis_journal_id" class="oe_inline"/>
</div>
</xpath>
</field>
</record>
</data>
</openerp>