[ADD] account: add tax_group on invoice to make reporting easier + create tax_group retention for l10n_co
This commit is contained in:
committed by
Cedric Snauwaert
parent
638db1f085
commit
d861cdc1c4
@@ -172,5 +172,11 @@
|
||||
<field name="padding">4</field>
|
||||
</record>
|
||||
|
||||
<!-- Account Tax Group -->
|
||||
<record id="tax_group_taxes" model="account.tax.group">
|
||||
<field name="name">Taxes</field>
|
||||
<field name="sequence">0</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -429,6 +429,10 @@ class AccountTax(models.Model):
|
||||
_description = 'Tax'
|
||||
_order = 'sequence'
|
||||
|
||||
@api.model
|
||||
def _default_tax_group(self):
|
||||
return self.env['account.tax.group'].search([], limit=1)
|
||||
|
||||
name = fields.Char(string='Tax Name', required=True, translate=True)
|
||||
type_tax_use = fields.Selection([('sale', 'Sales'), ('purchase', 'Purchases'), ('none', 'None')], string='Tax Scope', required=True, default="sale",
|
||||
help="Determines where the tax is selectable. Note : 'None' means a tax can't be used by itself, however it can still be used in a group.")
|
||||
@@ -451,6 +455,7 @@ class AccountTax(models.Model):
|
||||
help="If set, taxes which are computed after this one will be computed based on the price tax included.")
|
||||
analytic = fields.Boolean(string="Include in Analytic Cost", help="If set, the amount computed by this tax will be assigned to the same analytic account as the invoice line (if any)")
|
||||
tag_ids = fields.Many2many('account.account.tag', 'account_tax_account_tag', string='Tags', help="Optional tags you may want to assign for custom reporting")
|
||||
tax_group_id = fields.Many2one('account.tax.group', string="Tax Group", default=_default_tax_group, required=True)
|
||||
|
||||
_sql_constraints = [
|
||||
('name_company_uniq', 'unique(name, company_id)', 'Tax names must be unique !'),
|
||||
@@ -649,3 +654,11 @@ class AccountOperationTemplate(models.Model):
|
||||
@api.onchange('name')
|
||||
def onchange_name(self):
|
||||
self.label = self.name
|
||||
|
||||
|
||||
class AccountTaxGroup(models.Model):
|
||||
_name = 'account.tax.group'
|
||||
_order = 'sequence asc'
|
||||
|
||||
name = fields.Char(required=True, translate=True)
|
||||
sequence = fields.Integer(default=10)
|
||||
|
||||
@@ -7,6 +7,7 @@ from dateutil.relativedelta import relativedelta
|
||||
|
||||
from openerp import api, fields, models, _
|
||||
from openerp.tools import float_is_zero
|
||||
from openerp.tools.misc import formatLang
|
||||
|
||||
from openerp.exceptions import UserError, RedirectWarning
|
||||
|
||||
@@ -949,6 +950,18 @@ class AccountInvoice(models.Model):
|
||||
return 'account.mt_invoice_created'
|
||||
return super(AccountInvoice, self)._track_subtype(init_values)
|
||||
|
||||
@api.multi
|
||||
def _get_tax_amount_by_group(self):
|
||||
self.ensure_one()
|
||||
res = {}
|
||||
currency = self.currency_id or self.company_id.currency_id
|
||||
for line in self.tax_line_ids:
|
||||
res.setdefault(line.tax_id.tax_group_id, 0.0)
|
||||
res[line.tax_id.tax_group_id] += line.amount
|
||||
res = sorted(res.items(), key=lambda l: l[0].sequence)
|
||||
res = map(lambda l: (l[0].name, formatLang(self.env, l[1], currency_obj=currency)), res)
|
||||
return res
|
||||
|
||||
|
||||
class AccountInvoiceLine(models.Model):
|
||||
_name = "account.invoice.line"
|
||||
|
||||
@@ -73,3 +73,7 @@ access_account_payment_method,account.payment.method,model_account_payment_metho
|
||||
access_account_payment,account.payment,model_account_payment,account.group_account_invoice,1,1,1,1
|
||||
access_account_cashbox,account.bank.statement.cashbox,model_account_bank_statement_cashbox,account.group_account_user,1,1,1,1
|
||||
access_account_cashbox_line,account.bank.statement.cashbox.line,model_account_cashbox_line,account.group_account_user,1,1,1,1
|
||||
access_account_tax_group_internal_user,account.tax.group internal user,model_account_tax_group,base.group_user,1,0,0,0
|
||||
access_account_tax_group,account.tax.group,model_account_tax_group,account.group_account_invoice,1,0,0,0
|
||||
access_account_tax_group_manager,account.tax.group,model_account_tax_group,account.group_account_manager,1,1,1,1
|
||||
access_account_tax_group_sale_manager,account.tax.group sale manager,model_account_tax_group,base.group_sale_salesman,1,0,0,0
|
||||
|
||||
|
@@ -848,8 +848,9 @@
|
||||
<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'))]}">
|
||||
<group attrs="{'invisible':[('amount_type','=', 'group')]}">
|
||||
<field name="account_id"/>
|
||||
<field name="refund_account_id"/>
|
||||
</group>
|
||||
@@ -882,6 +883,7 @@
|
||||
<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"/>
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
<span t-field="l.discount"/>
|
||||
</td>
|
||||
<td>
|
||||
<span t-esc="', '.join(map(lambda x: x.description, l.invoice_line_tax_ids))"/>
|
||||
<span t-esc="', '.join(map(lambda x: (x.description or x.name), l.invoice_line_tax_ids))"/>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<span t-field="l.price_subtotal"
|
||||
@@ -98,12 +98,14 @@
|
||||
<span t-field="o.amount_untaxed" t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Taxes</td>
|
||||
<td class="text-right">
|
||||
<span t-field="o.amount_tax" t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
|
||||
</td>
|
||||
</tr>
|
||||
<t t-foreach="o._get_tax_amount_by_group()" t-as="amount_by_group">
|
||||
<tr>
|
||||
<td><span t-esc="amount_by_group[0]"/></td>
|
||||
<td class="text-right">
|
||||
<span t-esc="amount_by_group[1]"/>
|
||||
</td>
|
||||
</tr>
|
||||
</t>
|
||||
<tr class="border-black">
|
||||
<td><strong>Total</strong></td>
|
||||
<td class="text-right">
|
||||
@@ -114,28 +116,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" t-if="o.tax_line_ids">
|
||||
<div class="col-xs-6">
|
||||
<table class="table table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tax</th>
|
||||
<th class="text-right">Amount</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr t-foreach="o.tax_line_ids" t-as="t">
|
||||
<td><span t-field="t.tax_id.description"/></td>
|
||||
<td class="text-right">
|
||||
<span t-field="t.amount"
|
||||
t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p t-if="o.comment">
|
||||
<strong>Comment:</strong>
|
||||
<span t-field="o.comment"/>
|
||||
|
||||
@@ -12,12 +12,14 @@ class AccountTaxPython(models.Model):
|
||||
":param base_amount: float, actual amount on which the tax is applied\n"
|
||||
":param price_unit: float\n"
|
||||
":param quantity: float\n"
|
||||
":param company: res.company recordset singleton\n"
|
||||
":param product: product.product recordset singleton or None\n"
|
||||
":param partner: res.partner recordset singleton or None")
|
||||
python_applicable = fields.Text(string='Applicable Code', default="result = True",
|
||||
help="Determine if the tax will be applied by setting the variable 'result' to True or False.\n\n"
|
||||
":param price_unit: float\n"
|
||||
":param quantity: float\n"
|
||||
":param company: res.company recordset singleton\n"
|
||||
":param product: product.product recordset singleton or None\n"
|
||||
":param partner: res.partner recordset singleton or None")
|
||||
|
||||
@@ -25,7 +27,8 @@ class AccountTaxPython(models.Model):
|
||||
def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None):
|
||||
self.ensure_one()
|
||||
if self.amount_type == 'code':
|
||||
localdict = {'base_amount': base_amount, 'price_unit':price_unit, 'quantity': quantity, 'product':product, 'partner':partner}
|
||||
company = self.env.user.company_id
|
||||
localdict = {'base_amount': base_amount, 'price_unit':price_unit, 'quantity': quantity, 'product':product, 'partner':partner, 'company': company}
|
||||
exec self.python_compute in localdict
|
||||
return localdict['result']
|
||||
return super(AccountTaxPython, self)._compute_amount(base_amount, price_unit, quantity, product, partner)
|
||||
@@ -33,8 +36,9 @@ class AccountTaxPython(models.Model):
|
||||
@api.v8
|
||||
def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None):
|
||||
taxes = self.env['account.tax']
|
||||
company = self.env.user.company_id
|
||||
for tax in self:
|
||||
localdict = {'price_unit':price_unit, 'quantity': quantity, 'product':product, 'partner':partner}
|
||||
localdict = {'price_unit':price_unit, 'quantity': quantity, 'product':product, 'partner':partner, 'company': company}
|
||||
exec tax.python_applicable in localdict
|
||||
if localdict.get('result', False):
|
||||
taxes += tax
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
'data/account.account.template.csv',
|
||||
'data/account_chart_template.xml',
|
||||
'data/account.tax.template.csv',
|
||||
'data/account_tax_group.xml',
|
||||
'data/account_chart_template.yml',
|
||||
],
|
||||
'demo': [],
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="tax_group_retention" model="account.tax.group">
|
||||
<field name="name">Retention</field>
|
||||
<field name="sequence">10</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user