Skip to content

Commit

Permalink
[REF] l10n_ve_withholding_islr: 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 74cee6e commit f79f091
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 125 deletions.
12 changes: 4 additions & 8 deletions l10n_ve_withholding_islr/model/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import openerp.addons as addons
from openerp.osv import fields, osv
from openerp.tools.translate import _


class WhIslrConfig(osv.osv_memory):
Expand Down Expand Up @@ -97,11 +96,13 @@ def execute(self, cr, uid, ids, context=None):

_columns = {
'journal_purchase': fields.char(
"Journal Wh Income Purchase", 64,
string="Journal Wh Income Purchase", size=64,
default="Journal Income Withholding Purchase",
help="Journal for purchase operations involving Income"
" Withholding"),
'journal_sale': fields.char(
"Journal Wh Income Sale", 64,
string="Journal Wh Income Sale", size=64,
default="Journal Income Withholding Sale",
help="Journal for sale operations involving Income Withholding"),
'account_purchase': fields.many2one(
"account.account",
Expand All @@ -118,9 +119,4 @@ def execute(self, cr, uid, ids, context=None):
help="Check if this company is a income withholding agent"),
}

_defaults = {
'journal_purchase': _("Journal Income Withholding Purchase"),
'journal_sale': _("Journal Income Withholding Sale"),
}

WhIslrConfig()
39 changes: 13 additions & 26 deletions l10n_ve_withholding_islr/model/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##############################################################################
from openerp import api
from openerp.osv import fields, osv
from openerp.tools.translate import _

Expand All @@ -34,7 +35,7 @@ class AccountInvoiceLine(osv.osv):
_inherit = "account.invoice.line"
_columns = {
'apply_wh': fields.boolean(
'Withheld',
string='Withheld', default=False,
help="Indicates whether a line has been retained or not, to"
" accumulate the amount to withhold next month, according"
" to the lines that have not been retained."),
Expand All @@ -46,9 +47,6 @@ class AccountInvoiceLine(osv.osv):
'state': fields.related('invoice_id', 'state', string='Current Status',
type='char', required=True, readonly=True),
}
_defaults = {
'apply_wh': lambda *a: False,
}

