credativ team mailing list archive
-
credativ team
-
Mailing list archive
-
Message #06142
[Branch ~credativ/openobject-addons/6.1] Rev 7070: [MERGE] Allow tax lines to have analytic accounts assigned
Merge authors:
Alexis de Lattre (alexis-via)
------------------------------------------------------------
revno: 7070 [merge]
committer: Craig Gowing (credativ) <craig.gowing@xxxxxxxxxxxxxx>
branch nick: addons
timestamp: Tue 2015-04-21 14:15:51 +0100
message:
[MERGE] Allow tax lines to have analytic accounts assigned
modified:
account/account.py
account/account_invoice.py
account/account_invoice_view.xml
account/account_view.xml
--
lp:~credativ/openobject-addons/6.1
https://code.launchpad.net/~credativ/openobject-addons/6.1
Your team credativ is subscribed to branch lp:~credativ/openobject-addons/6.1.
To unsubscribe from this branch go to https://code.launchpad.net/~credativ/openobject-addons/6.1/+edit-subscription
=== modified file 'account/account.py'
--- account/account.py 2013-12-02 14:34:04 +0000
+++ account/account.py 2015-04-21 13:15:51 +0000
@@ -1892,8 +1892,10 @@
'applicable_type': fields.selection( [('true','Always'), ('code','Given by Python Code')], 'Applicability', required=True,
help="If not applicable (computed through a Python code), the tax won't appear on the invoice."),
'domain':fields.char('Domain', size=32, help="This field is only used if you develop your own module allowing developers to create specific taxes in a custom domain."),
- 'account_collected_id':fields.many2one('account.account', 'Invoice Tax Account'),
- 'account_paid_id':fields.many2one('account.account', 'Refund Tax Account'),
+ 'account_collected_id':fields.many2one('account.account', 'Invoice Tax Account', help="Set the account that will be set by default on invoice tax lines for invoices. Leave empty to use the expense account."),
+ 'account_paid_id':fields.many2one('account.account', 'Refund Tax Account', help="Set the account that will be set by default on invoice tax lines for refunds. Leave empty to use the expense account."),
+ 'account_analytic_collected_id':fields.many2one('account.analytic.account', 'Invoice Tax Analytic Account', help="Set the analytic account that will be used by default on the invoice tax lines for invoices. Leave empty if you don't want to use an analytic account on the invoice tax lines by default."),
+ 'account_analytic_paid_id':fields.many2one('account.analytic.account', 'Refund Tax Analytic Account', help="Set the analytic account that will be used by default on the invoice tax lines for refunds. Leave empty if you don't want to use an analytic account on the invoice tax lines by default."),
'parent_id':fields.many2one('account.tax', 'Parent Tax Account', select=True),
'child_ids':fields.one2many('account.tax', 'parent_id', 'Child Tax Accounts'),
'child_depend':fields.boolean('Tax on Children', help="Set if the tax computation is based on the computation of child taxes rather than on the total amount."),
@@ -2033,6 +2035,8 @@
'name':tax.description and tax.description + " - " + tax.name or tax.name,
'account_collected_id':tax.account_collected_id.id,
'account_paid_id':tax.account_paid_id.id,
+ 'account_analytic_collected_id': tax.account_analytic_collected_id.id,
+ 'account_analytic_paid_id': tax.account_analytic_paid_id.id,
'base_code_id': tax.base_code_id.id,
'ref_base_code_id': tax.ref_base_code_id.id,
'sequence': tax.sequence,
@@ -2197,6 +2201,8 @@
'amount': amount,
'account_collected_id': tax.account_collected_id.id,
'account_paid_id': tax.account_paid_id.id,
+ 'account_analytic_collected_id': tax.account_analytic_collected_id.id,
+ 'account_analytic_paid_id': tax.account_analytic_paid_id.id,
'base_code_id': tax.base_code_id.id,
'ref_base_code_id': tax.ref_base_code_id.id,
'sequence': tax.sequence,
=== modified file 'account/account_invoice.py'
--- account/account_invoice.py 2013-06-05 15:27:45 +0000
+++ account/account_invoice.py 2015-04-21 13:15:51 +0000
@@ -735,7 +735,7 @@
for tax in inv.tax_line:
if tax.manual:
continue
- key = (tax.tax_code_id.id, tax.base_code_id.id, tax.account_id.id)
+ key = (tax.tax_code_id.id, tax.base_code_id.id, tax.account_id.id, tax.account_analytic_id.id)
tax_key.append(key)
if not key in compute_taxes:
raise osv.except_osv(_('Warning !'), _('Global taxes defined, but they are not in invoice lines !'))
@@ -850,7 +850,7 @@
raise osv.except_osv(_('Error !'), _("Can not create the invoice !\nThe related payment term is probably misconfigured as it gives a computed amount greater than the total invoiced amount. The latest line of your payment term must be of type 'balance' to avoid rounding issues."))
# one move line per tax line
- iml += ait_obj.move_line_get(cr, uid, inv.id)
+ iml += ait_obj._get_analytic_lines(cr, uid, inv.id)
entry_type = ''
if inv.type in ('in_invoice', 'in_refund'):
@@ -1543,6 +1543,7 @@
'invoice_id': fields.many2one('account.invoice', 'Invoice Line', ondelete='cascade', select=True),
'name': fields.char('Tax Description', size=64, required=True),
'account_id': fields.many2one('account.account', 'Tax Account', required=True, domain=[('type','<>','view'),('type','<>','income'), ('type', '<>', 'closed')]),
+ 'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic account'),
'base': fields.float('Base', digits_compute=dp.get_precision('Account')),
'amount': fields.float('Amount', digits_compute=dp.get_precision('Account')),
'manual': fields.boolean('Manual'),
@@ -1612,14 +1613,16 @@
val['base_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['base'] * tax['base_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')}, round=False)
val['tax_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['amount'] * tax['tax_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')}, round=False)
val['account_id'] = tax['account_collected_id'] or line.account_id.id
+ val['account_analytic_id'] = tax['account_analytic_collected_id']
else:
val['base_code_id'] = tax['ref_base_code_id']
val['tax_code_id'] = tax['ref_tax_code_id']
val['base_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['base'] * tax['ref_base_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')}, round=False)
val['tax_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['amount'] * tax['ref_tax_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')}, round=False)
val['account_id'] = tax['account_paid_id'] or line.account_id.id
+ val['account_analytic_id'] = tax['account_analytic_paid_id']
- key = (val['tax_code_id'], val['base_code_id'], val['account_id'])
+ key = (val['tax_code_id'], val['base_code_id'], val['account_id'], val['account_analytic_id'])
if not key in tax_grouped:
tax_grouped[key] = val
else:
@@ -1635,6 +1638,44 @@
t['tax_amount'] = cur_obj.round(cr, uid, cur, t['tax_amount'])
return tax_grouped
+
+ def _get_analytic_lines(self, cr, uid, id, context=None):
+ """Prepare the creation of tax account move lines and corresponding analytic lines.
+ It is the equivalent of the function with the same name on the object account_invoice
+ but for tax account move lines."""
+ if context is None:
+ context = {}
+ inv_obj = self.pool.get('account.invoice')
+ cur_obj = self.pool.get('res.currency')
+ inv = inv_obj.browse(cr, uid, id, context=context)
+
+ company_currency = inv.company_id.currency_id.id
+ if inv.type in ('out_invoice', 'in_refund'):
+ sign = 1
+ else:
+ sign = -1
+
+ tax_lines = self.pool.get('account.invoice.tax').move_line_get(cr, uid, inv.id)
+ for tl in tax_lines:
+ if tl['account_analytic_id']:
+ if inv.type in ('in_invoice', 'in_refund'):
+ ref = inv.reference
+ else:
+ ref = inv_obj._convert_ref(cr, uid, inv.number)
+ if not inv.journal_id.analytic_journal_id:
+ raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (inv.journal_id.name,))
+ tl['analytic_lines'] = [(0,0, {
+ 'name': tl['name'],
+ 'date': inv['date_invoice'],
+ 'account_id': tl['account_analytic_id'],
+ 'amount': cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, tl['tax_amount'], context={'date': inv.date_invoice}) * sign,
+ 'general_account_id': tl['account_id'],
+ 'journal_id': inv.journal_id.analytic_journal_id.id,
+ 'ref': ref,
+ })]
+ return tax_lines
+
+
def move_line_get(self, cr, uid, invoice_id):
res = []
cr.execute('SELECT * FROM account_invoice_tax WHERE invoice_id=%s', (invoice_id,))
@@ -1651,7 +1692,8 @@
'price': t['amount'] or 0.0,
'account_id': t['account_id'],
'tax_code_id': t['tax_code_id'],
- 'tax_amount': t['tax_amount']
+ 'tax_amount': t['tax_amount'],
+ 'account_analytic_id': t['account_analytic_id'],
})
return res
=== modified file 'account/account_invoice_view.xml'
--- account/account_invoice_view.xml 2012-02-16 18:50:48 +0000
+++ account/account_invoice_view.xml 2015-04-21 13:15:51 +0000
@@ -96,6 +96,7 @@
<field name="name"/>
<field name="sequence"/>
<field name="account_id"/>
+ <field name="account_analytic_id" domain="[('type','<>','view'), ('company_id', '=', parent.company_id), ('parent_id', '!=', False)]" groups="analytic.group_analytic_accounting" />
<field name="manual"/>
<field name="amount"/>
<field name="base" readonly="0"/>
@@ -187,6 +188,7 @@
<tree editable="bottom" string="Taxes">
<field name="name"/>
<field name="account_id" groups="account.group_account_invoice"/>
+ <field name="account_analytic_id" domain="[('type','<>','view'), ('company_id', '=', parent.company_id), ('parent_id', '!=', False)]" groups="analytic.group_analytic_accounting" />
<field name="base" on_change="base_change(base,parent.currency_id,parent.company_id,parent.date_invoice)" readonly="1"/>
<field name="amount" on_change="amount_change(amount,parent.currency_id,parent.company_id,parent.date_invoice)"/>
=== modified file 'account/account_view.xml'
--- account/account_view.xml 2013-06-21 12:29:40 +0000
+++ account/account_view.xml 2015-04-21 13:15:51 +0000
@@ -979,9 +979,9 @@
<field name="amount" attrs="{'readonly':[('type','in',('none', 'code', 'balance'))]}"/>
<separator colspan="4" string="Accounting Information"/>
<field name="account_collected_id" domain="[('type','<>','view'),('type','<>','consolidation')]"/>
- <label colspan="2" nolabel="1" string="Keep empty to use the income account"/>
+ <field name="account_analytic_collected_id" domain="[('type','<>','view'), ('company_id', '=', company_id), ('parent_id', '<>', False)]" groups="analytic.group_analytic_accounting" />
<field name="account_paid_id" domain="[('type','<>','view'),('type','<>','consolidation')]"/>
- <label colspan="2" nolabel="1" string="Keep empty to use the expense account"/>
+ <field name="account_analytic_paid_id" domain="[('type','<>','view'), ('company_id', '=', company_id), ('parent_id', '<>', False)]" groups="analytic.group_analytic_accounting" />
<separator colspan="4" string="Tax Declaration: Invoices"/>
<field name="base_code_id"/>
<field name="base_sign"/>