27
27
class account_voucher_tax_sat(osv.Model):
29
29
_name = 'account.voucher.tax.sat'
32
32
'name': fields.char('Name', size=128,
33
33
help='Name of This Document',
35
35
'partner_id': fields.many2one('res.partner', 'Partner',
36
domain = "[('sat', '=', True)]",
36
domain="[('sat', '=', True)]",
37
37
help='Partner of SAT',
39
39
'date': fields.date('Accounting Date',
40
40
help='Accounting date affected',
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',
46
'journal_id':fields.many2one('account.journal', 'Journal',
46
'journal_id': fields.many2one('account.journal', 'Journal',
47
47
help='Accounting Journal where Entries will be posted',
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',
55
55
'state': fields.selection([
57
57
('cancelled', 'Cancelled'),
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 """,(
79
tuple([ move_lines.id\
80
for move_lines in voucher_tax.aml_ids ]))
77
AND move_line_id IN %s """, (
80
for move_lines in voucher_tax.aml_ids]))
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]))
85
85
raise osv.except_osv(_('Warning'),
86
86
_("You have this jornal items in other voucher tax sat '%s' ")
88
for move_line in move_line_obj.browse(cr, uid,
88
for move_line in move_line_obj.browse(cr, uid,
89
89
move_line_tax, context=context)]))
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):
100
self.validate_move_line(cr, uid,
101
voucher_tax_sat, context=context)
103
move_id = self.create_move_sat(cr, uid, ids, context=context)
104
self.write(cr, uid, ids, {'move_id': move_id})
106
amount_tax_sat = sum([move_line_tax_sat.credit
107
for move_line_tax_sat in voucher_tax_sat.aml_ids])
109
self.create_move_line_sat(cr, uid, voucher_tax_sat,
110
amount_tax_sat, context=context)
112
self.create_entries_tax_iva_sat(cr, uid, voucher_tax_sat,
115
move_line_copy = [ aml_obj.copy(cr, uid, move_line_tax.id,
118
'period_id': period_obj.find(cr, uid,
119
voucher_tax_sat.date,
121
'journal_id': voucher_tax_sat.journal_id.id,
123
'debit': move_line_tax.credit,
125
'tax_id_secondary': None,
126
'not_move_diot': True
127
}) for move_line_tax in voucher_tax_sat.aml_ids ]
129
cr.execute('UPDATE account_move_line '\
130
'SET amount_tax_unround = null '\
131
'WHERE id in %s ',(tuple(move_line_copy), ))
100
self.validate_move_line(cr, uid,
101
voucher_tax_sat, context=context)
103
move_id = self.create_move_sat(cr, uid, ids, context=context)
104
self.write(cr, uid, ids, {'move_id': move_id})
106
amount_tax_sat = sum([move_line_tax_sat.credit
107
for move_line_tax_sat in voucher_tax_sat.aml_ids])
109
self.create_move_line_sat(cr, uid, voucher_tax_sat,
110
amount_tax_sat, context=context)
112
self.create_entries_tax_iva_sat(cr, uid, voucher_tax_sat,
115
move_line_copy = [aml_obj.copy(cr, uid, move_line_tax.id,
118
'period_id': period_obj.find(cr, uid,
119
voucher_tax_sat.date,
121
'journal_id': voucher_tax_sat.journal_id.id,
123
'debit': move_line_tax.credit,
125
'tax_id_secondary': None,
126
'not_move_diot': True
127
}) for move_line_tax in voucher_tax_sat.aml_ids]
129
cr.execute('UPDATE account_move_line '
130
'SET amount_tax_unround = null '
131
'WHERE id in %s ', (tuple(move_line_copy), ))
133
133
return self.write(cr, uid, ids, {'state': 'done'}, context=context)
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],
146
146
return self.write(cr, uid, ids, {'state': 'draft'}, context=context)
148
148
def create_entries_tax_iva_sat(self, cr, uid, voucher_tax_sat,
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,
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,
180
voucher_tax_sat.date,
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,
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)
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')
206
206
'credit': amount,
208
208
return aml_obj.create(cr, uid, vals, context=context)
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)
222
221
def sat_pay(self, cr, uid, ids, context=None):
225
224
context = context or {}
226
225
ids = isinstance(ids, (int, long)) and [ids] or ids
227
if not ids: 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)
233
'name': _("Pay SAT"),
234
234
'view_mode': 'form',
235
235
'view_id': view_id,
236
236
'view_type': 'form',