Skip to content

Commit

Permalink
[FIX] It allows canceling withholding vat
Browse files Browse the repository at this point in the history
  • Loading branch information
egrivero committed Mar 18, 2016
1 parent 6b8d6ad commit e740a43
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
12 changes: 12 additions & 0 deletions l10n_ve_withholding_iva/model/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ def _compute_retenida(self):
except:
record.wh_iva = False

@api.multi
def check_withholding_duplicate(self):
"""
check that invoice not have a withholding vat created previously.
@return True or False.
"""
wh_vat = self.env['account.wh.iva.line']
for inv_brw in self:
if wh_vat.search([('invoice_id', '=', inv_brw.id)]):
return False
return True

@api.multi
def check_document_date(self):
"""
Expand Down
14 changes: 8 additions & 6 deletions l10n_ve_withholding_iva/model/wh_iva.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,20 +397,22 @@ def action_cancel(self):
def cancel_move(self):
""" Delete move lines related with withholding vat and cancel
"""
moves = self.pool.get('account.move')
moves_obj = self.env['account.move']
moves = []
for ret in self:
if ret.state == 'done':
for ret_line in ret.wh_lines:
moves += ret_line.move_id
moves.append(ret_line.move_id)
# first, detach the move id
ret_line.write({'move_id': False})
# second, set the withholding as cancelled
ret.write({'state': 'cancel'})
if moves:
# third, invalidate the move(s)
moves.button_cancel()
# last, delete the move(s)
moves.unlink()
for move in moves:
# third, invalidate the move(s)
move.button_cancel()
# last, delete the move(s)
move.unlink()
return True

@api.model
Expand Down
3 changes: 2 additions & 1 deletion l10n_ve_withholding_iva/workflow/wh_action_server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<field name="condition">True</field>
<field eval="3" name="sequence"/>
<field name="type">ir.actions.server</field>
<field name="code">object.check_document_date() and \
<field name="code">object.check_withholding_duplicate() and \
object.check_document_date() and \
object.check_invoice_dates() and \
object.check_wh_apply() and \
object.check_withholdable() and \
Expand Down

0 comments on commit e740a43

Please sign in to comment.