~serpent-consulting-services/addons-vauxoo/7.0-fix-aging-due-mx-dependency

« back to all changes in this revision

Viewing changes to account_voucher_tax_sat/model/account_voucher_tax_sat.py

  • Committer: Moises Lopez
  • Date: 2014-10-03 08:04:16 UTC
  • mfrom: (1144.1.3 70-addons-vauxoo)
  • Revision ID: moylop260@vauxoo.com-20141003080416-yquvsxfq5i4cy8ux
[MERGE] [FIX] trailing whitespace pylint error C0303 and
[FIX] autopep8 ignoring E501 & E128 and
[FIX] reimported

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
 
27
27
class account_voucher_tax_sat(osv.Model):
28
 
    
 
28
 
29
29
    _name = 'account.voucher.tax.sat'
30
 
    
 
30
 
31
31
    _columns = {
32
32
        'name': fields.char('Name', size=128,
33
33
                            help='Name of This Document',
34
34
                            ),
35
35
        'partner_id': fields.many2one('res.partner', 'Partner',
36
 
                            domain = "[('sat', '=', True)]",
 
36
                            domain="[('sat', '=', True)]",
37
37
                            help='Partner of SAT',
38
 
                            ),
 
38
                                      ),
39
39
        'date': fields.date('Accounting Date',
40
40
                            help='Accounting date affected',
41
41
                            ),
42
42
        'aml_ids': fields.many2many('account.move.line', 'voucher_tax_sat_rel',
43
43
                            'voucher_tax_sat_id', 'move_line_id',
44
44
                            'Move Lines', help='Entries to close',
45
 
                            ),
46
 
        'journal_id':fields.many2one('account.journal', 'Journal',
 
45
                                    ),
 
46
        'journal_id': fields.many2one('account.journal', 'Journal',
47
47
                            help='Accounting Journal where Entries will be posted',
48
 
                            ), 
 
48
                                      ),
49
49
        'move_id': fields.many2one('account.move', 'Journal Entry',
50
50
                            help='Accounting Entry'),
51
 
        'company_id':fields.many2one('res.company', 'Company', help='Company'), 
 
51
        'company_id': fields.many2one('res.company', 'Company', help='Company'),
52
52
        'period_id': fields.many2one('account.period', 'Period', required=True,
53
53
                            help='Period of Entries to find',
54
 
                            ),
 
54
                                     ),
55
55
        'state': fields.selection([
56
56
            ('draft', 'New'),
57
57
            ('cancelled', 'Cancelled'),
63
63
            u, cx).company_id.id,
64
64
        'state': 'draft'
65
65
    }
66
 
    
 
66
 
67
67
    def onchange_period(self, cr, uid, ids, period, context=None):
68
68
        res = {}
69
69
        if period:
74
74
        move_line_obj = self.pool.get('account.move.line')
75
75
        cr.execute(""" SELECT DISTINCT move_line_id FROM voucher_tax_sat_rel
76
76
                        WHERE voucher_tax_sat_id <> %s
77
 
                        AND move_line_id IN %s """,(
78
 
                            voucher_tax.id,
79
 
                            tuple([ move_lines.id\
80
 
                                    for move_lines in voucher_tax.aml_ids ]))
81
 
                    )
 
