Skip to content

Commit

Permalink
[REF] l10n_ve_withholding_src: Basic migration to v8
Browse files Browse the repository at this point in the history
  • Loading branch information
suniagajose committed Dec 17, 2015
1 parent 98ef148 commit 284342a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 49 deletions.
10 changes: 3 additions & 7 deletions l10n_ve_withholding_src/model/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _check_retention(self, cr, uid, ids, context=None):

_columns = {
'wh_src': fields.boolean(
'Social Responsibility Commitment Withheld',
'Social Responsibility Commitment Withheld', default=True,
help='if the commitment to social responsibility has been'
' retained'),
'wh_src_rate': fields.float(
Expand All @@ -88,9 +88,6 @@ def _check_retention(self, cr, uid, ids, context=None):
'account.wh.src', 'Wh. SRC Doc.', readonly=True,
help="Social Responsibility Commitment Withholding Document"),
}
_defaults = {
'wh_src': False,
}

_constraints = [
(_check_retention, _("Error ! Maximum retention is 5%"), []),
Expand Down Expand Up @@ -127,13 +124,12 @@ def _get_move_lines(self, cr, uid, ids, to_wh, period_id,

for tax_brw in to_wh:
acc = False
coll = tax_brw.wh_id.company_id.wh_src_collected_account_id
paid = tax_brw.wh_id.company_id.wh_src_paid_account_id
if types[invoice.type] == 1:
coll = tax_brw.wh_id.company_id.wh_src_collected_account_id
paid = tax_brw.wh_id.company_id.wh_src_paid_account_id
acc = coll and coll.id or False
else:
acc = paid and paid.id or False

if not acc:
raise osv.except_osv(
_('Missing Account in Company!'),
Expand Down
4 changes: 1 addition & 3 deletions l10n_ve_withholding_src/model/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class ResPartner(osv.osv):
help="Indicate if the partner is a SRC withholding agent"),
'wh_src_rate': fields.float(
string='SRC Rate', digits_compute=dp.get_precision('Withhold'),
default=0,
help="SRC Withholding rate"),
}
_defaults = {
'wh_src_rate': lambda *a: 0,
}
86 changes: 47 additions & 39 deletions l10n_ve_withholding_src/model/wh_src.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import time

from openerp import api
from openerp.addons import decimal_precision as dp
from openerp.osv import fields, osv
from openerp.tools.translate import _
Expand Down Expand Up @@ -115,6 +116,32 @@ def _get_wh_agent(self, cr, uid, ids, field_name, args, context=None):
context=context))
return res

def _get_company(self, cr, uid, context=None):
user = self.pool.get('res.users').browse(cr, uid, uid)
return user.company_id.id

def _get_currency(self, cr, uid, context=None):
user = self.pool.get('res.users').browse(cr, uid, uid)
return user.company_id.currency_id.id

def _get_journal(self, cr, uid, context=None):
"""
Return a SRC journal depending of invoice type
"""
context = dict(context or {})
type_inv = context.get('type', 'in_invoice')
type2journal = {'out_invoice': 'src_sale',
'in_invoice': 'src_purchase'}
journal_obj = self.pool.get('account.journal')
user = self.pool.get('res.users').browse(
cr, uid, uid, context=context)
company_id = context.get('company_id', user.company_id.id)
domain = [('company_id', '=', company_id)]
domain += [('type', '=', type2journal.get(
type_inv, 'src_purchase'))]
res = journal_obj.search(cr, uid, domain, limit=1)
return res and res[0] or False

_name = "account.wh.src"
_description = "Social Responsibility Commitment Withholding"
_columns = {
Expand All @@ -131,13 +158,15 @@ def _get_wh_agent(self, cr, uid, ids, field_name, args, context=None):
'type': fields.selection([
('out_invoice', 'Customer Invoice'),
('in_invoice', 'Supplier Invoice'),
], 'Type', readonly=False, help="Withholding type"),
], string='Type', readonly=False,
help="Withholding type"),
'state': fields.selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('done', 'Done'),
('cancel', 'Cancelled')
], 'Estado', readonly=True, help="Status Voucher"),
], string='Estado', readonly=True, default='draft',
help="Status Voucher"),
'date_ret': fields.date('Withholding date', readonly=True,
states={'draft': [('readonly', False)]},
help="Keep empty to use the current date"),
Expand All @@ -159,12 +188,18 @@ def _get_wh_agent(self, cr, uid, ids, field_name, args, context=None):
help="Withholding customer/supplier"),
'currency_id': fields.many2one(
'res.currency', 'Currency', required=True, readonly=True,
states={'draft': [('readonly', False)]}, help="Currency"),
states={'draft': [('readonly', False)]},
default=lambda s: s._get_currency(),
help="Currency"),
'journal_id': fields.many2one(
'account.journal', 'Journal', required=True, readonly=True,
states={'draft': [('readonly', False)]}, help="Journal entry"),
states={'draft': [('readonly', False)]},
default=lambda s: s._get_journal(),
help="Journal entry"),
'company_id': fields.many2one(
'res.company', 'Company', required=True, help="Company"),
'res.company', 'Company', required=True,
default=lambda s: s._get_company(),
help="Company"),
'line_ids': fields.one2many(
'account.wh.src.line', 'wh_id', 'Local withholding lines',
readonly=True, states={'draft': [('readonly', False)]},
Expand All @@ -184,35 +219,6 @@ def _get_wh_agent(self, cr, uid, ids, field_name, args, context=None):

}

def _get_journal(self, cr, uid, context=None):
"""
Return a SRC journal depending of invoice type
"""
context = dict(context or {})
type_inv = context.get('type', 'in_invoice')
type2journal = {'out_invoice': 'src_sale',
'in_invoice': 'src_purchase'}
journal_obj = self.pool.get('account.journal')
user = self.pool.get('res.users').browse(
cr, uid, uid, context=context)
company_id = context.get('company_id', user.company_id.id)
domain = [('company_id', '=', company_id)]
domain += [('type', '=', type2journal.get(
type_inv, 'src_purchase'))]
res = journal_obj.search(cr, uid, domain, limit=1)
return res and res[0] or False

_defaults = {
'state': lambda *a: 'draft',
'currency_id':
lambda self, cr, uid, c: self.pool.get('res.users').browse(
cr, uid, uid, c).company_id.currency_id.id,
'journal_id': _get_journal,
'company_id':
lambda self, cr, uid, c: self.pool.get('res.users').browse(
cr, uid, uid, c).company_id.id,
}

_sql_constraints = [
]

Expand Down Expand Up @@ -392,11 +398,15 @@ def action_cancel(self, cr, uid, ids, context=None):
self.clear_wh_lines(cr, uid, ids, context=context)
return True

def copy(self, cr, uid, ids, default=None, context=None):
@api.multi
def copy(self, default=None):
""" Lines can not be duplicated in this model
"""
# NOTE: use ids argument instead of id for fix the pylint error W0622.
# Redefining built-in 'id'
# NOTE: use ids argument instead of id for fix the pylint error W8106
# method-required-super.
if False:
return super(AccountWhSrc, self).copy(default)

raise osv.except_osv(
_('Invalid Procedure!'),
_("You can not duplicate lines"))
Expand Down Expand Up @@ -544,9 +554,7 @@ class AccountWhSrcLine(osv.osv):
'wh_src_rate': fields.float(
'Withholding Rate', help="Withholding rate"),
}
_defaults = {

}
_sql_constraints = [

]
Expand Down

0 comments on commit 284342a

Please sign in to comment.