~openbias/bias-trunk/bias-public-trunk

« back to all changes in this revision

Viewing changes to bias_tax_model_v42/account_move_line.py

  • Committer: Jose Patricio
  • Date: 2011-10-19 03:16:40 UTC
  • Revision ID: josepato@bias.com.mx-20111019031640-05zd7r5lxwx084qu
el push inicial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
import netsvc
 
23
from osv import fields, osv
 
24
from tools.translate import _
 
25
 
 
26
class account_move_line(osv.osv):
 
27
    _inherit = "account.move.line"
 
28
 
 
29
    def create(self, cr, uid, vals, context=None, check=True):
 
30
        result = super(account_move_line, self).create(cr, uid, vals, context=context)
 
31
 
 
32
        # CREATE Fiscal Lines
 
33
        fiscal_obj = self.pool.get('account.move.fiscal')
 
34
        line = self.browse(cr, uid, result)
 
35
        rate = 0
 
36
        if line.journal_id.type == 'bank':
 
37
            if line.partner_id and line.partner_id.operation_type_id:
 
38
                res = self.get_base(cr, uid, line, line.partner_id.operation_type_id)
 
39
                if res['rate']:
 
40
                    data = {
 
41
                        'move_id': line.move_id.id,
 
42
                        'line_id': line.id,
 
43
                        'partner_id': line.partner_id.id, 
 
44
                        'operation_type_id': line.partner_id.operation_type_id.id, 
 
45
                        'ietu_concept_id': line.partner_id.ietu_concept_id and line.partner_id.ietu_concept_id.id or False,
 
46
                        'base': res['base'],
 
47
                        'ietu': res['base'],
 
48
                        }
 
49
                    fiscal_id = fiscal_obj.create(cr, uid, data)
 
50
                    fiscal = fiscal_obj.browse(cr, uid, fiscal_id)
 
51
                    if fiscal.operation_type_id.auto:
 
52
                        fiscal_obj.button_tax_xfer(cr, uid, [fiscal.id], context=None)
 
53
        return result
 
54
 
 
55
    def get_base(self, cr, uid, line, operation):
 
56
        iva, ret_iva, ret_isr = False, False, False
 
57
        amount_iva, amount_ret_iva, amount_ret_isr, amount, base, rate = 0.0,0.0,0.0,0.0,0.0,0.0
 
58
        if line.account_id in operation.account_ids:
 
59
            iva = filter(lambda x: x.tax_type == 'iva', operation.tax_ids)
 
60
            ret_iva = filter(lambda x: x.tax_type == 'ret_iva', operation.tax_ids)
 
61
            ret_isr = filter(lambda x: x.tax_type == 'ret_isr', operation.tax_ids)
 
62
            amount_iva = iva and iva[0].tax_id.amount or 0.0
 
63
            amount_ret_iva = ret_iva and ret_iva[0].tax_id.amount or 0.0
 
64
            amount_ret_isr = ret_isr and ret_isr[0].tax_id.amount or 0.0
 
65
            rate = amount_iva + amount_ret_iva + amount_ret_isr
 
66
            amount = line.debit - line.credit
 
67
            base = amount / (1 + rate)
 
68
        elif line.account_id in operation.account_income_ids:
 
69
            iva = filter(lambda x: x.tax_type == 'iva', operation.tax_income_ids)
 
70
            ret_iva = filter(lambda x: x.tax_type == 'ret_iva', operation.tax_income_ids)
 
71
            ret_isr = filter(lambda x: x.tax_type == 'ret_isr', operation.tax_income_ids)
 
72
            amount_iva = iva and iva[0].tax_id.amount or 0.0
 
73
            amount_ret_iva = ret_iva and ret_iva[0].tax_id.amount or 0.0
 
74
            amount_ret_isr = ret_isr and ret_isr[0].tax_id.amount or 0.0
 
75
            rate = amount_iva + amount_ret_iva + amount_ret_isr
 
76
            amount = line.credit - line.debit
 
77
            base = amount / (1 + rate)
 
78
        return {'iva':iva and iva[0], 'amount_iva': amount_iva, 'amount_ret_iva':amount_ret_iva, 'amount_ret_isr':amount_ret_isr, 
 
79
                'rate':rate, 'base':base, 'amount':amount}
 
80
    
 
81
account_move_line()
 
82
 
 
83
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: