Skip to content

Commit

Permalink
Merge pull request Vauxoo#39 from vauxoo-dev/8.0-ovl-retencion-dev-edgar
Browse files Browse the repository at this point in the history
8.0 ovl retencion dev edgar
  • Loading branch information
nhomar committed Mar 29, 2016
2 parents 185773c + b6bf341 commit 81a137c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 33 deletions.
16 changes: 14 additions & 2 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 Expand Up @@ -203,7 +215,7 @@ def create_new_wh_iva(self, ret_line_id):
'account_id': acc_id,
'partner_id': acc_part_id.id,
'period_id': inv_brw.period_id.id,
'wh_lines': [(4, ret_line_id)],
'wh_lines': [(4, ret_line_id.id)],
'fortnight': per_obj.find_fortnight(inv_brw.date_invoice)[1],
}
if inv_brw.company_id.propagate_invoice_date_to_vat_withholding:
Expand Down Expand Up @@ -242,7 +254,7 @@ def action_wh_iva_create(self):
# Create a New WH Doc and add line
ret_id = inv.create_new_wh_iva(ret_line_id)
if ret_id:
inv.write({'wh_iva_id': ret_id})
inv.write({'wh_iva_id': ret_id.id})
inv.wh_iva_id.compute_amount_wh()
return True

Expand Down
76 changes: 48 additions & 28 deletions l10n_ve_withholding_iva/model/wh_iva.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _set_amount_ret(self):

@api.multi
@api.depends('amount', 'wh_vat_line_id.wh_iva_rate')
def _get_amount_ret(self, cr, uid, ids, fieldname, args, context=None):
def _get_amount_ret(self):
""" Return withholding amount
"""
for record in self:
Expand Down Expand Up @@ -138,16 +138,23 @@ def load_taxes(self):

@api.multi
@api.depends('tax_line.amount_ret', 'tax_line.base')
def _amount_all(self, cr, uid, ids, fieldname, args, context=None):
def _amount_all(self):
""" Return amount total each line
"""
for rec in self:
if rec.invoice_id.type not in 'in_refund':
rec.amount_tax_ret = sum(l.amount_ret for l in rec.tax_line)
rec.base_ret = sum(l.base for l in rec.tax_line)
if rec.invoice_id:
if rec.invoice_id.type not in ('in_refund'):
rec.amount_tax_ret = sum(l.amount_ret
for l in rec.tax_line)
rec.base_ret = sum(l.base for l in rec.tax_line)
else:
rec.amount_tax_ret = -sum(l.amount_ret
for l in rec.tax_line)
rec.base_ret = -sum(l.base for l in rec.tax_line)
else:
rec.amount_tax_ret = -sum(l.amount_ret for l in rec.tax_line)
rec.base_ret = -sum(l.base for l in rec.tax_line)
rec.amount_tax_ret = 0
rec.base_ret = 0