def islr_wh_change_concept(self, cr, uid, ids, context=None):
'''
Expand Down Expand Up @@ -78,11 +76,11 @@ def islr_wh_change_concept(self, cr, uid, ids, context=None):
'target': 'new',
}

def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='',
type='out_invoice', # pylint: disable=W0622
partner_id=False, fposition_id=False,
price_unit=False, currency_id=False, context=None,
company_id=None):
@api.multi
def product_id_change(
self, product, uom, qty=0, name='', type='out_invoice',
partner_id=False, fposition_id=False, price_unit=False,
currency_id=False, company_id=None):
""" Onchange information of the product invoice line
at once in the line of the bill
@param product: new product for the invoice line
Expand All @@ -95,20 +93,11 @@ def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='',
@param price_unit: new Unit Price for the invoice line
@param currency_id:
"""
context = context or {}
data = super(
AccountInvoiceLine, self).product_id_change(cr, uid, ids,
product, uom,
qty, name,
type, partner_id,
fposition_id,
price_unit,
currency_id,
context,
company_id)
data = super(AccountInvoiceLine, self).product_id_change(
product, uom, qty, name, type, partner_id, fposition_id,
price_unit, currency_id, company_id)
if product:
pro = self.pool.get('product.product').browse(
cr, uid, product, context=context)
pro = self.env['product.product'].browse(product)
data[data.keys()[1]]['concept_id'] = pro.concept_id.id
return data

Expand All @@ -132,7 +121,7 @@ class AccountInvoice(osv.osv):
('pro', 'Processed withholding, xml Line generated'),
('no_pro', 'Withholding no processed'),
('tasa', 'Not exceed the rate,xml Line generated'),
], 'Status', readonly=True,
], string='Status', readonly=True, default='no_pro',
help=''' * The \'Processed withholding, xml Line generated\' state
is used when a user is a withhold income is processed.
* The 'Withholding no processed\' state is when user create a
Expand All @@ -141,9 +130,7 @@ class AccountInvoice(osv.osv):
used when user create invoice,a invoice no exceed the
minimun rate.'''),
}
_defaults = {
'status': lambda *a: "no_pro",
}

# BEGIN OF REWRITING ISLR

def check_invoice_type(self, cr, uid, ids, context=None):
Expand Down
13 changes: 6 additions & 7 deletions l10n_ve_withholding_islr/model/islr_wh_concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class IslrWhConcept(osv.osv):
help="Name of Withholding Concept, Example: Honorarios"
" Profesionales, Comisiones a..."),
'withholdable': fields.boolean(
'Withhold',
string='Withhold', default=True,
help="Check if the concept withholding is withheld or not."),
'property_retencion_islr_payable': fields.property(
type='many2one',
Expand All @@ -66,11 +66,10 @@ class IslrWhConcept(osv.osv):
'islr.rates', 'concept_id', 'Rate',
help="Withholding Concept rate", required=False),
'user_id': fields.many2one(
'res.users', 'Salesman', readonly=True,
states={'draft': [('readonly', False)]}, help="Vendor user"),
}
_defaults = {
'withholdable': lambda *a: True,
'user_id': lambda s, cr, u, c: u,
'res.users', string='Salesman', readonly=True,
states={'draft': [('readonly', False)]},
default=lambda s: s._uid,
help="Vendor user"),
}

IslrWhConcept()
74 changes: 37 additions & 37 deletions l10n_ve_withholding_islr/model/islr_wh_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ def _get_amount_total(self, cr, uid, ids, name, args, context=None):
res[rete.id] += line.amount
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 retencion_seq_get(self, cr, uid, context=None):
""" Determinate the next sequence for islr withhold and returns.
"""
pool_seq = self.pool.get('ir.sequence')
cr.execute(
"select id,number_next,number_increment,prefix,suffix,padding"
" from ir_sequence where code='islr.wh.doc' and active=True")
res = cr.dictfetchone()
if res:
if res['number_next']:
return pool_seq._next(cr, uid, [res['id']])
else:
return pool_seq._process(res['prefix']) + pool_seq._process(
res['suffix'])
return False

_name = "islr.wh.doc"
_order = 'date_ret desc, number desc'
_description = 'Document Income Withholding'
Expand All @@ -104,8 +124,10 @@ def _get_amount_total(self, cr, uid, ids, name, args, context=None):
states={'draft': [('readonly', False)]}, required=True,
help="Voucher description"),
'code': fields.char(
'Code', size=32, readonly=True,
states={'draft': [('readonly', False)]}, help="Voucher reference"),
string='Code', size=32, readonly=True,
states={'draft': [('readonly', False)]},
default=lambda s: s.retencion_seq_get(),
help="Voucher reference"),
'number': fields.char(
'Withhold Number', size=32, readonly=True,
states={'draft': [('readonly', False)]}, help="Voucher reference"),
Expand All @@ -114,13 +136,16 @@ def _get_amount_total(self, cr, uid, ids, name, args, context=None):
('in_invoice', 'Supplier Invoice'),
('in_refund', 'Supplier Invoice Refund'),
('out_refund', 'Customer Invoice Refund'),
], 'Type', readonly=True, help="Voucher type"),
], string='Type', readonly=True,
default=lambda s: s._get_type(),
help="Voucher type"),
'state': fields.selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('done', 'Done'),
('cancel', 'Cancelled')
], 'State', readonly=True, help="Voucher state"),
], string='State', readonly=True, default='draft',
help="Voucher state"),
'date_ret': fields.date(
'Accounting Date', readonly=True,
states={'draft': [('readonly', False)]},
Expand All @@ -143,13 +168,16 @@ def _get_amount_total(self, cr, uid, ids, name, args, context=None):
'currency_id': fields.many2one(
'res.currency', 'Currency', required=True, readonly=True,
states={'draft': [('readonly', False)]},
default=lambda s: s._get_currency(),
help="Currency in which the transaction takes place"),
'journal_id': fields.many2one(
'account.journal', 'Journal', required=True, readonly=True,
states={'draft': [('readonly', False)]},
default=lambda s: s._get_journal(),
help="Journal where accounting entries are recorded"),
'company_id': fields.many2one(
'res.company', 'Company', required=True, readonly=True,
default=lambda s: s._get_company(),
help="Company"),
'amount_total_ret': fields.function(
_get_amount_total, method=True, string='Amount Total',
Expand All @@ -170,28 +198,16 @@ def _get_amount_total(self, cr, uid, ids, name, args, context=None):
' the bill'),
'user_id': fields.many2one(
'res.users', 'Salesman', readonly=True,
states={'draft': [('readonly', False)]}, help="Vendor user"),
states={'draft': [('readonly', False)]},
default=lambda s: s._uid,
help="Vendor user"),
'automatic_income_wh': fields.boolean(
'Automatic Income Withhold',
string='Automatic Income Withhold',
default=False,
help='When the whole process will be check automatically, '
'and if everything is Ok, will be set to done'),
}

_defaults = {
'code': (lambda obj, cr, uid, context:
obj.pool.get('islr.wh.doc').retencion_seq_get(
cr, uid, context)),
'type': _get_type,
'state': 'draft',
'journal_id': _get_journal,
'currency_id': _get_currency,
'company_id': lambda self, cr, uid, context:
self.pool.get('res.users').browse(cr, uid, uid,
context=context).company_id.id,
'user_id': lambda s, cr, u, c: u,
'automatic_income_wh': False,
}

def _check_partner(self, cr, uid, ids, context=None):
""" Determine if a given partner is a Income Withholding Agent
"""
Expand Down Expand Up @@ -357,22 +373,6 @@ def action_cancel_process(self, cr, uid, ids, context=None):

return True

def retencion_seq_get(self, cr, uid, context=None):
""" Determinate the next sequence for islr withhold and returns.
"""
pool_seq = self.pool.get('ir.sequence')
cr.execute(
"select id,number_next,number_increment,prefix,suffix,padding"
" from ir_sequence where code='islr.wh.doc' and active=True")
res = cr.dictfetchone()
if res:
if res['number_next']:
return pool_seq._next(cr, uid, [res['id']])
else:
return pool_seq._process(res['prefix']) + pool_seq._process(
res['suffix'])
return False

def onchange_partner_id(self, cr, uid, ids, inv_type, partner_id,
context=None):
""" Unlink all taxes when change the partner in the document.
Expand Down
53 changes: 24 additions & 29 deletions l10n_ve_withholding_islr/model/islr_xml_wh.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,29 @@ def _get_amount_total_base(self, cr, uid, ids, name, args, context=None):
res[xml.id] += line.base
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

_columns = {
'name': fields.char(
'Description', 128, required=True, select=True,
string='Description', size=128, required=True, select=True,
default='Income Withholding ' + time.strftime('%m/%Y'),
help="Description about statement of income withholding"),
'company_id': fields.many2one(
'res.company', 'Company', required=True, help="Company"),
'res.company', string='Company', required=True,
default=lambda s: s._get_company(),
help="Company"),
'state': fields.selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('done', 'Done'),
('cancel', 'Cancelled')
], 'State', readonly=True, help="Voucher state"),
], string='State', readonly=True, default='draft',
help="Voucher state"),
'period_id': fields.many2one(
'account.period', 'Period', required=True,
'account.period', string='Period', required=True,
default=lambda s: s.period_return(),
help="Period when the accounts entries were done"),
'amount_total_ret': fields.function(
_get_amount_total, method=True, digits=(16, 2), readonly=True,
Expand All @@ -97,22 +106,11 @@ def _get_amount_total_base(self, cr, uid, ids, name, args, context=None):
help='XML withhold employee line id',
domain=[('type', '=', 'employee')]),
'user_id': fields.many2one(
'res.users', 'User', readonly=True,
'res.users', string='User', readonly=True,
states={'draft': [('readonly', False)]},
default=lambda s: s._uid,
help='User Creating Document'),
}
_defaults = {
'state': lambda *a: 'draft',
'company_id': lambda self, cr, uid, context:
self.pool.get('res.users').browse(
cr, uid, uid, context=context).company_id.id,
'user_id': lambda s, cr, u, c: u,

'period_id': lambda self, cr, uid, context: self.period_return(
cr, uid, context),
'name': (lambda self, cr, uid, context:
'Income Withholding ' + time.strftime('%m/%Y'))
}

def copy(self, cr, uid, ids, default=None, context=None):
""" Initialized id by duplicating
Expand Down Expand Up @@ -330,9 +328,12 @@ class IslrXmlWhLine(osv.osv):
'VAT', size=10, required=True, help="Partner VAT"),
'invoice_number': fields.char(
'Invoice Number', size=10, required=True,
default='0',
help="Number of invoice"),
'control_number': fields.char(
'Control Number', size=8, required=True, help="Reference"),
'Control Number', size=8, required=True,
default='NA',
help="Reference"),
'concept_code': fields.char(
'Concept Code', size=10, required=True, help="Concept code"),
'base': fields.float(
Expand Down Expand Up @@ -379,16 +380,11 @@ class IslrXmlWhLine(osv.osv):
'date_ret': fields.date('Operation Date'),
'type': fields.selection(
ISLR_XML_WH_LINE_TYPES,
string='Type', required=True, readonly=False),
string='Type', required=True, readonly=False,
default='invoice'),
}
_rec_name = 'partner_id'

_defaults = {
'invoice_number': lambda *a: '0',
'control_number': lambda *a: 'NA',
'type': lambda *a: 'invoice',
}

def onchange_partner_vat(self, cr, uid, ids, partner_id, context=None):
""" Changing the partner, the partner_vat field is updated.
"""
Expand Down Expand Up @@ -416,9 +412,8 @@ class AccountInvoiceLine(osv.osv):

_columns = {
'wh_xml_id': fields.many2one(
'islr.xml.wh.line', 'XML Id', help="XML withhold line id"),
}
_defaults = {
'wh_xml_id': lambda *a: 0,
'islr.xml.wh.line', string='XML Id', default=0,
help="XML withhold line id"),
}

AccountInvoiceLine()
Loading

0 comments on commit f79f091

Please sign in to comment.