~lepistone/openobject-italia/6.1-fix-account_invoice_entry_date_signature

« back to all changes in this revision

Viewing changes to l10n_it_vat_registries/invoice.py

  • Committer: Lorenzo Battistini
  • Date: 2012-12-11 18:25:49 UTC
  • Revision ID: lorenzo.battistini@agilebg.com-20121211182549-n8d1bzktagf0tvd7
[FIX] l10n_it_vat_registries - PEP8

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#    This program is distributed in the hope that it will be useful,
14
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
#    GNU General Public License for more details.
 
16
#    GNU Affero General Public License for more details.
17
17
#
18
18
#    You should have received a copy of the GNU Affero General Public License
19
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
124
124
                        base_amount += self._get_line_amount_with_sign(line)
125
125
                # calcolo % indetraibile
126
126
                actual_tax_amount = base_amount * main_tax.amount
127
 
                actual_tax_amount = cur_pool.round(self.cr, self.uid, move.company_id.currency_id, actual_tax_amount)
 
127
                actual_tax_amount = cur_pool.round(
 
128
                    self.cr, self.uid, move.company_id.currency_id,
 
129
                    actual_tax_amount)
128
130
                non_deductible = 0.0
129
131
                if abs(actual_tax_amount) != abs(move_line.tax_amount):
130
132
                    non_deductible = 100
131
133
                    if move_line.tax_amount:
132
 
                        non_deductible = 100 - abs((move_line.tax_amount * 100.0) / actual_tax_amount)
133
 
                        non_deductible = cur_pool.round(self.cr, self.uid, move.company_id.currency_id, non_deductible)
 
134
                        non_deductible = 100 - abs((
 
135
                            move_line.tax_amount * 100.0) / actual_tax_amount)
 
136
                        non_deductible = cur_pool.round(
 
137
                            self.cr, self.uid, move.company_id.currency_id,
 
138
                            non_deductible)
134
139
                # calcolo il totale dell'operazione
135
140
                invoice_amount_total = self._move_total(move_line)
136
141
                if self._is_refund(move_line):
138
143
                str_non_deductible = str(non_deductible).split('.')[0]
139
144
                tax_item = {
140
145
                    'tax_percentage': main_tax.amount and str(
141
 
                        main_tax.amount * 100).split('.')[0] or move_line.tax_code_id.name,
 
146
                        main_tax.amount * 100).split('.')[0] or
 
147
                        move_line.tax_code_id.name,
142
148
                    'tax_code_name': move_line.tax_code_id.name,
143
149
                    'base': base_amount,
144
150
                    'amount': actual_tax_amount,
145
 
                    'non_deductible': str_non_deductible != '0' and str_non_deductible or '',
 
151
                    'non_deductible': str_non_deductible != '0' and
 
152
                        str_non_deductible or '',
146
153
                    'index': index,
147
154
                    'amount_total': invoice_amount_total,
148
155
                    }
149
156
                res.append(tax_item)