name = fields.Char(
string='Description', size=64, required=True,
Expand Down Expand Up @@ -199,20 +206,21 @@ def invoice_id_change(self, invoice_id):
@param invoice: invoice for assign a withholding vat
"""
result = {}
invoice = self.env['account.invoice'].browse(invoice_id)
self._cr.execute('select retention_id '
'from account_wh_iva_line '
'where invoice_id=%s' % (invoice_id))
ret_ids = self._cr.fetchone()
if bool(ret_ids):
ret = self.env['account.wh.iva'].browse(ret_ids[0])
raise exceptions.except_orm(
'Assigned Invoice !',
"The invoice has already assigned in withholding"
" vat code: '%s' !" % (ret.code))
result.update({
'name': invoice.name,
'supplier_invoice_number': invoice.supplier_invoice_number})
if invoice_id:
invoice = self.env['account.invoice'].browse(invoice_id)
self._cr.execute('select retention_id '
'from account_wh_iva_line '
'where invoice_id=%s' % (invoice_id))
ret_ids = self._cr.fetchone()
if bool(ret_ids):
ret = self.env['account.wh.iva'].browse(ret_ids[0])
raise exceptions.except_orm(
'Assigned Invoice !',
"The invoice has already assigned in withholding"
" vat code: '%s' !" % (ret.code))
result.update({
'name': invoice.name,
'supplier_invoice_number': invoice.supplier_invoice_number})

return {'value': result}

Expand Down Expand Up @@ -389,20 +397,32 @@ 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.multi
def action_cancel_draft(self):
"""Restarting the workflow withholding vat.
The state is placed in draft.
"""
self.write({'state': 'draft'})
self.delete_workflow()
self.create_workflow()
return True

@api.model
Expand Down Expand Up @@ -617,7 +637,7 @@ def action_move_create(self):
"""
ctx = dict(self._context,
vat_wh=True,
company_id=self.env.user.company_id.idv)
company_id=self.env.user.company_id.id)
for ret in self.with_context(ctx):
for line in ret.wh_lines:
if line.move_id or line.invoice_id.wh_iva:
Expand Down
4 changes: 2 additions & 2 deletions l10n_ve_withholding_iva/view/wh_iva_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<button name="wh_iva_done" states="confirmed" string="Done" icon="gtk-execute"/>
<button name="%(withholding_vat)d" type="action" colspan="2" states="done" string="Print VAT Withholding" icon="gtk-execute"/>
<button name="cancel" colspan="2" states="confirmed,draft,done" string="Cancel" icon="gtk-cancel"/>
<button name="set_to_draft" colspan="2" states="cancel" string="Set to draft" icon="terp-stock_effects-object-colorize"/>
<button name="action_cancel_draft" colspan="2" states="cancel" string="Set to draft" type="object" icon="terp-stock_effects-object-colorize"/>
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,done" statusbar_colors="{&quot;confirmed&quot;:&quot;blue&quot;}"/>
</header>
<group colspan="4" col="6">
Expand Down Expand Up @@ -207,7 +207,7 @@
<button name="wh_iva_confirmed" states="draft" string="Confirm" icon="gtk-go-forward"/>
<button name="wh_iva_done" states="confirmed" string="Done" icon="gtk-execute"/>
<button name="cancel" states="confirmed,draft,done" string="Cancel" icon="gtk-cancel"/>
<button name="set_to_draft" states="cancel" string="Set to draft" icon="terp-stock_effects-object-colorize"/>
<button name="action_cancel_draft" colspan="2" states="cancel" string="Set to draft" type="object" icon="terp-stock_effects-object-colorize"/>
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,done" statusbar_colors="{&quot;confirmed&quot;:&quot;blue&quot;}"/>
</header>
<group colspan="4" col="6">
Expand Down
21 changes: 20 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 All @@ -21,5 +22,23 @@ object.action_wh_iva_create()</field>
<field name="child_ids" eval="[(4,ref(&quot;wh_iva_srv_act&quot;))]"/>
</record>
-->
<record id="filter_invoice_state_open_iva" model="ir.filters">
<field name="name">Invoice Open Withholding IVA</field>
<field name="model_id">account.invoice</field>
<field name="domain" eval="[('wh_iva_id', '=', False), ('state', '=', 'open')]"/>
<field name="context">{}</field>
<field name="user_id"></field>
</record>

<record id="wh_iva_act_rule" model="base.action.rule">
<field name="name">IVA Withholding Action Rule</field>
<field name="model_id" model="ir.model" search="[('model', '=', 'account.invoice')]"/>
<field name="active" eval="True"/>
<field name="sequence">1</field>
<field name="kind">on_write</field>
<field name="filter_id" ref="filter_invoice_state_open_iva"/>
<field name="server_action_ids"
eval="[(4, ref('wh_iva_srv_act')),]" />
</record>
</data>
</openerp>
3 changes: 3 additions & 0 deletions l10n_ve_withholding_iva/workflow/wh_iva_workflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<record id="act_draft" model="workflow.activity">
<field name="wkf_id" ref="wh_iva_order"/>
<field name="action">write({'state':'draft'})</field>
<field name="flow_start">True</field>
<field name="kind">function</field>
<field name="name">draft</field>
</record>
Expand All @@ -26,6 +27,7 @@
<field name="wkf_id" ref="wh_iva_order"/>
<field name="action">action_cancel()
write({'state':'cancel'})</field>
<field name="flow_stop">True</field>
<field name="kind">function</field>
<field name="name">cancel</field>
</record>
Expand All @@ -36,6 +38,7 @@
action_date_ret()
action_move_create()
write({'state':'done'})</field>
<field name="flow_stop">True</field>
<field name="kind">function</field>
<field name="name">done</field>
</record>
Expand Down

0 comments on commit 81a137c

Please sign in to comment.