77
                        AND move_line_id IN %s """, (
 
78
            voucher_tax.id,
 
79
            tuple([move_lines.id
 
80
                   for move_lines in voucher_tax.aml_ids]))
 
81
        )
82
82
        dat = cr.dictfetchall()
83
 
        move_line_tax = list( set([ move_tax['move_line_id'] for move_tax in dat ]) )
 
83
        move_line_tax = list(set([move_tax['move_line_id'] for move_tax in dat]))
84
84
        if dat:
85
85
            raise osv.except_osv(_('Warning'),
86
86
                _("You have this jornal items in other voucher tax sat '%s' ")
87
 
                % ([ move_line.name\
88
 
                        for move_line in move_line_obj.browse(cr, uid,
 
87
                % ([move_line.name
 
88
                    for move_line in move_line_obj.browse(cr, uid,
89
89
                                            move_line_tax, context=context)]))
90
90
 
91
91
        return True
92
 
    
 
92
 
93
93
    def action_close_tax(self, cr, uid, ids, context=None):
94
94
        aml_obj = self.pool.get('account.move.line')
95
95
        period_obj = self.pool.get('account.period')
96
96
        context = context or {}
97
 
        ids= isinstance(ids,(int,long)) and [ids] or ids
 
97
        ids = isinstance(ids, (int, long)) and [ids] or ids
98
98
        for voucher_tax_sat in self.browse(cr, uid, ids, context=context):
99
 
                                            
100
 
                self.validate_move_line(cr, uid,
101
 
                                        voucher_tax_sat, context=context)
102
 
                                    
103
 
                move_id = self.create_move_sat(cr, uid, ids, context=context)
104
 
                self.write(cr, uid, ids, {'move_id': move_id})
105
 
                
106
 
                amount_tax_sat = sum([move_line_tax_sat.credit
107
 
                            for move_line_tax_sat in voucher_tax_sat.aml_ids])
108
 
                            
109
 
                self.create_move_line_sat(cr, uid, voucher_tax_sat,
110
 
                                            amount_tax_sat, context=context)
111
 
                                            
112
 
                self.create_entries_tax_iva_sat(cr, uid, voucher_tax_sat,
113
 
                                                            context=context)
114
 
                                        
115
 
                move_line_copy = [ aml_obj.copy(cr, uid, move_line_tax.id,
116
 
                    {
117
 
                        'move_id': move_id,
118
 
                        'period_id': period_obj.find(cr, uid,
119
 
                                        voucher_tax_sat.date,
120
 
                                        context=context)[0],
121
 
                        'journal_id': voucher_tax_sat.journal_id.id,
122
 
                        'credit': 0.0,
123
 
                        'debit': move_line_tax.credit,
124
 
                        'amount_base': None,
125
 
                        'tax_id_secondary': None,
126
 
                        'not_move_diot': True
127
 
                    }) for move_line_tax in voucher_tax_sat.aml_ids ]
128
 
                    
129
 
                cr.execute('UPDATE account_move_line '\
130
 
                            'SET amount_tax_unround = null '\
131
 
                            'WHERE id in %s ',(tuple(move_line_copy), ))
132
 
                            
 
99
 
 
100
            self.validate_move_line(cr, uid,
 
101
                                    voucher_tax_sat, context=context)
 
102
 
 
103
            move_id = self.create_move_sat(cr, uid, ids, context=context)
 
104
            self.write(cr, uid, ids, {'move_id': move_id})
 
105
 
 
106
            amount_tax_sat = sum([move_line_tax_sat.credit
 
107
                        for move_line_tax_sat in voucher_tax_sat.aml_ids])
 
108
 
 
109
            self.create_move_line_sat(cr, uid, voucher_tax_sat,
 
110
                                      amount_tax_sat, context=context)
 
111
 
 
112
            self.create_entries_tax_iva_sat(cr, uid, voucher_tax_sat,
 
113
                                            context=context)
 
114
 
 
115
            move_line_copy = [aml_obj.copy(cr, uid, move_line_tax.id,
 
116
                {
 
117
                    'move_id': move_id,
 
118
                    'period_id': period_obj.find(cr, uid,
 
119
                                    voucher_tax_sat.date,
 
120
                                    context=context)[0],
 
121
                    'journal_id': voucher_tax_sat.journal_id.id,
 
122
                    'credit': 0.0,
 
123
                    'debit': move_line_tax.credit,
 
124
                    'amount_base': None,
 
125
                    'tax_id_secondary': None,
 
126
                    'not_move_diot': True
 
127
                }) for move_line_tax in voucher_tax_sat.aml_ids]
 
128
 
 
129
            cr.execute('UPDATE account_move_line '
 
130
                       'SET amount_tax_unround = null '
 
131
                       'WHERE id in %s ', (tuple(move_line_copy), ))
 
132
 
133
133
        return self.write(cr, uid, ids, {'state': 'done'}, context=context)
134
 
    
 
134
 
135
135
    def action_cancel(self, cr, uid, ids, context=None):
136
136
        obj_move_line = self.pool.get('account.move.line')
137
137
        obj_move = self.pool.get('account.move')
144
144
                obj_move.unlink(cr, uid, [tax_sat.move_id.id],
145
145
                                context=context)
146
146
        return self.write(cr, uid, ids, {'state': 'draft'}, context=context)
147
 
    
 
147
 
148
148
    def create_entries_tax_iva_sat(self, cr, uid, voucher_tax_sat,
149
 
                                                            context=None):
 
149
                                   context=None):
150
150
        aml_obj = self.pool.get('account.move.line')
151
151
        av_obj = self.pool.get('account.voucher')
152
152
        period_obj = self.pool.get('account.period')
153
153
        for move_line in voucher_tax_sat.aml_ids:
154
154
            if move_line.tax_id_secondary and\
155
 
                                        move_line.tax_id_secondary.tax_sat_ok:
 
155
                    move_line.tax_id_secondary.tax_sat_ok:
156
156
                amount_base, tax_secondary = av_obj._get_base_amount_tax_secondary(cr,
157
157
                            uid, move_line.tax_id_secondary,
158
158
                            move_line.amount_base, move_line.credit,
162
162
                    'journal_id': voucher_tax_sat.journal_id.id,
163
163
                    'date': voucher_tax_sat.date,
164
164
                    'period_id': period_obj.find(cr, uid,
165
 
                                                    voucher_tax_sat.date,
166
 
                                                    context=context)[0],
 
165
                                                 voucher_tax_sat.date,
 
166
                                                 context=context)[0],
167
167
                    'debit': move_line.credit,
168
168
                    'name': _('Close of IVA Retained'),
169
 
                    'partner_id' : move_line.partner_id.id,
 
169
                    'partner_id': move_line.partner_id.id,
170
170
                    'account_id': move_line.tax_id_secondary.account_id_creditable.id,
171
171
                    'credit': 0.0,
172
172
                    'amount_base': amount_base,
177
177
                    'journal_id': voucher_tax_sat.journal_id.id,
178
178
                    'date': voucher_tax_sat.date,
179
179
                    'period_id': period_obj.find(cr, uid,
180
 
                                                    voucher_tax_sat.date,
181
 
                                                    context=context)[0],
 
180
                                                 voucher_tax_sat.date,
 
181
                                                 context=context)[0],
182
182
                    'debit': 0.0,
183
183
                    'name': _('Close of IVA Retained'),
184
 
                    'partner_id' : move_line.partner_id.id,
 
184
                    'partner_id': move_line.partner_id.id,
185
185
                    'account_id': move_line.tax_id_secondary.account_id_by_creditable.id,
186
186
                    'credit': move_line.credit,
187
187
                }
188
188
                for line_dt_cr in [move_line_dt, move_line_cr]:
189
189
                    aml_obj.create(cr, uid, line_dt_cr, context=context)
190
190
        return True
191
 
    
 
191
 
192
192
    def create_move_line_sat(self, cr, uid, voucher_tax_sat, amount, context=None):
193
193
        aml_obj = self.pool.get('account.move.line')
194
194
        period_obj = self.pool.get('account.period')
197
197
            'journal_id': voucher_tax_sat.journal_id.id,
198
198
            'date': voucher_tax_sat.date,
199
199
            'period_id': period_obj.find(cr, uid,
200
 
                                                voucher_tax_sat.date,
201
 
                                                context=context)[0],
 
200
                                         voucher_tax_sat.date,
 
201
                                         context=context)[0],
202
202
            'debit': 0,
203
203
            'name': _('Payment to SAT'),
204
204
            'partner_id': voucher_tax_sat.partner_id.id,
206
206
            'credit': amount,
207
207
        }
208
208
        return aml_obj.create(cr, uid, vals, context=context)
209
 
    
 
209
 
210
210
    def create_move_sat(self, cr, uid, ids, context=None):
211
211
        account_move_obj = self.pool.get('account.move')
212
212
        context = context or {}
213
 
        ids= isinstance(ids,(int,long)) and [ids] or ids
 
213
        ids = isinstance(ids, (int, long)) and [ids] or ids
214
214
        for move_tax_sat in self.browse(cr, uid, ids, context=context):
215
 
            vals_move_tax= account_move_obj.account_move_prepare(cr, uid,
 
215
            vals_move_tax = account_move_obj.account_move_prepare(cr, uid,
216
216
                    move_tax_sat.journal_id.id,
217
 
                    date = move_tax_sat.date,
 
217
                    date=move_tax_sat.date,
218
218
                    ref='Entry SAT', context=context)
219
219
        return account_move_obj.create(cr, uid, vals_move_tax, context=context)
220
220
 
221
 
 
222
221
    def sat_pay(self, cr, uid, ids, context=None):
223
222
        """
