openobject-italia-core-devs team mailing list archive
-
openobject-italia-core-devs team
-
Mailing list archive
-
Message #00757
lp:~openobject-italia-core-devs/openobject-italia/l10n_it_vat_registries_fix_845359 into lp:openobject-italia
Lorenzo Battistini - Agile BG - Domsense has proposed merging lp:~openobject-italia-core-devs/openobject-italia/l10n_it_vat_registries_fix_845359 into lp:openobject-italia.
Requested reviews:
OpenERP Italia core devs (openobject-italia-core-devs)
Related bugs:
Bug #845359 in OpenERP Italia: "raggruppo giornaliero su reg. iva corrispettivi"
https://bugs.launchpad.net/openobject-italia/+bug/845359
For more details, see:
https://code.launchpad.net/~openobject-italia-core-devs/openobject-italia/l10n_it_vat_registries_fix_845359/+merge/82646
--
https://code.launchpad.net/~openobject-italia-core-devs/openobject-italia/l10n_it_vat_registries_fix_845359/+merge/82646
Your team OpenERP Italia core devs is requested to review the proposed merge of lp:~openobject-italia-core-devs/openobject-italia/l10n_it_vat_registries_fix_845359 into lp:openobject-italia.
=== modified file 'l10n_it_vat_registries/__openerp__.py'
--- l10n_it_vat_registries/__openerp__.py 2011-11-05 14:09:17 +0000
+++ l10n_it_vat_registries/__openerp__.py 2011-11-18 08:55:27 +0000
@@ -27,7 +27,7 @@
'author': 'OpenERP Italian Community',
'website': 'http://www.openerp-italia.org',
'license': 'AGPL-3',
- "depends" : ['l10n_it_base', 'report_webkit', 'l10n_it_account', 'l10n_it_corrispettivi', 'account_invoice_tax_by_column'],
+ "depends" : ['report_webkit', 'l10n_it_account', 'account_invoice_tax_by_column', 'l10n_it_partially_deductible_vat'],
"init_xml" : [
],
"update_xml" : [
=== modified file 'l10n_it_vat_registries/account.py'
--- l10n_it_vat_registries/account.py 2011-11-05 14:09:17 +0000
+++ l10n_it_vat_registries/account.py 2011-11-18 08:55:27 +0000
@@ -37,7 +37,7 @@
_inherit = 'account.tax'
_columns = {
'exclude_from_registries': fields.boolean('Exclude from VAT registries'),
- 'base_tax_ids': fields.one2many('account.tax', 'base_code_id', 'Base Taxes'),
+ 'base_tax_ids': fields.one2many('account.tax', 'base_code_id', 'Base Taxes'), # serve ancora?
}
_sql_constraints = [
('name_uniq', 'UNIQUE(name)', 'The tax name must be unique!'),
=== modified file 'l10n_it_vat_registries/invoice.py'
--- l10n_it_vat_registries/invoice.py 2011-11-06 11:25:21 +0000
+++ l10n_it_vat_registries/invoice.py 2011-11-18 08:55:27 +0000
@@ -30,9 +30,18 @@
class Parser(report_sxw.rml_parse):
logger = netsvc.Logger()
+
+ def _move_total(self, move_line):
+ if not move_line.credit:
+ for line in move_line.move_id.line_id:
+ if line.credit:
+ return line.credit
+ elif not move_line.debit:
+ for line in move_line.move_id.line_id:
+ if line.debit:
+ return line.debit
- # TODO verificare multi valuta
- def _get_tax_lines(self, invoice):
+ def _get_tax_lines(self, move):
res=[]
tax_obj = self.pool.get('account.tax')
# index è usato per non ripetere la stampa dei dati fattura quando ci sono più codici IVA
@@ -41,62 +50,41 @@
totale_iva_inded = 0.0
invoice_amount_total = 0.0
invoice_amount_untaxed = 0.0
- precision = self.pool.get('decimal.precision').precision_get(self.cr, self.uid, 'Account')
- for inv_tax in invoice.tax_line:
+ for move_line in move.line_id:
tax_item = {}
- if inv_tax.base_code_id and inv_tax.tax_code_id:
- account_tax = tax_obj.get_account_tax(self.cr, self.uid, inv_tax.name)
- if account_tax.exclude_from_registries:
- self.logger.notifyChannel("l10n_it_vat_registries", netsvc.LOG_INFO,
- _('The tax %s is excluded from registries') % account_tax.name)
- continue
- account_tax_amount = account_tax.amount
+ if move_line.tax_code_id and move_line.tax_code_id.tax_ids:
+ main_tax = tax_obj.get_main_tax(move_line.tax_code_id.tax_ids[0])
+ # sommo gli imponibili relativi all'imposta corrente
+ base_amount = 0.0
+ for line in move_line.move_id.line_id:
+ if line.tax_code_id.id == main_tax.base_code_id.id:
+ base_amount += line.tax_amount
+ # calcolo % indetraibile
+ actual_tax_amount = base_amount * main_tax.amount
+ non_deductible = 0.0
+ if actual_tax_amount != move_line.tax_amount:
+ non_deductible = 100
+ if move_line.tax_amount:
+ non_deductible = 100 - abs((move_line.tax_amount * 100.0) / actual_tax_amount)
+ # calcolo il totale dell'operazione
+ invoice_amount_total = self._move_total(move_line)
+ if base_amount < 0:
+ invoice_amount_total = - invoice_amount_total
tax_item = {
- 'tax_percentage': account_tax_amount and str(
- account_tax_amount * 100).split('.')[0] or inv_tax.tax_code_id.name,
- 'base': inv_tax.base,
- 'amount': inv_tax.amount,
- 'non_deductible': 0.0,
+ 'tax_percentage': main_tax.amount and str(
+ main_tax.amount * 100).split('.')[0] or move_line.tax_code_id.name,
+ 'base': base_amount,
+ 'amount': actual_tax_amount,
+ 'non_deductible': non_deductible and str(non_deductible).split('.')[0] or '',
'index': index,
+ 'amount_total': invoice_amount_total,
}
res.append(tax_item)
- totale_iva += inv_tax.amount
- invoice_amount_total = invoice.amount_total
- invoice_amount_untaxed = invoice.amount_untaxed
+ totale_iva += actual_tax_amount * (100 - non_deductible) * 0.01
+ invoice_amount_untaxed += base_amount
+ totale_iva_inded += actual_tax_amount * non_deductible * 0.01
index += 1
- # Se non c'è il tax code imponibile, cerco la tassa relativa alla parte non deducibile
- elif inv_tax.tax_code_id:
- tax = tax_obj.get_main_tax(tax_obj.get_account_tax(self.cr, self.uid, inv_tax.name))
- if tax.exclude_from_registries:
- self.logger.notifyChannel("l10n_it_vat_registries", netsvc.LOG_INFO,
- _('The tax %s is excluded from registries') % tax.name)
- continue
- for inv_tax_2 in invoice.tax_line:
- if inv_tax_2.base_code_id and not inv_tax_2.tax_code_id:
- base_tax = tax_obj.get_main_tax(tax_obj.get_account_tax(self.cr, self.uid, inv_tax_2.name))
- # Se hanno la stessa tassa
- if base_tax.id == tax.id:
- # TODO verificare se si può evitare Decimal
- tax_item = {
- 'tax_percentage': base_tax.amount and str(
- base_tax.amount * 100).split('.')[0] or inv_tax.tax_code_id.name,
- 'base': inv_tax.base + inv_tax_2.base,
- 'amount': inv_tax.amount + inv_tax_2.amount,
- 'non_deductible': float(Decimal(str(inv_tax_2.base / (inv_tax.base + inv_tax_2.base) * 100)
- ).quantize(Decimal('.1'), rounding=ROUND_HALF_UP)),
- 'index': index,
- }
- res.append(tax_item)
- totale_iva += inv_tax.amount
- totale_iva_inded += inv_tax_2.amount
- invoice_amount_total = invoice.amount_total
- invoice_amount_untaxed = invoice.amount_untaxed
- index += 1
- break
- elif not inv_tax.tax_code_id and not inv_tax.base_code_id:
- self.logger.notifyChannel("l10n_it_vat_registries", netsvc.LOG_INFO,
- _('The tax %s has no tax codes') % inv_tax.name)
- continue
+
if tax_item:
if tax_item['tax_percentage'] not in self.localcontext['tax_codes']:
self.localcontext['tax_codes'][tax_item['tax_percentage']] = {
=== modified file 'l10n_it_vat_registries/reports.xml'
--- l10n_it_vat_registries/reports.xml 2011-10-28 11:39:52 +0000
+++ l10n_it_vat_registries/reports.xml 2011-11-18 08:55:27 +0000
@@ -83,7 +83,7 @@
<record id="registro_iva_vendite_report_id" model="ir.actions.report.xml">
<field name="name">Customer Invoices VAT Registry</field>
<field name="type">ir.actions.report.xml</field>
- <field name="model">account.invoice</field>
+ <field name="model">account.move</field>
<field name="report_name">registro_iva_vendite</field>
<field name="report_type">webkit</field>
<field name="report_rml">l10n_it_vat_registries/templates/registro_iva_vendite.mako</field>
@@ -92,7 +92,7 @@
<record id="registro_iva_acquisti_report_id" model="ir.actions.report.xml">
<field name="name">Supplier Invoices VAT Registry</field>
<field name="type">ir.actions.report.xml</field>
- <field name="model">account.invoice</field>
+ <field name="model">account.move</field>
<field name="report_name">registro_iva_acquisti</field>
<field name="report_type">webkit</field>
<field name="report_rml">l10n_it_vat_registries/templates/registro_iva_acquisti.mako</field>
@@ -101,7 +101,7 @@
<record id="registro_iva_corrispettivi_report_id" model="ir.actions.report.xml">
<field name="name">Corrispettivi VAT Registry</field>
<field name="type">ir.actions.report.xml</field>
- <field name="model">account.invoice</field>
+ <field name="model">account.move</field>
<field name="report_name">registro_iva_corrispettivi</field>
<field name="report_type">webkit</field>
<field name="report_rml">l10n_it_vat_registries/templates/registro_iva_corrispettivi.mako</field>
=== modified file 'l10n_it_vat_registries/templates/registro_iva_acquisti.mako'
--- l10n_it_vat_registries/templates/registro_iva_acquisti.mako 2011-08-06 10:23:30 +0000
+++ l10n_it_vat_registries/templates/registro_iva_acquisti.mako 2011-11-18 08:55:27 +0000
@@ -10,7 +10,6 @@
<table style="width:100%;">
<thead>
<tr>
- <th style="text-align:left">Data registrazione</th>
<th style="text-align:left">Data fattura</th>
<th style="text-align:left">Numero fattura</th>
<th style="text-align:left">Ragione sociale</th>
@@ -27,16 +26,12 @@
%for object in objects :
%for line in tax_lines(object) :
<tr><td>
- %if line['index']==0:
- ${ formatLang(object.move_id.date,date=True) or ''| entity}
- %endif
- </td><td>
- %if line['index']==0:
- ${ formatLang(object.date_invoice,date=True) or '' | entity}
- %endif
- </td><td>
- %if line['index']==0:
- ${object.number or ''| entity}
+ %if line['index']==0:
+ ${ formatLang(object.date,date=True) or '' | entity}
+ %endif
+ </td><td>
+ %if line['index']==0:
+ ${object.name or ''| entity}
%endif
</td><td>
%if line['index']==0:
@@ -44,20 +39,20 @@
%endif
</td><td>
%if line['index']==0:
- %if object.type == 'in_invoice':
+ %if line['base'] > 0:
Fattura
- %elif object.type == 'in_refund':
- Nota di debito
+ %else:
+ Nota di credito
%endif
%endif
</td><td style="text-align:right">
%if line['index']==0:
- ${ object.amount_total | entity}
+ ${ formatLang(line['amount_total']) | entity}
%endif
</td>
<td style="text-align:right">${ line['tax_percentage'] or ''| entity}</td>
- <td style="text-align:right">${ line['base'] or ''| entity}</td>
- <td style="text-align:right">${ line['amount'] or ''| entity}</td>
+ <td style="text-align:right">${ formatLang(line['base']) or ''| entity}</td>
+ <td style="text-align:right">${ formatLang(line['amount']) or ''| entity}</td>
<td style="text-align:right">
%if line['non_deductible']:
${ line['non_deductible'] | entity} %
=== modified file 'l10n_it_vat_registries/templates/registro_iva_corrispettivi.mako'
--- l10n_it_vat_registries/templates/registro_iva_corrispettivi.mako 2011-08-06 10:24:46 +0000
+++ l10n_it_vat_registries/templates/registro_iva_corrispettivi.mako 2011-11-18 08:55:27 +0000
@@ -24,7 +24,7 @@
%for line in tax_lines(object) :
<tr><td>
%if line['index']==0:
- ${ formatLang(object.move_id.date,date=True) or ''| entity}
+ ${ formatLang(object.date,date=True) or ''| entity}
%endif
</td><td>
%if line['index']==0:
@@ -32,12 +32,12 @@
%endif
</td><td style="text-align:right">
%if line['index']==0:
- ${ object.amount_total | entity}
+ ${ formatLang(line['amount_total']) | entity}
%endif
</td>
<td style="text-align:right">${ line['tax_percentage'] or ''| entity}</td>
- <td style="text-align:right">${ line['base'] or ''| entity}</td>
- <td style="text-align:right">${ line['amount'] or ''| entity}</td>
+ <td style="text-align:right">${ formatLang(line['base']) or ''| entity}</td>
+ <td style="text-align:right">${ formatLang(line['amount']) or ''| entity}</td>
<td></td>
</tr>
%endfor
=== modified file 'l10n_it_vat_registries/templates/registro_iva_vendite.mako'
--- l10n_it_vat_registries/templates/registro_iva_vendite.mako 2011-08-06 10:23:30 +0000
+++ l10n_it_vat_registries/templates/registro_iva_vendite.mako 2011-11-18 08:55:27 +0000
@@ -10,7 +10,6 @@
<table style="width:100%;">
<thead>
<tr>
- <th style="text-align:left">Data registrazione</th>
<th style="text-align:left">Data fattura</th>
<th style="text-align:left">Numero fattura</th>
<th style="text-align:left">Ragione sociale</th>
@@ -26,16 +25,12 @@
%for object in objects :
%for line in tax_lines(object) :
<tr><td>
- %if line['index']==0:
- ${ formatLang(object.move_id.date,date=True) or ''| entity}
- %endif
- </td><td>
- %if line['index']==0:
- ${ formatLang(object.date_invoice,date=True) or '' | entity}
- %endif
- </td><td>
- %if line['index']==0:
- ${object.number or ''| entity}
+ %if line['index']==0:
+ ${ formatLang(object.date,date=True) or '' | entity}
+ %endif
+ </td><td>
+ %if line['index']==0:
+ ${object.name or ''| entity}
%endif
</td><td>
%if line['index']==0:
@@ -43,20 +38,20 @@
%endif
</td><td>
%if line['index']==0:
- %if object.type == 'out_invoice':
+ %if line['base'] > 0:
Fattura
- %elif object.type == 'out_refund':
+ %else:
Nota di credito
%endif
%endif
</td><td style="text-align:right">
%if line['index']==0:
- ${ object.amount_total | entity}
+ ${ formatLang(line['amount_total']) | entity}
%endif
</td>
<td style="text-align:right">${ line['tax_percentage'] or ''| entity}</td>
- <td style="text-align:right">${ line['base'] or ''| entity}</td>
- <td style="text-align:right">${ line['amount'] or ''| entity}</td>
+ <td style="text-align:right">${ formatLang(line['base']) or ''| entity}</td>
+ <td style="text-align:right">${ formatLang(line['amount']) or ''| entity}</td>
<td></td>
</tr>
%endfor
=== modified file 'l10n_it_vat_registries/wizard/print_registro_iva.py'
--- l10n_it_vat_registries/wizard/print_registro_iva.py 2011-08-19 13:08:24 +0000
+++ l10n_it_vat_registries/wizard/print_registro_iva.py 2011-11-18 08:55:27 +0000
@@ -44,61 +44,55 @@
'date_to': lambda * a: time.strftime('%Y-%m-%d'),
'journal_ids': lambda s, cr, uid, c: s.pool.get('account.journal').search(cr, uid, []),
}
+
+ def counterparts_number(self, move_line):
+ counter = 0
+ if not move_line.credit:
+ for line in move_line.move_id.line_id:
+ if line.credit:
+ counter += 1
+ elif not move_line.debit:
+ for line in move_line.move_id.line_id:
+ if line.debit:
+ counter += 1
+ return counter
def print_registro(self, cr, uid, ids, context=None):
- inv_ids = []
+ move_ids = []
wizard = self.read(cr, uid, ids)[0]
- inv_obj = self.pool.get('account.invoice')
+ move_line_obj = self.pool.get('account.move.line')
search_list = []
- if wizard['type'] == 'customer':
- search_list = [
- ('journal_id', 'in', wizard['journal_ids']),
- ('corrispettivo', '=', False),
- ('move_id.date', '<=', wizard['date_to']),
- ('move_id.date', '>=', wizard['date_from']),
- '|',
- ('type', '=', 'out_invoice'),
- ('type', '=', 'out_refund'),
- '|',
- ('state', '=', 'open'),
- ('state', '=', 'paid'),
- ]
- elif wizard['type'] == 'supplier':
- search_list = [
- ('journal_id', 'in', wizard['journal_ids']),
- ('corrispettivo', '=', False),
- ('move_id.date', '<=', wizard['date_to']),
- ('move_id.date', '>=', wizard['date_from']),
- '|',
- ('type', '=', 'in_invoice'),
- ('type', '=', 'in_refund'),
- '|',
- ('state', '=', 'open'),
- ('state', '=', 'paid'),
- ]
- elif wizard['type'] == 'corrispettivi':
- search_list = [
- ('journal_id', 'in', wizard['journal_ids']),
- ('corrispettivo', '=', True),
- ('move_id.date', '<=', wizard['date_to']),
- ('move_id.date', '>=', wizard['date_from']),
- '|',
- ('type', '=', 'out_invoice'),
- ('type', '=', 'out_refund'),
- '|',
- ('state', '=', 'open'),
- ('state', '=', 'paid'),
- ]
- inv_ids = inv_obj.search(cr, uid, search_list)
- if not inv_ids:
+ search_list = [
+ ('journal_id', 'in', wizard['journal_ids']),
+ ('move_id.date', '<=', wizard['date_to']),
+ ('move_id.date', '>=', wizard['date_from']),
+ ('move_id.state', '=', 'posted'),
+ ('tax_code_id', '!=', False),
+ ]
+ move_line_ids = move_line_obj.search(cr, uid, search_list, order='date')
+ if not move_line_ids:
self.write(cr, uid, ids, {'message': _('No documents found in the current selection')})
return True
if context is None:
context = {}
- datas = {'ids': inv_ids}
- datas['model'] = 'account.invoice'
+ for move_line in move_line_obj.browse(cr, uid, move_line_ids):
+ if move_line.tax_code_id.tax_ids:
+ # controllo che ogni tax code abbia una e una sola imposta
+ ''' non posso farlo per via dell IVA inclusa nel prezzo
+ if len(move_line.tax_code_id.tax_ids) != 1:
+ raise osv.except_osv(_('Error'), _('Wrong tax configuration for tax code %s')
+ % move_line.tax_code_id.name)
+ '''
+ # controllo che ci sia una sola riga di debito o credito
+ if self.counterparts_number(move_line) != 1:
+ raise osv.except_osv(_('Error'), _('Wrong counterparts number for move %s')
+ % move_line.move_id.name)
+ if move_line.move_id.id not in move_ids:
+ move_ids.append(move_line.move_id.id)
+ datas = {'ids': move_ids}
+ datas['model'] = 'account.move'
datas['form'] = wizard
- datas['inv_ids'] = inv_ids
+ datas['move_ids'] = move_ids
res= {
'type': 'ir.actions.report.xml',
'datas': datas,
Follow ups