150
 
                totale_iva += cur_pool.round(self.cr, self.uid, move.company_id.currency_id,
 
157
                totale_iva += cur_pool.round(
 
158
                    self.cr, self.uid, move.company_id.currency_id,
151
159
                    (actual_tax_amount * (100 - non_deductible) * 0.01))
152
160
                invoice_amount_untaxed += base_amount
153
 
                totale_iva_inded += cur_pool.round(self.cr, self.uid, move.company_id.currency_id,
 
161
                totale_iva_inded += cur_pool.round(
 
162
                    self.cr, self.uid, move.company_id.currency_id,
154
163
                    (actual_tax_amount * non_deductible * 0.01))
155
164
                index += 1
156
165
 
157
166
            if tax_item:
158
 
                if tax_item['tax_code_name'] not in self.localcontext['tax_codes']:
159
 
                    self.localcontext['tax_codes'][tax_item['tax_code_name']] = {
 
167
                if tax_item['tax_code_name'] not in self.localcontext[
 
168
                    'tax_codes']:
 
169
                    self.localcontext['tax_codes'][tax_item[
 
170
                        'tax_code_name']] = {
160
171
                        'base': tax_item['base'],
161
172
                        'amount': tax_item['amount'],
162
173
                        }
163
174
                else:
164
 
                    self.localcontext['tax_codes'][tax_item['tax_code_name']]['base'] += tax_item['base']
165
 
                    self.localcontext['tax_codes'][tax_item['tax_code_name']]['amount'] += tax_item['amount']
 
175
                    self.localcontext['tax_codes'][tax_item[
 
176
                        'tax_code_name']]['base'] += tax_item['base']
 
177
                    self.localcontext['tax_codes'][tax_item[
 
178
                        'tax_code_name']]['amount'] += tax_item['amount']
166
179
 
167
 
        self.localcontext['totali']['totale_operazioni'] += invoice_amount_total
168
 
        self.localcontext['totali']['totale_imponibili'] += invoice_amount_untaxed
 
180
        self.localcontext['totali'][
 
181
            'totale_operazioni'] += invoice_amount_total
 
182
        self.localcontext['totali'][
 
183
            'totale_imponibili'] += invoice_amount_untaxed
169
184
        self.localcontext['totali']['totale_iva'] += totale_iva
170
185
        self.localcontext['totali']['totale_iva_inded'] += totale_iva_inded
171
186
 
175
190
        res=[]
176
191
        tax_obj = self.pool.get('account.tax')
177
192
        # index è usato per non ripetere la stampa dei dati fattura quando ci sono più codici IVA
178
 
        index=0
 
193
        index = 0
179
194
        totale_iva = 0.0
180
195
        totale_iva_inded = 0.0
181
196
        invoice_amount_total = 0.0
185
200
            if inv_tax.base_code_id and inv_tax.tax_code_id:
186
201
                account_tax = tax_obj.get_account_tax(inv_tax)
187
202
                if account_tax.exclude_from_registries:
188
 
                    self.logger.notifyChannel("l10n_it_vat_registries", netsvc.LOG_INFO,
189
 
                        _('The tax %s is excluded from registries') % account_tax.name)
 
203
                    self.logger.notifyChannel("l10n_it_vat_registries",
 
204
                        netsvc.LOG_INFO, _(
 
205
                        'The tax %s is excluded from registries')
 
206
                        % account_tax.name)
190
207
                    continue
191
208
                account_tax_amount = account_tax.amount
192
209
                invoice_amount_total = self._get_invoice_amount_total(invoice)
193
 
                invoice_amount_untaxed = self._get_invoice_amount_untaxed(invoice)
194
 
                amount = self._get_amount_with_sign(inv_tax.tax_amount, inv_tax.amount)
195
 
                base = self._get_amount_with_sign(inv_tax.base_amount, inv_tax.base)
 
210
                invoice_amount_untaxed = self._get_invoice_amount_untaxed(
 
211
                    invoice)
 
212
                amount = self._get_amount_with_sign(inv_tax.tax_amount,
 
213
                    inv_tax.amount)
 
214
                base = self._get_amount_with_sign(inv_tax.base_amount,
 
215
                    inv_tax.base)
196
216
                # calcolo le note di credito con segno invertito
197
217
                if invoice.type in ('in_refund', 'out_refund'):
198
218
                    amount = -amount
201
221
                    invoice_amount_total = -invoice_amount_total
202
222
                tax_item = {
203
223
                    'tax_percentage': account_tax_amount and str(
204
 
                        account_tax_amount * 100).split('.')[0] or inv_tax.tax_code_id.name,
 
224
                        account_tax_amount * 100).split('.')[0] or
 
225
                        inv_tax.tax_code_id.name,
205
226
                    'base': base,
206
 
                    'amount': amount, #in valuta base
 
227
                    'amount': amount,  # in valuta base
207
228
                    'non_deductible': 0.0,
208
229
                    'index': index,
209
230
                    'amount_total': invoice_amount_total,
215
236
            elif inv_tax.tax_code_id:
216
237
                tax = tax_obj.get_main_tax(tax_obj.get_account_tax(inv_tax))
217
238
                if tax.exclude_from_registries:
218
 
                    self.logger.notifyChannel("l10n_it_vat_registries", netsvc.LOG_INFO,
 
239
                    self.logger.notifyChannel("l10n_it_vat_registries",
 
240
                        netsvc.LOG_INFO,
219
241
                        _('The tax %s is excluded from registries') % tax.name)
220
242
                    continue
221
243
                for inv_tax_2 in invoice.tax_line:
222
244
                    if inv_tax_2.base_code_id and not inv_tax_2.tax_code_id:
223
 
                        base_tax = tax_obj.get_main_tax(tax_obj.get_account_tax(inv_tax_2))
 
245
                        base_tax = tax_obj.get_main_tax(
 
246
                            tax_obj.get_account_tax(inv_tax_2))
224
247
                        # Se hanno la stessa tassa
225
248
                        if base_tax.id == tax.id:
226
249
                            # Uso il valore assoluto perchè riferendosi
227
250
                            # alla stessa imposta non ci possono essere
228
251
                            # segni differenti
229
252
                            non_deductible = (abs(inv_tax_2.base_amount) /
230
 
                                (abs(inv_tax.base_amount) + abs(inv_tax_2.base_amount)) * 100)
231
 
                            invoice_amount_total = self._get_invoice_amount_total(invoice)
232
 
                            invoice_amount_untaxed = self._get_invoice_amount_untaxed(invoice)
233
 
                            amount = self._get_amount_with_sign(inv_tax.tax_amount, inv_tax.amount)
234
 
                            base = self._get_amount_with_sign(inv_tax.base_amount, inv_tax.base)
235
 
                            amount2 = self._get_amount_with_sign(inv_tax_2.tax_amount, inv_tax_2.amount)
236
 
                            base2 = self._get_amount_with_sign(inv_tax_2.base_amount, inv_tax_2.base)
 
253
                                (abs(inv_tax.base_amount) + abs(
 
254
                                    inv_tax_2.base_amount)) * 100)
 
255
                            invoice_amount_total = \
 
256
                                self._get_invoice_amount_total(invoice)
 
257
                            invoice_amount_untaxed = \
 
258
                                self._get_invoice_amount_untaxed(invoice)
 
259
                            amount = self._get_amount_with_sign(
 
260
                                inv_tax.tax_amount, inv_tax.amount)
 
261
                            base = self._get_amount_with_sign(
 
262
                                inv_tax.base_amount, inv_tax.base)
 
263
                            amount2 = self._get_amount_with_sign(
 
264
                                inv_tax_2.tax_amount, inv_tax_2.amount)
 
265
                            base2 = self._get_amount_with_sign(
 
266
                                inv_tax_2.base_amount, inv_tax_2.base)
237
267
                            # calcolo le note di credito con segno invertito
238
268
                            if invoice.type in ('in_refund', 'out_refund'):
239
269
                                amount = -amount
240
270
                                base = -base
241
271
                                amount2 = -amount2
242
272
                                base2 = -base2
243
 
                                invoice_amount_untaxed = -invoice_amount_untaxed
 
273
                                invoice_amount_untaxed = \
 
274
                                    -invoice_amount_untaxed
244
275
                                invoice_amount_total = -invoice_amount_total
245
276
                            tax_item = {
246
277
                                'tax_percentage': base_tax.amount and str(
247
 
                                    base_tax.amount * 100).split('.')[0] or inv_tax.tax_code_id.name,
 
278
                                    base_tax.amount * 100).split('.')[0] or
 
279
                                    inv_tax.tax_code_id.name,
248
280
                                'base': base + base2,
249
281
                                'amount': amount + amount2,
250
 
                                'non_deductible': non_deductible and str(non_deductible).split('.')[0] or '',
 
282
                                'non_deductible': non_deductible and str(
 
283
                                    non_deductible).split('.')[0] or '',
251
284
                                'index': index,
252
285
                                'amount_total': invoice_amount_total,
253
286
                                }
257
290
                            index += 1
258
291
                            break
259
292
            elif not inv_tax.tax_code_id and not inv_tax.base_code_id:
260
 
                self.logger.notifyChannel("l10n_it_vat_registries", netsvc.LOG_INFO,
 
293
                self.logger.notifyChannel("l10n_it_vat_registries",
 
294
                    netsvc.LOG_INFO,
261
295
                    _('The tax %s has no tax codes') % inv_tax.name)
262
296
                continue
263
297
            if tax_item:
264
 
                if tax_item['tax_percentage'] not in self.localcontext['tax_codes']:
265
 
                    self.localcontext['tax_codes'][tax_item['tax_percentage']] = {
 
298
                if tax_item['tax_percentage'] not in self.localcontext[
 
299
                    'tax_codes']:
 
300
                    self.localcontext['tax_codes'][tax_item[
 
301
                        'tax_percentage']] = {
266
302
                        'base': tax_item['base'],
267
303
                        'amount': tax_item['amount'],
268
304
                        }
269
305
                else:
270
 
                    self.localcontext['tax_codes'][tax_item['tax_percentage']]['base'] += tax_item['base']
271
 
                    self.localcontext['tax_codes'][tax_item['tax_percentage']]['amount'] += tax_item['amount']
 
306
                    self.localcontext['tax_codes'][tax_item[
 
307
                        'tax_percentage']]['base'] += tax_item['base']
 
308
                    self.localcontext['tax_codes'][tax_item[
 
309
                        'tax_percentage']]['amount'] += tax_item['amount']
272
310
 
273
 
        self.localcontext['totali']['totale_operazioni'] += invoice_amount_total
274
 
        self.localcontext['totali']['totale_imponibili'] += invoice_amount_untaxed
 
311
        self.localcontext['totali'][
 
312
            'totale_operazioni'] += invoice_amount_total
 
313
        self.localcontext['totali'][
 
314
            'totale_imponibili'] += invoice_amount_untaxed
275
315
# da analizzare           self.totale_variazioni += invoice.amount_total
276
316
        self.localcontext['totali']['totale_iva'] += totale_iva
277
317
        self.localcontext['totali']['totale_iva_inded'] += totale_iva_inded