224
223
        """
225
224
        context = context or {}
226
225
        ids = isinstance(ids, (int, long)) and [ids] or ids
227
 
        if not ids: return []
 
226
        if not ids:
 
227
            return []
228
228
        dummy, view_id = self.pool.get('ir.model.data').\
229
 
                                get_object_reference(cr, uid,
230
 
                                'account_voucher', 'view_vendor_payment_form')
 
229
            get_object_reference(cr, uid,
 
230
                             'account_voucher', 'view_vendor_payment_form')
231
231
        exp_brw = self.browse(cr, uid, ids[0], context=context)
232
232
        return {
233
 
            'name':_("Pay SAT"),
 
233
            'name': _("Pay SAT"),
234
234
            'view_mode': 'form',
235
235
            'view_id': view_id,
236
236
            'view_type': 'form',
250
250
 
251
251
 
252
252
class account_tax(osv.Model):
253
 
    
 
253
 
254
254
    _inherit = 'account.tax'
255
 
    
 
255
 
256
256
    _columns = {
257
257
        'tax_sat_ok': fields.boolean('Create entries IVA to SAT'),
258
258
        'account_id_creditable': fields.many2one('account.account',
261
261
                                        'Account of entries SAT x Acreditable'),
262
262
        'tax_reference': fields.many2one('account.tax',
263
263
            'Tax Reference',
264
 
            help = 'Tax Reference to get data of DIOT/SAT')
265
 
    }
 
 
b'\\ No newline at end of file'
 
264
            help='Tax Reference to get data of DIOT/SAT')
 
265
    }