~vauxoo/addons-vauxoo/7.0-addons-vauxoo-send_email_add_follower-dev-julio

« back to all changes in this revision

Viewing changes to account_voucher_tax_sat/model/account_voucher_tax_sat.py

  • Committer: Julio Serna
  • Date: 2013-10-02 22:24:19 UTC
  • mto: (885.1.1 7.0-avts_2-dev-julio)
  • mto: This revision was merged to the branch mainline in revision 901.
  • Revision ID: julio@vauxoo.com-20131002222419-81wzw1yb5uthl6cu
[ADD] added module that create entries of tax to SAT

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- encoding: utf-8 -*-
 
3
###########################################################################
 
4
#    Module Writen to OpenERP, Open Source Management Solution
 
5
#    Copyright (C) Vauxoo (<http://vauxoo.com>).
 
6
#    All Rights Reserved
 
7
###############Credits######################################################
 
8
#    Coded by: Julio Cesar Serna Hernandez(julio@vauxoo.com)
 
9
#############################################################################
 
10
#    This program is free software: you can redistribute it and/or modify
 
11
#    it under the terms of the GNU Affero General Public License as published by
 
12
#    the Free Software Foundation, either version 3 of the License, or
 
13
#    (at your option) any later version.
 
14
#
 
15
#    This program is distributed in the hope that it will be useful,
 
16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
#    GNU Affero General Public License for more details.
 
19
#
 
20
#    You should have received a copy of the GNU Affero General Public License
 
21
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
################################################################################
 
23
import time
 
24
from openerp.osv import fields, osv
 
25
from openerp import netsvc
 
26
import openerp.addons.decimal_precision as dp
 
27
from openerp.tools.translate import _
 
28
 
 
29
 
 
30
class account_voucher_tax_sat(osv.Model):
 
31
    
 
32
    _name = 'account.voucher.tax.sat'
 
33
    
 
34
    _columns = {
 
35
        'name': fields.many2one('res.partner', 'Partner'),
 
36
        'period_id': fields.many2one('account.period', 'Period'),
 
37
        'aml_ids': fields.many2many('account.move.line', 'voucher_tax_sat_rel',
 
38
                                        'voucher_tax_sat_id', 'move_line_id',
 
39
                                        'Move Lines'),
 
40
        'journal_id':fields.many2one('account.journal', 'Journal'), 
 
41
        'move_id': fields.many2one('account.move', 'Journal Entry')
 
42
    }
 
43
    
 
44
    def action_close_tax(self, cr, uid, ids, context=None):
 
45
        aml_obj = self.pool.get('account.move.line')
 
46
        context = context or {}
 
47
        ids= isinstance(ids,(int,long)) and [ids] or ids
 
48
        for voucher_tax_sat in self.browse(cr, uid, ids, context=context):
 
49
            
 
50
                move_id = self.create_move_sat(cr, uid, ids, context=context)
 
51
                print move_id,'move_idmove_idmove_idmove_idmove_idmove_idmove_idmove_idmove_idmove_idmove_idmove_idmove_idmove_idmove_idmove_idmove_id'
 
52
                self.write(cr, uid, ids, {'move_id': move_id})
 
53
                
 
54
                amount_tax_sat = sum([move_line_tax_sat.credit
 
55
                            for move_line_tax_sat in voucher_tax_sat.aml_ids])
 
56
                            
 
57
                self.create_move_line_sat(cr, uid, voucher_tax_sat,
 
58
                                            amount_tax_sat, context=context)
 
59
                                        
 
60
                move_line_copy = [ aml_obj.copy(cr, uid, move_line_tax.id,
 
61
                    {
 
62
                        'move_id': move_id,
 
63
                        'period_id': voucher_tax_sat.period_id.id,
 
64
                        'journal_id': voucher_tax_sat.journal_id.id,
 
65
                        'credit': 0.0,
 
66
                        'debit': move_line_tax.credit,
 
67
                    }) for move_line_tax in voucher_tax_sat.aml_ids ]
 
68
                    
 
69
        return True
 
70
    
 
71
    def create_move_line_sat(self, cr, uid, voucher_tax_sat, amount, context=None):
 
72
        print voucher_tax_sat,'voucher_tax_sat'
 
73
        aml_obj = self.pool.get('account.move.line')
 
74
        vals = {
 
75
            'move_id': voucher_tax_sat.move_id.id,
 
76
            'journal_id': voucher_tax_sat.journal_id.id,
 
77
            'date' : fields.datetime.now(),
 
78
            'period_id' : voucher_tax_sat.period_id.id,
 
79
            'debit' : 0.0,
 
80
            'name' : _('Payment with Advance'),
 
81
            'partner_id' : voucher_tax_sat.name.id,
 
82
            'account_id' : voucher_tax_sat.name.property_account_payable.id,
 
83
            'credit' : amount,
 
84
        }
 
85
        return aml_obj.create(cr, uid, vals, context=context)
 
86
    
 
87
    def create_move_sat(self, cr, uid, ids, context=None):
 
88
        account_move_obj = self.pool.get('account.move')
 
89
        context = context or {}
 
90
        ids= isinstance(ids,(int,long)) and [ids] or ids
 
91
        for move_tax_sat in self.browse(cr, uid, ids, context=context):
 
92
            vals_move_tax= account_move_obj.account_move_prepare(cr, uid,
 
93
                    move_tax_sat.journal_id.id,
 
94
                    ref='Entry SAT', context=context)
 
95
        return account_move_obj.create(cr, uid, vals_move_tax, context=context)
 
 
b'\\ No newline at end of file'