From 00495a0bf6e210e004310420ae06b85cf8ffc705 Mon Sep 17 00:00:00 2001 From: mtr Date: Wed, 13 Apr 2011 18:46:28 +0530 Subject: [PATCH 01/33] [IMP] hr_payroll_account: removed unrequired objects and added fields as per etherpad bzr revid: mtr@mtr-20110413131628-wp4km4zwuatfjn63 --- addons/hr_payroll_account/__openerp__.py | 2 +- .../hr_payroll_account/hr_payroll_account.py | 206 ++++++++++-------- .../hr_payroll_account_view.xml | 168 ++++++-------- 3 files changed, 184 insertions(+), 192 deletions(-) diff --git a/addons/hr_payroll_account/__openerp__.py b/addons/hr_payroll_account/__openerp__.py index 30dcd9e7b55..5134529901d 100644 --- a/addons/hr_payroll_account/__openerp__.py +++ b/addons/hr_payroll_account/__openerp__.py @@ -46,7 +46,7 @@ Generic Payroll system Integrated with Accountings. "hr_payroll_account_view.xml", ], 'demo_xml': [ - 'hr_payroll_demo.xml' +# 'hr_payroll_demo.xml' ], 'installable': True, 'active': False, diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 045063a7284..07d05fd5363 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -94,90 +94,90 @@ class hr_employee(osv.osv): } hr_employee() -class payroll_register(osv.osv): - _inherit = 'hr.payroll.register' - _description = 'Payroll Register' +#class payroll_register(osv.osv): +# _inherit = 'hr.payroll.register' +# _description = 'Payroll Register' +# +# _columns = { +# 'journal_id': fields.many2one('account.journal', 'Expense Journal'), +# 'bank_journal_id': fields.many2one('account.journal', 'Bank Journal'), +# 'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), +# } +# +# def compute_sheet(self, cr, uid, ids, context=None): +# emp_pool = self.pool.get('hr.employee') +# slip_pool = self.pool.get('hr.payslip') +# func_pool = self.pool.get('hr.payroll.structure') +# slip_line_pool = self.pool.get('hr.payslip.line') +# wf_service = netsvc.LocalService("workflow") +# vals = self.browse(cr, uid, ids, context=context)[0] +# emp_ids = emp_pool.search(cr, uid, []) +# +# for emp in emp_pool.browse(cr, uid, emp_ids, context=context): +# old_slips = slip_pool.search(cr, uid, [('employee_id','=', emp.id), ('date','=',vals.date)]) +# if old_slips: +# slip_pool.write(cr, uid, old_slips, {'register_id':ids[0]}) +# for sid in old_slips: +# wf_service.trg_validate(uid, 'hr.payslip', sid, 'compute_sheet', cr) +# else: +# res = { +# 'employee_id':emp.id, +# 'basic':0.0, +# 'register_id':ids[0], +# 'name':vals.name, +# 'date':vals.date, +# 'journal_id':vals.journal_id.id, +# 'bank_journal_id':vals.bank_journal_id.id +# } +# slip_id = slip_pool.create(cr, uid, res) +# wf_service.trg_validate(uid, 'hr.payslip', slip_id, 'compute_sheet', cr) +# +# number = self.pool.get('ir.sequence').get(cr, uid, 'salary.register') +# self.write(cr, uid, ids, {'state':'draft', 'number':number}) +# return True +# +#payroll_register() - _columns = { - 'journal_id': fields.many2one('account.journal', 'Expense Journal'), - 'bank_journal_id': fields.many2one('account.journal', 'Bank Journal'), - 'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), - } - - def compute_sheet(self, cr, uid, ids, context=None): - emp_pool = self.pool.get('hr.employee') - slip_pool = self.pool.get('hr.payslip') - func_pool = self.pool.get('hr.payroll.structure') - slip_line_pool = self.pool.get('hr.payslip.line') - wf_service = netsvc.LocalService("workflow") - vals = self.browse(cr, uid, ids, context=context)[0] - emp_ids = emp_pool.search(cr, uid, []) - - for emp in emp_pool.browse(cr, uid, emp_ids, context=context): - old_slips = slip_pool.search(cr, uid, [('employee_id','=', emp.id), ('date','=',vals.date)]) - if old_slips: - slip_pool.write(cr, uid, old_slips, {'register_id':ids[0]}) - for sid in old_slips: - wf_service.trg_validate(uid, 'hr.payslip', sid, 'compute_sheet', cr) - else: - res = { - 'employee_id':emp.id, - 'basic':0.0, - 'register_id':ids[0], - 'name':vals.name, - 'date':vals.date, - 'journal_id':vals.journal_id.id, - 'bank_journal_id':vals.bank_journal_id.id - } - slip_id = slip_pool.create(cr, uid, res) - wf_service.trg_validate(uid, 'hr.payslip', slip_id, 'compute_sheet', cr) - - number = self.pool.get('ir.sequence').get(cr, uid, 'salary.register') - self.write(cr, uid, ids, {'state':'draft', 'number':number}) - return True - -payroll_register() - -class payroll_advice(osv.osv): - _inherit = 'hr.payroll.advice' - _description = 'Bank Advice Note' - - _columns = { - 'account_id': fields.many2one('account.account', 'Account'), - } -payroll_advice() +#class payroll_advice(osv.osv): +# _inherit = 'hr.payroll.advice' +# _description = 'Bank Advice Note' +# +# _columns = { +# 'account_id': fields.many2one('account.account', 'Account'), +# } +#payroll_advice() class contrib_register(osv.osv): - _inherit = 'hr.contibution.register' + _inherit = 'hr.contribution.register' _description = 'Contribution Register' def _total_contrib(self, cr, uid, ids, field_names, arg, context=None): - line_pool = self.pool.get('hr.contibution.register.line') +# line_pool = self.pool.get('hr.contibution.register.line') period_id = self.pool.get('account.period').search(cr,uid,[('date_start','<=',time.strftime('%Y-%m-%d')),('date_stop','>=',time.strftime('%Y-%m-%d'))])[0] fiscalyear_id = self.pool.get('account.period').browse(cr, uid, period_id, context=context).fiscalyear_id res = {} - for cur in self.browse(cr, uid, ids, context=context): - current = line_pool.search(cr, uid, [('period_id','=',period_id),('register_id','=',cur.id)]) - years = line_pool.search(cr, uid, [('period_id.fiscalyear_id','=',fiscalyear_id.id), ('register_id','=',cur.id)]) - - e_month = 0.0 - c_month = 0.0 - for i in line_pool.browse(cr, uid, current, context=context): - e_month += i.emp_deduction - c_month += i.comp_deduction - - e_year = 0.0 - c_year = 0.0 - for j in line_pool.browse(cr, uid, years, context=context): - e_year += i.emp_deduction - c_year += i.comp_deduction - - res[cur.id]={ - 'monthly_total_by_emp':e_month, - 'monthly_total_by_comp':c_month, - 'yearly_total_by_emp':e_year, - 'yearly_total_by_comp':c_year - } +# for cur in self.browse(cr, uid, ids, context=context): +# current = line_pool.search(cr, uid, [('period_id','=',period_id),('register_id','=',cur.id)]) +# years = line_pool.search(cr, uid, [('period_id.fiscalyear_id','=',fiscalyear_id.id), ('register_id','=',cur.id)]) +# +# e_month = 0.0 +# c_month = 0.0 +# for i in line_pool.browse(cr, uid, current, context=context): +# e_month += i.emp_deduction +# c_month += i.comp_deduction +# +# e_year = 0.0 +# c_year = 0.0 +# for j in line_pool.browse(cr, uid, years, context=context): +# e_year += i.emp_deduction +# c_year += i.comp_deduction +# +# res[cur.id]={ +# 'monthly_total_by_emp':e_month, +# 'monthly_total_by_comp':c_month, +# 'yearly_total_by_emp':e_year, +# 'yearly_total_by_comp':c_year +# } return res _columns = { @@ -188,22 +188,22 @@ class contrib_register(osv.osv): } contrib_register() -class contrib_register_line(osv.osv): - _inherit = 'hr.contibution.register.line' - _description = 'Contribution Register Line' +#class contrib_register_line(osv.osv): +# _inherit = 'hr.contibution.register.line' +# _description = 'Contribution Register Line' +# +# _columns = { +# 'period_id': fields.many2one('account.period', 'Period'), +# } +#contrib_register_line() - _columns = { - 'period_id': fields.many2one('account.period', 'Period'), - } -contrib_register_line() - -class hr_holidays_status(osv.osv): - _inherit = 'hr.holidays.status' - _columns = { - 'account_id': fields.many2one('account.account', 'Account'), - 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'), - } -hr_holidays_status() +#class hr_holidays_status(osv.osv): +# _inherit = 'hr.holidays.status' +# _columns = { +# 'account_id': fields.many2one('account.account', 'Account'), +# 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'), +# } +#hr_holidays_status() class hr_payslip(osv.osv): ''' @@ -449,11 +449,11 @@ class hr_payslip(osv.osv): fiscal_year_objs = fiscalyear_pool.read(cr, uid, fiscal_year_ids, ['date_start','date_stop'], context=context) year_exist = False for fiscal_year in fiscal_year_objs: - if ((fiscal_year['date_start'] <= slip.date) and (fiscal_year['date_stop'] >= slip.date)): + if ((fiscal_year['date_start'] <= slip.date_from) and (fiscal_year['date_stop'] >= slip.date_to)): year_exist = True if not year_exist: raise osv.except_osv(_('Warning !'), _('Fiscal Year is not defined for slip date %s') % slip.date) - search_periods = period_pool.search(cr,uid,[('date_start','<=',slip.date),('date_stop','>=',slip.date)], context=context) + search_periods = period_pool.search(cr,uid,[('date_start','=',slip.date_from),('date_stop','=',slip.date_to)], context=context) if not search_periods: raise osv.except_osv(_('Warning !'), _('Period is not defined for slip date %s') % slip.date) period_id = search_periods[0] @@ -661,6 +661,17 @@ class hr_payslip_line(osv.osv): } hr_payslip_line() +class hr_salary_rule(osv.osv): + _inherit = 'hr.salary.rule' + _columns = { +# 'account_id': fields.many2one('account.account', 'General Account'), + 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'), + 'account_tax_id':fields.many2one('account.tax.code', 'Tax Code'), + 'account_debit': fields.many2one('account.account', 'Debit Account'), + 'account_credit': fields.many2one('account.account', 'Credit Account'), + } +hr_salary_rule() + class account_move_link_slip(osv.osv): ''' Account Move Link to Pay Slip @@ -675,4 +686,15 @@ class account_move_link_slip(osv.osv): } account_move_link_slip() +class hr_contract(osv.osv): + + _inherit = 'hr.contract' + _description = 'Employee Contract' + _columns = { + 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'), + 'journal_id': fields.many2one('account.journal', 'Journal'), + } +hr_contract() + + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_payroll_account/hr_payroll_account_view.xml b/addons/hr_payroll_account/hr_payroll_account_view.xml index d2ad309dc32..e290f94bcac 100644 --- a/addons/hr_payroll_account/hr_payroll_account_view.xml +++ b/addons/hr_payroll_account/hr_payroll_account_view.xml @@ -2,22 +2,6 @@ - - - hr.holidays.status.inherit1 - hr.holidays.status - - form - - - - - - - - - - hr.payslip.line.inherit.tree hr.payslip.line @@ -44,7 +28,7 @@ - + hr.payslip.inherit.form @@ -62,7 +46,7 @@ form - + @@ -87,51 +71,13 @@ - - hr.payroll.advice.inherit.form - hr.payroll.advice - - form + + hr.contribution.register.inherit.tree + hr.contribution.register + + tree - - - - - - - hr.payroll.register.inherit.tree - hr.payroll.register - - tree - - - - - - - - - - hr.payroll.register.inherit.form - hr.payroll.register - - form - - - - - - - - - - hr.contibution.register.inherit.tree - hr.contibution.register - - tree - - @@ -139,45 +85,35 @@ - hr.contibution.register.inherit.form - hr.contibution.register - + hr.contribution.register.inherit.form + hr.contribution.register + form - - - - + + + + + - - hr.contibution.register.inherit1.form - hr.contibution.register - + hr.payslip.form @@ -185,7 +121,7 @@ form - + @@ -203,18 +139,18 @@ - - - - - - + + + + + + - - + + - - + + @@ -251,5 +187,39 @@ + + + + hr.salary.rule.form.inherit + hr.salary.rule + + + + + + + + + + + + + + + + + hr.contract.view.form.inherit + hr.contract + form + + + + + + + + + + From a75715ec9740297bc4c3a44dc80fc7d8cde33ed6 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Thu, 14 Apr 2011 18:45:55 +0530 Subject: [PATCH 02/33] [IMP] Improved payslip report bzr revid: psi@tinyerp.co.in-20110414131555-6d5tgt5vwjt05rn2 --- addons/hr_payroll/report/report_payslip.py | 54 +- addons/hr_payroll/report/report_payslip.rml | 535 +++++++++++--------- 2 files changed, 353 insertions(+), 236 deletions(-) diff --git a/addons/hr_payroll/report/report_payslip.py b/addons/hr_payroll/report/report_payslip.py index 0e6f9137330..31f99607a1e 100644 --- a/addons/hr_payroll/report/report_payslip.py +++ b/addons/hr_payroll/report/report_payslip.py @@ -37,8 +37,8 @@ class payslip_report(report_sxw.rml_parse): 'get_deductions':self.get_deductions, 'get_leave': self.get_leave, 'get_payslip_lines': self.get_payslip_lines, -# 'get_details_by_salary_head': self.get_details_by_salary_head - }) + 'get_details_by_salary_head': self.get_details_by_salary_head, + }) def convert(self, amount, cur): amt_en = amount_to_text_en.amount_to_text(amount, 'en', cur) @@ -84,7 +84,7 @@ class payslip_report(report_sxw.rml_parse): date = datetime.strptime(obj.date, '%Y-%m-%d') res['mname']= date.strftime('%B')+"-"+date.strftime('%Y') return res['mname'] - + def get_payslip_lines(self, obj): payslip_line = self.pool.get('hr.payslip.line') res = [] @@ -96,6 +96,54 @@ class payslip_report(report_sxw.rml_parse): res = payslip_line.browse(self.cr, self.uid, ids) return res + def get_recursive_parent(self, heads): + if not heads: + return [] + if heads[0].parent_id: + heads.insert(0, heads[0].parent_id) + self.get_recursive_parent(heads) + return heads + + def get_details_by_salary_head(self, obj): + payslip_line = self.pool.get('hr.payslip.line') + salary_head = self.pool.get('hr.salary.head') + res = [] + result = {} + ids = [] + for id in range(len(obj)): + ids.append(obj[id].id) + if ids: + self.cr.execute('''SELECT pl.id, pl.category_id FROM hr_payslip_line as pl \ + LEFT JOIN hr_salary_head AS sh on (pl.category_id = sh.id) \ + WHERE pl.id in %s \ + GROUP BY sh.parent_id, sh.sequence, pl.sequence, pl.id, pl.category_id \ + ORDER BY sh.sequence, pl.sequence, sh.parent_id''',(tuple(ids),)) + for x in self.cr.fetchall(): + result.setdefault(x[1], []) + result[x[1]].append(x[0]) + for key, value in result.iteritems(): + heads = salary_head.browse(self.cr, self.uid, [key]) + parents = self.get_recursive_parent(heads) + level = 0 + for parent in parents: + res.append({ + 'salary_head': parent.name, + 'name': parent.name, + 'code': parent.code, + 'level': level + }) + level += 1 + lines = payslip_line.browse(self.cr, self.uid, value) + for line in lines: + res.append({ + 'salary_head': line.name, + 'name': line.name, + 'code': line.code, + 'total': line.total, + 'level': level + }) + return res + report_sxw.report_sxw('report.payslip.pdf', 'hr.payslip', 'hr_payroll/report/payslip.rml', parser=payslip_report) report_sxw.report_sxw('report.test.pdf', 'hr.payslip', 'hr_payroll/report/report_payslip.rml', parser=payslip_report) diff --git a/addons/hr_payroll/report/report_payslip.rml b/addons/hr_payroll/report/report_payslip.rml index a827ee3ce7b..31e71f9c98f 100644 --- a/addons/hr_payroll/report/report_payslip.rml +++ b/addons/hr_payroll/report/report_payslip.rml @@ -10,73 +10,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -96,248 +34,379 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - [[repeatIn(objects,'o')]] - + [[repeatIn(objects,'o')]] + - Pay Slip - - + Pay Slip + + + + + [[o.credit_note==False and removeParentNode('para')]] + Credit + + Note + + ([[o.name]]) + + + + Name + + + [[o.employee_id.name]] + + + Designation + + + [[ o.employee_id.contract_id and o.employee_id.contract_id.job_id.name or '' ]] + + + + + + + + Address - - - - - - - - Code - - - [[ o.employee_id.sinid or '' ]] - - - Name - - - [[o.employee_id.name]] + [[o.employee_id.address_home_id and o.employee_id.address_home_id.name or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.street or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.street2 or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.zip or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.city or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.state_id and o.employee_id.address_home_id.state_id.name or '' ]] [[o.employee_id.address_home_id and o.employee_id.address_home_id.country_id and o.employee_id.address_home_id.country_id.name or '' ]] - + - Address + Email - [[o.employee_id.address_home_id and o.employee_id.address_home_id.name or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.street or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.street2 or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.zip or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.city or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.state_id and o.employee_id.address_home_id.state_id.name or '' ]] [[o.employee_id.address_home_id and o.employee_id.address_home_id.country_id and o.employee_id.address_home_id.country_id.name or '' ]] + [[ o.employee_id.work_email or '' ]] + + + + Identification No + + + + [[ o.employee_id.identification_id or '' ]] - + - Email + Slip ID - [[ o.employee_id.work_email or '' ]] + [[ o.number or '' ]] - Bank Details + Bank Details - [[ o.employee_id.otherid or '' ]] + [[ o.employee_id.otherid or '' ]] - + - Slip ID + Date From - [[ o.number or '' ]] + [[ o.date_from or '']] - Identification No + + Date To + - [[ o.employee_id.passport_id and o.employee_id.passport_id.name or '' ]] + [[ o.date_to or '' ]] - - - - Register - - - [[ o.register_id and o.register_id.name or '' ]] - - - Designation - - - [[ o.employee_id.contract_id and o.employee_id.contract_id.job_id.name or '' ]] - - - - - - Payslip Lines - - - - - Sequence - - - Name - - - Code - - - Sub Total - - - - - [[repeatIn(get_payslip_lines(o.line_ids),'p') ]] [[ p.sequence ]] - - - [[ p.name ]] - - - [[ p.code ]] - - - [[ p.total ]] [[ o.company_id and o.company_id.currency_id.symbol or '' ]] - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - - - - - - + + - + Payslip Lines: + + + + + + + Code + + + Name + + + Amount (in [[o.company_id and o.company_id.currency_id.symbol or '']]) + + + +
+ [[repeatIn(get_payslip_lines(o.line_ids),'p') ]] + + + + [[ p.code ]] + + + [[ p.name ]] + + + [[ p.total or '0.0']] + + + +
+ + + + + + + Details By Salary Head: + + + + + + + Code + + + Salary Head + + + Name + + + Amount(in [[o.company_id and o.company_id.currency_id.symbol or '']]) + + + +
+ [[repeatIn(get_details_by_salary_head(o.line_ids),'h') ]] + + + + + [[ h['code'] ]] + [[ h['total'] and ( setTag('para','para',{'style':'terp_default_8'}))]] + + + + [[ '..'*h['level'] ]][[ h['salary_head'] ]][[ h['total'] and ( setTag('para','para',{'style':'terp_default_9'}))]] + + + [[ h['name'] ]][[ h['total'] and ( setTag('para','para',{'style':'terp_default_8'}))]] + + + [[ h['total'] ]] + + + +
+ + + + + + + + + + + + + - Authorized Signature + Authorized Signature - +
From 6550a55bb4160ac8f81ca8d6fb6b165fe249b148 Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 14 Apr 2011 19:03:15 +0530 Subject: [PATCH 03/33] [IMP] hr_payroll_account: improved code for the verify_sheet function bzr revid: mtr@mtr-20110414133315-3ecyexf2xngs2peb --- .../hr_payroll_account/hr_payroll_account.py | 63 ++++++++++++------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 07d05fd5363..d1ab3c10286 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -220,6 +220,20 @@ class hr_payslip(osv.osv): 'move_payment_ids':fields.many2many('account.move.line', 'payslip_payment_rel', 'slip_id', 'payment_id', 'Payment Lines', readonly=True), 'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), } + + def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): + result = super(hr_payslip, self).get_payslip_lines(cr, uid, contract_ids, payslip_id, context) + structure_ids = self.pool.get('hr.contract').get_all_structures(cr, uid, contract_ids, context=context) + #get the rules of the structure and thier children + rule_ids = self.pool.get('hr.payroll.structure').get_all_rules(cr, uid, structure_ids, context=context) + #run the rules by sequence + sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])] + + for rule in self.pool.get('hr.salary.rule').browse(cr, uid, sorted_rule_ids, context=context): + for value in result: + if value['salary_rule_id'] == rule.id: + value['account_id'] = rule.account_debit.id, + return result def create_voucher(self, cr, uid, ids, name, voucher, sequence=5): slip_move = self.pool.get('hr.payslip.account.move') @@ -419,6 +433,9 @@ class hr_payslip(osv.osv): payslip_pool = self.pool.get('hr.payslip.line') for slip in self.browse(cr, uid, ids, context=context): + for line in slip.line_ids: + if line.category_id.name == 'Basic': + basic_amt = line.total if not slip.journal_id: # Call super method to verify sheet if journal_id is not specified. super(hr_payslip, self).verify_sheet(cr, uid, [slip.id], context=context) @@ -461,7 +478,7 @@ class hr_payslip(osv.osv): move = { 'journal_id': slip.journal_id.id, 'period_id': period_id, - 'date': slip.date, + 'date': slip.date_from, 'ref':slip.number, 'narration': slip.name } @@ -474,11 +491,11 @@ class hr_payslip(osv.osv): line = { 'move_id':move_id, 'name': "By Basic Salary / " + slip.employee_id.name, - 'date': slip.date, + 'date': slip.date_from, 'account_id': slip.employee_id.salary_account.id, - 'debit': slip.basic, + 'debit': basic_amt, 'credit': 0.0, - 'quantity':slip.working_days, +# 'quantity':slip.working_days, 'journal_id': slip.journal_id.id, 'period_id': period_id, 'analytic_account_id': False, @@ -499,11 +516,11 @@ class hr_payslip(osv.osv): 'move_id':move_id, 'name': "To Basic Payble Salary / " + slip.employee_id.name, 'partner_id': partner_id, - 'date': slip.date, + 'date': slip.date_from, 'account_id': slip.employee_id.employee_account.id, 'debit': 0.0, - 'quantity':slip.working_days, - 'credit': slip.basic, +# 'quantity':slip.working_days, + 'credit': basic_amt, 'journal_id': slip.journal_id.id, 'period_id': period_id, 'ref':slip.number @@ -514,13 +531,13 @@ class hr_payslip(osv.osv): name = "[%s] - %s / %s" % (line.code, line.name, slip.employee_id.name) amount = line.total - if line.type == 'leaves': - continue +# if line.type == 'leaves': +# continue rec = { 'move_id': move_id, 'name': name, - 'date': slip.date, + 'date': slip.date_from, 'account_id': line.account_id.id, 'debit': 0.0, 'credit': 0.0, @@ -534,10 +551,11 @@ class hr_payslip(osv.osv): #Setting Analysis Account for Salary Slip Lines if line.analytic_account_id: rec['analytic_account_id'] = line.analytic_account_id.id - else: - rec['analytic_account_id'] = slip.deg_id.account_id.id +# else: +# rec['analytic_account_id'] = slip.deg_id.account_id.id - if line.type == 'allowance' or line.type == 'otherpay': +# if line.type == 'allowance' or line.type == 'otherpay': + if line.category_id.name == 'Allowance' : rec['debit'] = amount if not partner.property_account_payable: raise osv.except_osv(_('Integrity Error !'), _('Please Configure Partners Payable Account!!')) @@ -545,7 +563,7 @@ class hr_payslip(osv.osv): 'move_id': move_id, 'name': name, 'partner_id': partner_id, - 'date': slip.date, + 'date': slip.date_from, 'account_id': partner.property_account_payable.id, 'debit': 0.0, 'quantity': 1, @@ -555,7 +573,7 @@ class hr_payslip(osv.osv): 'ref': slip.number } line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] - elif line.type == 'deduction' or line.type == 'otherdeduct': + elif line.category_id.name == 'Deduction': if not partner.property_account_receivable: raise osv.except_osv(_('Integrity Error !'), _('Please Configure Partners Receivable Account!!')) rec['credit'] = amount @@ -564,7 +582,7 @@ class hr_payslip(osv.osv): 'move_id': move_id, 'name': name, 'partner_id': partner_id, - 'date': slip.date, + 'date': slip.date_from, 'quantity': 1, 'account_id': partner.property_account_receivable.id, 'debit': amount, @@ -574,9 +592,7 @@ class hr_payslip(osv.osv): 'ref': slip.number } line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] - line_ids += [movel_pool.create(cr, uid, rec, context=context)] - # if self._debug: # for contrib in line.category_id.contribute_ids: # _log.debug("%s %s %s %s %s", contrib.name, contrub.code, contrub.amount_type, contrib.contribute_per, line.total) @@ -586,7 +602,7 @@ class hr_payslip(osv.osv): move = { 'journal_id': slip.journal_id.id, 'period_id': period_id, - 'date': slip.date, + 'date': slip.date_from, 'ref':slip.number, 'narration': 'Adjustment: %s' % (slip.name) } @@ -598,7 +614,7 @@ class hr_payslip(osv.osv): 'move_id': adj_move_id, 'name': name, 'partner_id': partner_id, - 'date': slip.date, + 'date': slip.date_from, 'account_id': partner.property_account_receivable.id, 'debit': 0.0, 'quantity': 1, @@ -612,7 +628,7 @@ class hr_payslip(osv.osv): 'move_id': adj_move_id, 'name': name, 'partner_id': partner_id, - 'date': slip.date, + 'date': slip.date_from, 'account_id': partner.property_account_payable.id, 'debit': total_deduct, 'quantity': 1, @@ -630,8 +646,8 @@ class hr_payslip(osv.osv): if not slip.period_id: rec['period_id'] = period_id - dates = prev_bounds(slip.date) - exp_ids = exp_pool.search(cr, uid, [('date_valid','>=',dates[0]), ('date_valid','<=',dates[1]), ('state','=','invoiced')], context=context) +# dates = prev_bounds(slip.date) + exp_ids = exp_pool.search(cr, uid, [('date_valid','>=',slip.date_from), ('date_valid','<=',slip.date_to), ('state','=','invoiced')], context=context) if exp_ids: acc = property_pool.get(cr, uid, 'property_account_expense_categ', 'product.category') for exp in exp_pool.browse(cr, uid, exp_ids, context=context): @@ -648,7 +664,6 @@ class hr_payslip(osv.osv): payslip_pool.create(cr, uid, exp_res, context=context) self.write(cr, uid, [slip.id], rec, context=context) - return True hr_payslip() From 34e9bed678b095d8abd2f4feb376f7f01a8efb28 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Fri, 15 Apr 2011 11:11:45 +0530 Subject: [PATCH 04/33] [FIX] remove warning of keyError bzr revid: psi@tinyerp.co.in-20110415054145-m3w71j5837v0su2j --- addons/hr_payroll/report/report_payslip.rml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/hr_payroll/report/report_payslip.rml b/addons/hr_payroll/report/report_payslip.rml index 31e71f9c98f..58d558f42cb 100644 --- a/addons/hr_payroll/report/report_payslip.rml +++ b/addons/hr_payroll/report/report_payslip.rml @@ -370,17 +370,17 @@ [[ h['code'] ]] - [[ h['total'] and ( setTag('para','para',{'style':'terp_default_8'}))]] + [[ h.get('total', False) and ( setTag('para','para',{'style':'terp_default_8'})) or removeParentNode('font') ]] - [[ '..'*h['level'] ]][[ h['salary_head'] ]][[ h['total'] and ( setTag('para','para',{'style':'terp_default_9'}))]] + [[ '..'*h['level'] ]][[ h['salary_head'] ]][[ h.get('total', False) and ( setTag('para','para',{'style':'terp_default_9'})) or removeParentNode('font') ]] - [[ h['name'] ]][[ h['total'] and ( setTag('para','para',{'style':'terp_default_8'}))]] + [[ h['name'] ]][[ h.get('total', False) and ( setTag('para','para',{'style':'terp_default_8'})) or removeParentNode('font') ]] - [[ h['total'] ]] + [[ h['total'] ]] From 5fa182ab0069ad6dfe459be05b99318521c251b7 Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 18 Apr 2011 17:57:08 +0530 Subject: [PATCH 05/33] [IMP] hr_payroll_account: demo data and code for the verify_sheet,process_sheet function bzr revid: mtr@mtr-20110418122708-qeb452wyl9gk18q4 --- addons/hr_payroll/hr_payroll.py | 4 +- addons/hr_payroll_account/__openerp__.py | 2 +- .../hr_payroll_account/hr_payroll_account.py | 148 +++++++++--------- addons/hr_payroll_account/hr_payroll_demo.xml | 48 ++++-- 4 files changed, 116 insertions(+), 86 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 6757b57c417..dfd748d42ae 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -399,6 +399,8 @@ class hr_payslip(osv.osv): def compute_sheet(self, cr, uid, ids, context=None): slip_line_pool = self.pool.get('hr.payslip.line') + sequence_obj = self.pool.get('ir.sequence') + number = sequence_obj.get(cr, uid, 'salary.slip') for payslip in self.browse(cr, uid, ids, context=context): #delete old payslip lines old_slipline_ids = slip_line_pool.search(cr, uid, [('slip_id', '=', payslip.id)], context=context) @@ -412,7 +414,7 @@ class hr_payslip(osv.osv): #if we don't give the contract, then the rules to apply should be for all current contracts of the employee contract_ids = self.get_contract(cr, uid, payslip.employee_id, payslip.date_from, payslip.date_to, context=context) lines = [(0,0,line) for line in self.pool.get('hr.payslip').get_payslip_lines(cr, uid, contract_ids, payslip.id, context=context)] - self.write(cr, uid, [payslip.id], {'line_ids': lines}, context=context) + self.write(cr, uid, [payslip.id], {'line_ids': lines, 'number': number,}, context=context) return True def get_input_lines(self, cr, uid, contract_ids, date_from, date_to, context=None): diff --git a/addons/hr_payroll_account/__openerp__.py b/addons/hr_payroll_account/__openerp__.py index 5134529901d..30dcd9e7b55 100644 --- a/addons/hr_payroll_account/__openerp__.py +++ b/addons/hr_payroll_account/__openerp__.py @@ -46,7 +46,7 @@ Generic Payroll system Integrated with Accountings. "hr_payroll_account_view.xml", ], 'demo_xml': [ -# 'hr_payroll_demo.xml' + 'hr_payroll_demo.xml' ], 'installable': True, 'active': False, diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index d1ab3c10286..8939c5b5e6e 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -234,7 +234,7 @@ class hr_payslip(osv.osv): if value['salary_rule_id'] == rule.id: value['account_id'] = rule.account_debit.id, return result - + def create_voucher(self, cr, uid, ids, name, voucher, sequence=5): slip_move = self.pool.get('hr.payslip.account.move') for slip in ids: @@ -281,18 +281,22 @@ class hr_payslip(osv.osv): partner = slip.employee_id.bank_account_id.partner_id partner_id = partner.id - + + for line in slip.line_ids: + if line.category_id.name == 'Net': + amt = line.total + fiscal_year_ids = fiscalyear_pool.search(cr, uid, [], context=context) if not fiscal_year_ids: raise osv.except_osv(_('Warning !'), _('Please define fiscal year for perticular contract')) fiscal_year_objs = fiscalyear_pool.read(cr, uid, fiscal_year_ids, ['date_start','date_stop'], context=context) year_exist = False for fiscal_year in fiscal_year_objs: - if ((fiscal_year['date_start'] <= slip.date) and (fiscal_year['date_stop'] >= slip.date)): + if ((fiscal_year['date_start'] <= slip.date_from) and (fiscal_year['date_stop'] >= slip.date_to)): year_exist = True if not year_exist: raise osv.except_osv(_('Warning !'), _('Fiscal Year is not defined for slip date %s') % slip.date) - search_periods = period_pool.search(cr, uid, [('date_start','<=',slip.date),('date_stop','>=',slip.date)], context=context) + search_periods = period_pool.search(cr, uid, [('date_start','<=',slip.date_from),('date_stop','>=',slip.date_to)], context=context) if not search_periods: raise osv.except_osv(_('Warning !'), _('Period is not defined for slip date %s') % slip.date) period_id = search_periods[0] @@ -300,7 +304,7 @@ class hr_payslip(osv.osv): move = { 'journal_id': slip.bank_journal_id.id, 'period_id': period_id, - 'date': slip.date, + 'date': slip.date_from, 'type':'bank_pay_voucher', 'ref':slip.number, 'narration': name @@ -316,10 +320,10 @@ class hr_payslip(osv.osv): ded_rec = { 'move_id': move_id, 'name': name, - 'date': slip.date, + 'date': slip.date_from, 'account_id': slip.employee_id.property_bank_account.id, 'debit': 0.0, - 'credit': slip.total_pay, + 'credit': amt, 'journal_id': slip.journal_id.id, 'period_id': period_id, 'ref': slip.number @@ -330,9 +334,9 @@ class hr_payslip(osv.osv): 'move_id': move_id, 'name': name, 'partner_id': partner_id, - 'date': slip.date, + 'date': slip.date_from, 'account_id': partner.property_account_payable.id, - 'debit': slip.total_pay, + 'debit': amt, 'credit': 0.0, 'journal_id': slip.journal_id.id, 'period_id': period_id, @@ -340,69 +344,69 @@ class hr_payslip(osv.osv): } line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)] - other_pay = slip.other_pay +# other_pay = slip.other_pay #Process all Reambuse Entries - for line in slip.line_ids: - if line.type == 'otherpay' and line.expanse_id.invoice_id: - if not line.expanse_id.invoice_id.move_id: - raise osv.except_osv(_('Warning !'), _('Please Confirm all Expense Invoice appear for Reimbursement')) - invids = [line.expanse_id.invoice_id.id] - amount = line.total - acc_id = slip.bank_journal_id.default_credit_account_id and slip.bank_journal_id.default_credit_account_id.id - period_id = slip.period_id.id - journal_id = slip.bank_journal_id.id - name = '[%s]-%s' % (slip.number, line.name) - invoice_pool.pay_and_reconcile(cr, uid, invids, amount, acc_id, period_id, journal_id, False, period_id, False, context, name) - other_pay -= amount - #TODO: link this account entries to the Payment Lines also Expense Entries to Account Lines - l_ids = movel_pool.search(cr, uid, [('name','=',name)], context=context) - line_ids += l_ids - - l_ids = movel_pool.search(cr, uid, [('invoice','=',line.expanse_id.invoice_id.id)], context=context) - exp_ids += l_ids +# for line in slip.line_ids: +# if line.type == 'otherpay' and line.expanse_id.invoice_id: +# if not line.expanse_id.invoice_id.move_id: +# raise osv.except_osv(_('Warning !'), _('Please Confirm all Expense Invoice appear for Reimbursement')) +# invids = [line.expanse_id.invoice_id.id] +# amount = line.total +# acc_id = slip.bank_journal_id.default_credit_account_id and slip.bank_journal_id.default_credit_account_id.id +# period_id = slip.period_id.id +# journal_id = slip.bank_journal_id.id +# name = '[%s]-%s' % (slip.number, line.name) +# invoice_pool.pay_and_reconcile(cr, uid, invids, amount, acc_id, period_id, journal_id, False, period_id, False, context, name) +# other_pay -= amount +# #TODO: link this account entries to the Payment Lines also Expense Entries to Account Lines +# l_ids = movel_pool.search(cr, uid, [('name','=',name)], context=context) +# line_ids += l_ids +# +# l_ids = movel_pool.search(cr, uid, [('invoice','=',line.expanse_id.invoice_id.id)], context=context) +# exp_ids += l_ids #Process for Other payment if any - other_move_id = False - if slip.other_pay > 0: - narration = 'Payment of Other Payeble amounts to %s' % (slip.employee_id.name) - move = { - 'journal_id': slip.bank_journal_id.id, - 'period_id': period_id, - 'date': slip.date, - 'type':'bank_pay_voucher', - 'ref':slip.number, - 'narration': narration - } - other_move_id = move_pool.create(cr, uid, move, context=context) - self.create_voucher(cr, uid, [slip.id], narration, move_id) - - name = "To %s account" % (slip.employee_id.name) - ded_rec = { - 'move_id':other_move_id, - 'name':name, - 'date':slip.date, - 'account_id':slip.employee_id.property_bank_account.id, - 'debit': 0.0, - 'credit': other_pay, - 'journal_id':slip.journal_id.id, - 'period_id':period_id, - 'ref':slip.number - } - line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] - name = "By %s account" % (slip.employee_id.property_bank_account.name) - cre_rec = { - 'move_id':other_move_id, - 'name':name, - 'partner_id':partner_id, - 'date':slip.date, - 'account_id':partner.property_account_payable.id, - 'debit': other_pay, - 'credit':0.0, - 'journal_id':slip.journal_id.id, - 'period_id':period_id, - 'ref':slip.number - } - line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)] +# other_move_id = False +# if slip.other_pay > 0: +# narration = 'Payment of Other Payeble amounts to %s' % (slip.employee_id.name) +# move = { +# 'journal_id': slip.bank_journal_id.id, +# 'period_id': period_id, +# 'date': slip.date_from, +# 'type':'bank_pay_voucher', +# 'ref':slip.number, +# 'narration': narration +# } +# other_move_id = move_pool.create(cr, uid, move, context=context) +# self.create_voucher(cr, uid, [slip.id], narration, move_id) +# +# name = "To %s account" % (slip.employee_id.name) +# ded_rec = { +# 'move_id':other_move_id, +# 'name':name, +# 'date':slip.date_from, +# 'account_id':slip.employee_id.property_bank_account.id, +# 'debit': 0.0, +# 'credit': other_pay, +# 'journal_id':slip.journal_id.id, +# 'period_id':period_id, +# 'ref':slip.number +# } +# line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] +# name = "By %s account" % (slip.employee_id.property_bank_account.name) +# cre_rec = { +# 'move_id':other_move_id, +# 'name':name, +# 'partner_id':partner_id, +# 'date':slip.date_from, +# 'account_id':partner.property_account_payable.id, +# 'debit': other_pay, +# 'credit':0.0, +# 'journal_id':slip.journal_id.id, +# 'period_id':period_id, +# 'ref':slip.number +# } +# line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)] rec = { 'state':'done', @@ -501,7 +505,6 @@ class hr_payslip(osv.osv): 'analytic_account_id': False, 'ref':slip.number } - #Setting Analysis Account for Basic Salary if slip.employee_id.analytic_account: line['analytic_account_id'] = slip.employee_id.analytic_account.id @@ -528,6 +531,8 @@ class hr_payslip(osv.osv): line_ids += [movel_pool.create(cr, uid, line, context=context)] for line in slip.line_ids: + if line.name == 'Net' or line.name == 'Gross' or line.name == 'Basic': + continue name = "[%s] - %s / %s" % (line.code, line.name, slip.employee_id.name) amount = line.total @@ -576,6 +581,7 @@ class hr_payslip(osv.osv): elif line.category_id.name == 'Deduction': if not partner.property_account_receivable: raise osv.except_osv(_('Integrity Error !'), _('Please Configure Partners Receivable Account!!')) + amount = -(amount) rec['credit'] = amount total_deduct += amount ded_rec = { @@ -596,7 +602,6 @@ class hr_payslip(osv.osv): # if self._debug: # for contrib in line.category_id.contribute_ids: # _log.debug("%s %s %s %s %s", contrib.name, contrub.code, contrub.amount_type, contrib.contribute_per, line.total) - adj_move_id = False if total_deduct > 0: move = { @@ -662,7 +667,6 @@ class hr_payslip(osv.osv): 'account_id':acc } payslip_pool.create(cr, uid, exp_res, context=context) - self.write(cr, uid, [slip.id], rec, context=context) return True diff --git a/addons/hr_payroll_account/hr_payroll_demo.xml b/addons/hr_payroll_account/hr_payroll_demo.xml index 2875c2c03c5..1483015e9b4 100644 --- a/addons/hr_payroll_account/hr_payroll_demo.xml +++ b/addons/hr_payroll_account/hr_payroll_demo.xml @@ -2,31 +2,55 @@ - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + X110041 From 566c5c7a8c54a48c211a862d8dc9463bda4fd91f Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 18 Apr 2011 19:06:42 +0530 Subject: [PATCH 06/33] [IMP] hr_payroll: improved code for payslip reference bzr revid: mtr@mtr-20110418133642-8xn0ka4bkwrty241 --- addons/hr_payroll/hr_payroll.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index dfd748d42ae..45826254df5 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -400,8 +400,8 @@ class hr_payslip(osv.osv): def compute_sheet(self, cr, uid, ids, context=None): slip_line_pool = self.pool.get('hr.payslip.line') sequence_obj = self.pool.get('ir.sequence') - number = sequence_obj.get(cr, uid, 'salary.slip') for payslip in self.browse(cr, uid, ids, context=context): + number = sequence_obj.get(cr, uid, 'salary.slip') #delete old payslip lines old_slipline_ids = slip_line_pool.search(cr, uid, [('slip_id', '=', payslip.id)], context=context) old_slipline_ids From 148c73acb1877a09b1c847bc2d6c3e6f84471bba Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 19 Apr 2011 12:32:04 +0530 Subject: [PATCH 07/33] [IMP] hr_payroll_account: improved code to assign the account(if empty) on salary rules from payslip journal bzr revid: mtr@mtr-20110419070204-r3xaby5fl7rl1e80 --- .../hr_payroll_account/hr_payroll_account.py | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 8939c5b5e6e..bce878d521e 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -222,17 +222,32 @@ class hr_payslip(osv.osv): } def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): + journal_obj = self.pool.get('account.journal') + rule_obj = self.pool.get('hr.salary.rule') + contract_obj = self.pool.get('hr.contract') + structure_obj = self.pool.get('hr.payroll.structure') + vals_account = {} result = super(hr_payslip, self).get_payslip_lines(cr, uid, contract_ids, payslip_id, context) - structure_ids = self.pool.get('hr.contract').get_all_structures(cr, uid, contract_ids, context=context) + structure_ids = contract_obj.get_all_structures(cr, uid, contract_ids, context=context) #get the rules of the structure and thier children - rule_ids = self.pool.get('hr.payroll.structure').get_all_rules(cr, uid, structure_ids, context=context) - #run the rules by sequence + rule_ids = structure_obj.get_all_rules(cr, uid, structure_ids, context=context) sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])] - - for rule in self.pool.get('hr.salary.rule').browse(cr, uid, sorted_rule_ids, context=context): + journal_id = [record.journal_id.id for record in self.browse(cr, uid, [payslip_id], context=context)] + for jou in journal_obj.browse(cr ,uid, journal_id, context=context): + credit_account = jou.default_credit_account_id.id + debit_account = jou.default_debit_account_id.id + for rule in rule_obj.browse(cr, uid, sorted_rule_ids, context=context): + if not rule.account_debit.id: + vals_account['account_debit'] = debit_account + if not rule.account_credit.id: + vals_account['account_credit'] = credit_account + rule_obj.write(cr, uid, [rule.id], vals_account) for value in result: if value['salary_rule_id'] == rule.id: - value['account_id'] = rule.account_debit.id, + if not rule.account_debit.id: + value['account_id'] = debit_account + else: + value['account_id'] = rule.account_debit.id return result def create_voucher(self, cr, uid, ids, name, voucher, sequence=5): From 5051b21ea4f94bbb6386e0e724659edad6c0b56f Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 19 Apr 2011 18:14:01 +0530 Subject: [PATCH 08/33] [IMP] hr_payroll_account: improved code to assign credit/debit account on payslip line bzr revid: mtr@mtr-20110419124401-fpn4kxijz74xxhbu --- .../hr_payroll_account/hr_payroll_account.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index bce878d521e..81e3c9911ca 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -238,16 +238,24 @@ class hr_payslip(osv.osv): debit_account = jou.default_debit_account_id.id for rule in rule_obj.browse(cr, uid, sorted_rule_ids, context=context): if not rule.account_debit.id: - vals_account['account_debit'] = debit_account + rule_obj.write(cr, uid, [rule.id], {'account_debit': debit_account}) if not rule.account_credit.id: - vals_account['account_credit'] = credit_account - rule_obj.write(cr, uid, [rule.id], vals_account) + rule_obj.write(cr, uid, [rule.id], {'account_credit': credit_account}) for value in result: if value['salary_rule_id'] == rule.id: - if not rule.account_debit.id: - value['account_id'] = debit_account + if rule.category_id.name == 'Deduction': + if not rule.account_debit.id: + value['account_id'] = debit_account + else: + value['account_id'] = rule.account_debit.id + elif rule.category_id.name == 'Allowance': + if not rule.account_credit.id: + value['account_id'] = credit_account + else: + value['account_id'] = rule.account_credit.id else: - value['account_id'] = rule.account_debit.id + emp_account_id = [record.employee_id.employee_account.id for record in self.browse(cr, uid, [payslip_id], context=context)] + value['account_id'] = emp_account_id[0] return result def create_voucher(self, cr, uid, ids, name, voucher, sequence=5): From fa908b5e00e33ce370722ab4ba12b0b650ef607e Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 19 Apr 2011 18:16:37 +0530 Subject: [PATCH 09/33] [IMP] hr_payroll_account: commented code, creating hr.expense.expense as payslip line bzr revid: mtr@mtr-20110419124637-p96wnqvwbfm3uhv1 --- .../hr_payroll_account/hr_payroll_account.py | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 81e3c9911ca..51c6ab22d0a 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -676,20 +676,20 @@ class hr_payslip(osv.osv): # dates = prev_bounds(slip.date) exp_ids = exp_pool.search(cr, uid, [('date_valid','>=',slip.date_from), ('date_valid','<=',slip.date_to), ('state','=','invoiced')], context=context) - if exp_ids: - acc = property_pool.get(cr, uid, 'property_account_expense_categ', 'product.category') - for exp in exp_pool.browse(cr, uid, exp_ids, context=context): - exp_res = { - 'name':exp.name, - 'amount_type':'fix', - 'type':'otherpay', - 'category_id':exp.category_id.id, - 'amount':exp.amount, - 'slip_id':slip.id, - 'expanse_id':exp.id, - 'account_id':acc - } - payslip_pool.create(cr, uid, exp_res, context=context) +# if exp_ids: +# acc = property_pool.get(cr, uid, 'property_account_expense_categ', 'product.category') +# for exp in exp_pool.browse(cr, uid, exp_ids, context=context): +# exp_res = { +# 'name':exp.name, +# 'amount_type':'fix', +# 'type':'otherpay', +# 'category_id':exp.category_id.id, +# 'amount':exp.amount, +# 'slip_id':slip.id, +# 'expanse_id':exp.id, +# 'account_id':acc +# } +# payslip_pool.create(cr, uid, exp_res, context=context) self.write(cr, uid, [slip.id], rec, context=context) return True From eb36f0c7269c009f06851d51b10bae9f0ae28d32 Mon Sep 17 00:00:00 2001 From: mtr Date: Wed, 20 Apr 2011 14:20:11 +0530 Subject: [PATCH 10/33] [IMP] hr_payroll_account: commented unrequired prev_bounds() method bzr revid: mtr@mtr-20110420085011-sujli3n7xeab22r3 --- .../hr_payroll_account/hr_payroll_account.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 51c6ab22d0a..cac642027af 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -27,17 +27,17 @@ from osv import fields, osv from tools import config from tools.translate import _ -def prev_bounds(cdate=False): - when = date.fromtimestamp(time.mktime(time.strptime(cdate,"%Y-%m-%d"))) - this_first = date(when.year, when.month, 1) - month = when.month + 1 - year = when.year - if month > 12: - month = 1 - year += 1 - next_month = date(year, month, 1) - prev_end = next_month - timedelta(days=1) - return this_first, prev_end +#def prev_bounds(cdate=False): +# when = date.fromtimestamp(time.mktime(time.strptime(cdate,"%Y-%m-%d"))) +# this_first = date(when.year, when.month, 1) +# month = when.month + 1 +# year = when.year +# if month > 12: +# month = 1 +# year += 1 +# next_month = date(year, month, 1) +# prev_end = next_month - timedelta(days=1) +# return this_first, prev_end class hr_payroll_structure(osv.osv): _inherit = 'hr.payroll.structure' From 2447cd56ddb1306c0b8e6816e5a490c87d7d0326 Mon Sep 17 00:00:00 2001 From: mtr Date: Wed, 20 Apr 2011 14:25:19 +0530 Subject: [PATCH 11/33] [IMP] hr_payroll_account: improved code to assigned analytic account on payslip line from salary rule bzr revid: mtr@mtr-20110420085519-emevo3dufjvso7w6 --- addons/hr_payroll_account/hr_payroll_account.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index cac642027af..203c00c88cb 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -256,6 +256,8 @@ class hr_payslip(osv.osv): else: emp_account_id = [record.employee_id.employee_account.id for record in self.browse(cr, uid, [payslip_id], context=context)] value['account_id'] = emp_account_id[0] + if rule.analytic_account_id: + value['analytic_account_id'] = rule.analytic_account_id.id return result def create_voucher(self, cr, uid, ids, name, voucher, sequence=5): From ba2f190424f68d5f9254366db4782f0dde06b251 Mon Sep 17 00:00:00 2001 From: mtr Date: Wed, 20 Apr 2011 16:08:11 +0530 Subject: [PATCH 12/33] [IMP] hr_payroll_account: added account.move(m2m) field on payslip and improved code to get its Entries bzr revid: mtr@mtr-20110420103811-rphergw2re9ca11y --- addons/hr_payroll_account/hr_payroll_account.py | 9 +++++++-- addons/hr_payroll_account/hr_payroll_account_view.xml | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 203c00c88cb..7cd12a58c78 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -219,6 +219,7 @@ class hr_payslip(osv.osv): 'move_line_ids':fields.many2many('account.move.line', 'payslip_lines_rel', 'slip_id', 'line_id', 'Accounting Lines', readonly=True), 'move_payment_ids':fields.many2many('account.move.line', 'payslip_payment_rel', 'slip_id', 'payment_id', 'Payment Lines', readonly=True), 'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), + 'account_move_ids': fields.many2many('account.move', 'payslip_move_rel', 'slip_id', 'move_id', 'Accounting Entries', readonly=True), } def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): @@ -436,7 +437,8 @@ class hr_payslip(osv.osv): rec = { 'state':'done', 'move_payment_ids':[(6, 0, line_ids)], - 'paid':True + 'paid':True, + 'account_move_ids': [(4, move_id)], } self.write(cr, uid, [slip.id], rec, context=context) for exp_id in exp_ids: @@ -472,6 +474,7 @@ class hr_payslip(osv.osv): total_deduct = 0.0 line_ids = [] + move_ids = [] partner = False partner_id = False @@ -512,6 +515,7 @@ class hr_payslip(osv.osv): 'narration': slip.name } move_id = move_pool.create(cr, uid, move, context=context) + move_ids += [move_id] self.create_voucher(cr, uid, [slip.id], slip.name, move_id) if not slip.employee_id.salary_account.id: @@ -554,7 +558,6 @@ class hr_payslip(osv.osv): 'ref':slip.number } line_ids += [movel_pool.create(cr, uid, line, context=context)] - for line in slip.line_ids: if line.name == 'Net' or line.name == 'Gross' or line.name == 'Basic': continue @@ -637,6 +640,7 @@ class hr_payslip(osv.osv): 'narration': 'Adjustment: %s' % (slip.name) } adj_move_id = move_pool.create(cr, uid, move, context=context) + move_ids += [adj_move_id] name = "Adjustment Entry - %s" % (slip.employee_id.name) self.create_voucher(cr, uid, [slip.id], name, adj_move_id) @@ -672,6 +676,7 @@ class hr_payslip(osv.osv): rec = { 'state':'confirm', 'move_line_ids':[(6, 0,line_ids)], + 'account_move_ids':[(6, 0, move_ids)] } if not slip.period_id: rec['period_id'] = period_id diff --git a/addons/hr_payroll_account/hr_payroll_account_view.xml b/addons/hr_payroll_account/hr_payroll_account_view.xml index e290f94bcac..f95c8d3cba5 100644 --- a/addons/hr_payroll_account/hr_payroll_account_view.xml +++ b/addons/hr_payroll_account/hr_payroll_account_view.xml @@ -166,6 +166,9 @@ + + + From c158f0235ea26015c8cdc86767721b69d2997eab Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Wed, 20 Apr 2011 16:41:17 +0530 Subject: [PATCH 13/33] [FIX] Payroll: Correct xml views bzr revid: mra@mra-laptop-20110420111117-1k9ihl2ytwu1zbyq --- .../hr_payroll_account_view.xml | 34 ++++++------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account_view.xml b/addons/hr_payroll_account/hr_payroll_account_view.xml index f95c8d3cba5..876d00943ee 100644 --- a/addons/hr_payroll_account/hr_payroll_account_view.xml +++ b/addons/hr_payroll_account/hr_payroll_account_view.xml @@ -149,31 +149,19 @@ + + + + + + + + + - - hr.payslip.form - hr.payslip - form - - - - - - - - - - - - - - - - - @@ -191,7 +179,7 @@ - + hr.salary.rule.form.inherit hr.salary.rule @@ -209,7 +197,7 @@ - + hr.contract.view.form.inherit hr.contract From 54338ff5a18c94263044b2109d094982b768423a Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Wed, 20 Apr 2011 16:52:22 +0530 Subject: [PATCH 14/33] [FIX] payroll_account: fix bzr revid: mra@mra-laptop-20110420112222-l0ztdl70fxhyqs16 --- addons/hr_payroll_account/hr_payroll_account.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 7cd12a58c78..3f6010bd5ad 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -221,7 +221,7 @@ class hr_payslip(osv.osv): 'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), 'account_move_ids': fields.many2many('account.move', 'payslip_move_rel', 'slip_id', 'move_id', 'Accounting Entries', readonly=True), } - + def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): journal_obj = self.pool.get('account.journal') rule_obj = self.pool.get('hr.salary.rule') @@ -233,10 +233,9 @@ class hr_payslip(osv.osv): #get the rules of the structure and thier children rule_ids = structure_obj.get_all_rules(cr, uid, structure_ids, context=context) sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])] - journal_id = [record.journal_id.id for record in self.browse(cr, uid, [payslip_id], context=context)] - for jou in journal_obj.browse(cr ,uid, journal_id, context=context): - credit_account = jou.default_credit_account_id.id - debit_account = jou.default_debit_account_id.id + journal = self.browse(cr, uid, payslip_id, context=context).journal_id.id + credit_account = journal.default_credit_account_id and journal.default_credit_account_id.id or False + debit_account = journal.default_debit_account_id and journal.default_debit_account_id.id or False for rule in rule_obj.browse(cr, uid, sorted_rule_ids, context=context): if not rule.account_debit.id: rule_obj.write(cr, uid, [rule.id], {'account_debit': debit_account}) @@ -260,7 +259,7 @@ class hr_payslip(osv.osv): if rule.analytic_account_id: value['analytic_account_id'] = rule.analytic_account_id.id return result - + def create_voucher(self, cr, uid, ids, name, voucher, sequence=5): slip_move = self.pool.get('hr.payslip.account.move') for slip in ids: @@ -307,11 +306,11 @@ class hr_payslip(osv.osv): partner = slip.employee_id.bank_account_id.partner_id partner_id = partner.id - + for line in slip.line_ids: if line.category_id.name == 'Net': amt = line.total - + fiscal_year_ids = fiscalyear_pool.search(cr, uid, [], context=context) if not fiscal_year_ids: raise osv.except_osv(_('Warning !'), _('Please define fiscal year for perticular contract')) @@ -736,7 +735,7 @@ class account_move_link_slip(osv.osv): account_move_link_slip() class hr_contract(osv.osv): - + _inherit = 'hr.contract' _description = 'Employee Contract' _columns = { From 4ef126925944901407871eb0b48f365e2a7d7639 Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Wed, 20 Apr 2011 17:08:47 +0530 Subject: [PATCH 15/33] [FIX] payroll_account: improve code bzr revid: mra@mra-laptop-20110420113847-fu562g080n3svr8b --- addons/hr_payroll_account/hr_payroll_account.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 3f6010bd5ad..affe06c8499 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -282,10 +282,8 @@ class hr_payslip(osv.osv): if line.move_id.state == 'posted': move_pool.button_cancel(cr, uid [line.move_id.id], context) move_pool.unlink(cr, uid, [line.move_id.id], context=context) - slip_move.unlink(cr, uid, move_ids, context=context) - self.write(cr, uid, ids, {'state':'cancel'}, context=context) - return True + return self.write(cr, uid, ids, {'state':'cancel'}, context=context) def process_sheet(self, cr, uid, ids, context=None): move_pool = self.pool.get('account.move') @@ -446,12 +444,10 @@ class hr_payslip(osv.osv): return True def account_check_sheet(self, cr, uid, ids, context=None): - self.write(cr, uid, ids, {'state':'accont_check'}, context=context) - return True + return self.write(cr, uid, ids, {'state':'accont_check'}, context=context) def hr_check_sheet(self, cr, uid, ids, context=None): - self.write(cr, uid, ids, {'state':'hr_check'}, context=context) - return True + return self.write(cr, uid, ids, {'state':'hr_check'}, context=context) def verify_sheet(self, cr, uid, ids, context=None): move_pool = self.pool.get('account.move') From 3e87d45ce3ed28e131182619a6e14b1f60a42c87 Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Wed, 20 Apr 2011 18:54:28 +0530 Subject: [PATCH 16/33] [FIX] hr_payroll_account: payslip line link not working bzr revid: ara@tinyerp.com-20110420132428-kk8fa7v0bhm616d9 --- addons/hr_payroll_account/hr_payroll_account_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll_account/hr_payroll_account_view.xml b/addons/hr_payroll_account/hr_payroll_account_view.xml index 876d00943ee..8ff199fb466 100644 --- a/addons/hr_payroll_account/hr_payroll_account_view.xml +++ b/addons/hr_payroll_account/hr_payroll_account_view.xml @@ -8,7 +8,7 @@ tree - + From 956f12eccd494afeac364f01e3b2a481f327e308 Mon Sep 17 00:00:00 2001 From: mtr Date: Wed, 20 Apr 2011 18:55:08 +0530 Subject: [PATCH 17/33] [IMP] hr_payroll_account: assign journal on payslip with contract journal bzr revid: mtr@mtr-20110420132508-7u5lry0mkq9533a9 --- addons/hr_payroll_account/hr_payroll_account.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index affe06c8499..1c7cd5735bb 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -221,6 +221,13 @@ class hr_payslip(osv.osv): 'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), 'account_move_ids': fields.many2many('account.move', 'payslip_move_rel', 'slip_id', 'move_id', 'Accounting Entries', readonly=True), } + + def onchange_contract_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None): + contract_obj = self.pool.get('hr.contract') + res = super(hr_payslip, self).onchange_contract_id(cr, uid, ids, date_from=date_from, date_to=date_to, employee_id=employee_id, contract_id=contract_id, context=context) + journal_id = contract_obj.browse(cr, uid, contract_id, context=context).journal_id.id + res['value'].update({'journal_id': journal_id}) + return res def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): journal_obj = self.pool.get('account.journal') From 398f82a1b1b3e511825e8e11e549d9f575ac6877 Mon Sep 17 00:00:00 2001 From: mtr Date: Wed, 20 Apr 2011 19:00:58 +0530 Subject: [PATCH 18/33] [IMP] hr_payroll_account: code cleaning bzr revid: mtr@mtr-20110420133058-wrt4tzupai4osgfs --- addons/hr_payroll_account/hr_payroll_account.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 1c7cd5735bb..231a8b8d837 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -240,7 +240,7 @@ class hr_payslip(osv.osv): #get the rules of the structure and thier children rule_ids = structure_obj.get_all_rules(cr, uid, structure_ids, context=context) sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])] - journal = self.browse(cr, uid, payslip_id, context=context).journal_id.id + journal = self.browse(cr, uid, payslip_id, context=context).journal_id credit_account = journal.default_credit_account_id and journal.default_credit_account_id.id or False debit_account = journal.default_debit_account_id and journal.default_debit_account_id.id or False for rule in rule_obj.browse(cr, uid, sorted_rule_ids, context=context): @@ -261,8 +261,8 @@ class hr_payslip(osv.osv): else: value['account_id'] = rule.account_credit.id else: - emp_account_id = [record.employee_id.employee_account.id for record in self.browse(cr, uid, [payslip_id], context=context)] - value['account_id'] = emp_account_id[0] + emp_account_id = self.browse(cr, uid, payslip_id, context=context).employee_id.employee_account.id + value['account_id'] = emp_account_id if rule.analytic_account_id: value['analytic_account_id'] = rule.analytic_account_id.id return result From 2f9f8f1e4fff3777fa25932dbc425dbf1331735e Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Thu, 21 Apr 2011 10:41:46 +0530 Subject: [PATCH 19/33] [FIX] Payroll: rename demo file bzr revid: mra@mra-laptop-20110421051146-xvy2lvai7wa8k9lw --- .../{hr_payroll_demo.xml => hr_payroll_account_demo.xml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename addons/hr_payroll_account/{hr_payroll_demo.xml => hr_payroll_account_demo.xml} (100%) diff --git a/addons/hr_payroll_account/hr_payroll_demo.xml b/addons/hr_payroll_account/hr_payroll_account_demo.xml similarity index 100% rename from addons/hr_payroll_account/hr_payroll_demo.xml rename to addons/hr_payroll_account/hr_payroll_account_demo.xml From 005d73a5e57d9e60395be2f5b460d9c3634d68a4 Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Thu, 21 Apr 2011 11:52:09 +0530 Subject: [PATCH 20/33] [FIX] Payroll_account: fix bzr revid: mra@mra-laptop-20110421062209-dv0rpudc6tdt6gtg --- addons/hr_payroll_account/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll_account/__openerp__.py b/addons/hr_payroll_account/__openerp__.py index 30dcd9e7b55..99da1d6b451 100644 --- a/addons/hr_payroll_account/__openerp__.py +++ b/addons/hr_payroll_account/__openerp__.py @@ -46,7 +46,7 @@ Generic Payroll system Integrated with Accountings. "hr_payroll_account_view.xml", ], 'demo_xml': [ - 'hr_payroll_demo.xml' + 'hr_payroll_account_demo.xml' ], 'installable': True, 'active': False, From 60ad4cdfe6f18419116c8b479eada9f91c19604f Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Thu, 21 Apr 2011 12:52:56 +0530 Subject: [PATCH 21/33] [IMP] Payroll_account: improved views, on the other state of draft make fields on payslip to readonly=true bzr revid: mra@mra-laptop-20110421072256-la7412gwr7osf0hj --- addons/hr_payroll/hr_payroll.py | 2 +- addons/hr_payroll_account/hr_payroll_account.py | 8 ++++---- addons/hr_payroll_account/hr_payroll_account_view.xml | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 45826254df5..9b20e048bcf 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -226,7 +226,7 @@ class hr_payslip(osv.osv): return result _columns = { - 'struct_id': fields.many2one('hr.payroll.structure', 'Structure', help='Defines the rules that have to be applied to this payslip, accordingly to the contract chosen. If you let empty the field contract, this field isn\'t mandatory anymore and thus the rules applied will be all the rules set on the structure of all contracts of the employee valid for the chosen period'), + 'struct_id': fields.many2one('hr.payroll.structure', 'Structure', readonly=True, states={'draft': [('readonly', False)]},help='Defines the rules that have to be applied to this payslip, accordingly to the contract chosen. If you let empty the field contract, this field isn\'t mandatory anymore and thus the rules applied will be all the rules set on the structure of all contracts of the employee valid for the chosen period'), 'name': fields.char('Description', size=64, required=False, readonly=True, states={'draft': [('readonly', False)]}), 'number': fields.char('Reference', size=64, required=False, readonly=True, states={'draft': [('readonly', False)]}), 'employee_id': fields.many2one('hr.employee', 'Employee', required=True, readonly=True, states={'draft': [('readonly', False)]}), diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 231a8b8d837..af7a911bf31 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -213,15 +213,15 @@ class hr_payslip(osv.osv): _description = 'Pay Slip' _columns = { - 'journal_id': fields.many2one('account.journal', 'Expense Journal'), - 'bank_journal_id': fields.many2one('account.journal', 'Bank Journal'), + 'journal_id': fields.many2one('account.journal', 'Expense Journal',states={'draft': [('readonly', False)]}, readonly=True), + 'bank_journal_id': fields.many2one('account.journal', 'Bank Journal', states={'draft': [('readonly', False)]}, readonly=True), 'move_ids':fields.one2many('hr.payslip.account.move', 'slip_id', 'Accounting vouchers'), 'move_line_ids':fields.many2many('account.move.line', 'payslip_lines_rel', 'slip_id', 'line_id', 'Accounting Lines', readonly=True), 'move_payment_ids':fields.many2many('account.move.line', 'payslip_payment_rel', 'slip_id', 'payment_id', 'Payment Lines', readonly=True), - 'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), + 'period_id': fields.many2one('account.period', 'Force Period',states={'draft': [('readonly', False)]}, readonly=True, domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), 'account_move_ids': fields.many2many('account.move', 'payslip_move_rel', 'slip_id', 'move_id', 'Accounting Entries', readonly=True), } - + def onchange_contract_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None): contract_obj = self.pool.get('hr.contract') res = super(hr_payslip, self).onchange_contract_id(cr, uid, ids, date_from=date_from, date_to=date_to, employee_id=employee_id, contract_id=contract_id, context=context) diff --git a/addons/hr_payroll_account/hr_payroll_account_view.xml b/addons/hr_payroll_account/hr_payroll_account_view.xml index 8ff199fb466..94af7526192 100644 --- a/addons/hr_payroll_account/hr_payroll_account_view.xml +++ b/addons/hr_payroll_account/hr_payroll_account_view.xml @@ -49,6 +49,7 @@ + @@ -152,12 +153,12 @@ - - - + + + From faf4bec06c4771dc3047c09d1be62702f2795426 Mon Sep 17 00:00:00 2001 From: "Michael Telahun Makonnen, mtr(OpenERP)" <> Date: Thu, 21 Apr 2011 17:09:25 +0530 Subject: [PATCH 22/33] [FIX] hr_payroll_account: changed domain and ir.property to make account type=payable lp bug: https://launchpad.net/bugs/761456 fixed bzr revid: mtr@mtr-20110421113925-r6j0cxhdxrcaqqyg --- .../hr_payroll_account/hr_payroll_account.py | 2 +- .../hr_payroll_account_demo.xml | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index af7a911bf31..68339252fa4 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -80,7 +80,7 @@ class hr_employee(osv.osv): relation='account.account', string="Employee Account", method=True, - domain="[('type', '=', 'other')]", + domain="[('type', '=', 'payable')]", view_load=True, help="Employee Payable Account"), 'analytic_account':fields.property( diff --git a/addons/hr_payroll_account/hr_payroll_account_demo.xml b/addons/hr_payroll_account/hr_payroll_account_demo.xml index 1483015e9b4..5d246342e53 100644 --- a/addons/hr_payroll_account/hr_payroll_account_demo.xml +++ b/addons/hr_payroll_account/hr_payroll_account_demo.xml @@ -50,7 +50,7 @@ - + X110041 @@ -96,12 +96,13 @@ - - X21102 - Expenses - - other - + + X11111 + Employee Payable Account + + payable + + @@ -122,7 +123,7 @@ employee_account - + From 06f47c3c3e86df249a0acfc9a77beef50afceb39 Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 26 Apr 2011 16:22:15 +0530 Subject: [PATCH 23/33] [IMP] hr_payroll:calculates total for salary head in payslip report bzr revid: mtr@mtr-20110426105215-aiijosjm7wv2rjjr --- addons/hr_payroll/report/report_payslip.py | 7 ++++++- addons/hr_payroll/report/report_payslip.rml | 16 +++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/addons/hr_payroll/report/report_payslip.py b/addons/hr_payroll/report/report_payslip.py index 31f99607a1e..84fc85e10c8 100644 --- a/addons/hr_payroll/report/report_payslip.py +++ b/addons/hr_payroll/report/report_payslip.py @@ -110,6 +110,7 @@ class payslip_report(report_sxw.rml_parse): res = [] result = {} ids = [] + for id in range(len(obj)): ids.append(obj[id].id) if ids: @@ -124,13 +125,17 @@ class payslip_report(report_sxw.rml_parse): for key, value in result.iteritems(): heads = salary_head.browse(self.cr, self.uid, [key]) parents = self.get_recursive_parent(heads) + head_total = 0 + for line in payslip_line.browse(self.cr, self.uid, value): + head_total += line.total level = 0 for parent in parents: res.append({ 'salary_head': parent.name, 'name': parent.name, 'code': parent.code, - 'level': level + 'level': level, + 'total': head_total, }) level += 1 lines = payslip_line.browse(self.cr, self.uid, value) diff --git a/addons/hr_payroll/report/report_payslip.rml b/addons/hr_payroll/report/report_payslip.rml index 58d558f42cb..76b28a65fb2 100644 --- a/addons/hr_payroll/report/report_payslip.rml +++ b/addons/hr_payroll/report/report_payslip.rml @@ -178,6 +178,7 @@ + @@ -193,6 +194,7 @@ + @@ -229,7 +231,7 @@ Designation - [[ o.employee_id.contract_id and o.employee_id.contract_id.job_id.name or '' ]] + [[ o.employee_id.job_id.name or '' ]] @@ -266,7 +268,7 @@ - Slip ID + Reference [[ o.number or '' ]] @@ -275,7 +277,7 @@ Bank Details - [[ o.employee_id.otherid or '' ]] + [[ o.employee_id.bank_account_id.acc_number or '' ]] @@ -370,17 +372,17 @@ [[ h['code'] ]] - [[ h.get('total', False) and ( setTag('para','para',{'style':'terp_default_8'})) or removeParentNode('font') ]] + [[ h['level']!=0 and ( setTag('para','para',{'style':'terp_default_8'})) or removeParentNode('font') ]] - [[ '..'*h['level'] ]][[ h['salary_head'] ]][[ h.get('total', False) and ( setTag('para','para',{'style':'terp_default_9'})) or removeParentNode('font') ]] + [[ '..'*h['level'] ]][[ h['salary_head'] ]][[ h['level']!=0 and ( setTag('para','para',{'style':'terp_default_9'})) or removeParentNode('font') ]] - [[ h['name'] ]][[ h.get('total', False) and ( setTag('para','para',{'style':'terp_default_8'})) or removeParentNode('font') ]] + [[ h['name'] ]][[ h['level']!=0 and ( setTag('para','para',{'style':'terp_default_8'})) or removeParentNode('font') ]] - [[ h['total'] ]] + [[ h['total'] ]][[ h['level']!=0 and ( setTag('para','para',{'style':'terp_default_10'})) or removeParentNode('font') ]] From f90308d9e8abe635745ab313f806ef9f7048e3c8 Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 26 Apr 2011 16:47:15 +0530 Subject: [PATCH 24/33] [IMP] hr_payroll:improved bank details on payslip report bzr revid: mtr@mtr-20110426111715-p3kt5lz3arw1wgda --- addons/hr_payroll/report/report_payslip.rml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/hr_payroll/report/report_payslip.rml b/addons/hr_payroll/report/report_payslip.rml index 76b28a65fb2..c3b3cb935c7 100644 --- a/addons/hr_payroll/report/report_payslip.rml +++ b/addons/hr_payroll/report/report_payslip.rml @@ -274,10 +274,10 @@ [[ o.number or '' ]] - Bank Details + Bank Account - [[ o.employee_id.bank_account_id.acc_number or '' ]] + [[o.employee_id.bank_account_id and o.employee_id.bank_account_id.acc_number or '' ]] From e91a6c9f0366c694e9ef7ebfbfd8428e1f3aecbc Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 26 Apr 2011 17:05:59 +0530 Subject: [PATCH 25/33] [IMP] hr_payroll:commented older payslip report bzr revid: mtr@mtr-20110426113559-bd8dr2d2txe1njxj --- addons/hr_payroll/hr_payroll_report.xml | 6 +++--- addons/hr_payroll/report/report_payslip.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/hr_payroll/hr_payroll_report.xml b/addons/hr_payroll/hr_payroll_report.xml index 67eea27b26c..23e72d511f0 100644 --- a/addons/hr_payroll/hr_payroll_report.xml +++ b/addons/hr_payroll/hr_payroll_report.xml @@ -1,13 +1,13 @@ - + string="Employee PaySlip" />--> + string="Employee PaySlip" /> Date: Thu, 12 May 2011 10:49:49 +0530 Subject: [PATCH 26/33] [IMP] hr_payroll_account: added onchange_employee_id method and comments(help) in the code bzr revid: mtr@mtr-20110512051949-8znbh8wy6yyt192t --- addons/hr_payroll_account/hr_payroll_account.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 68339252fa4..30252f4592b 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -229,6 +229,15 @@ class hr_payslip(osv.osv): res['value'].update({'journal_id': journal_id}) return res +# def onchange_employee_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None): +# contract_obj = self.pool.get('hr.contract') +# res = super(hr_payslip, self).onchange_employee_id(cr, uid, ids, date_from=date_from, date_to=date_to, employee_id=employee_id, contract_id=contract_id, context=context) +# contract_id = res['value']['contract_id'] +# if res['value']['contract_id']: +# journal_id = contract_obj.browse(cr, uid, res['value']['contract_id'], context=context).journal_id.id +# res['value'].update({'journal_id': journal_id}) +# return res + def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): journal_obj = self.pool.get('account.journal') rule_obj = self.pool.get('hr.salary.rule') @@ -240,14 +249,17 @@ class hr_payslip(osv.osv): #get the rules of the structure and thier children rule_ids = structure_obj.get_all_rules(cr, uid, structure_ids, context=context) sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])] + #Fetching Debit/Credit account of the payslip journal. journal = self.browse(cr, uid, payslip_id, context=context).journal_id credit_account = journal.default_credit_account_id and journal.default_credit_account_id.id or False debit_account = journal.default_debit_account_id and journal.default_debit_account_id.id or False + # Assigning above fetched Debit/Credit account on salary rules if not specified for rule in rule_obj.browse(cr, uid, sorted_rule_ids, context=context): if not rule.account_debit.id: rule_obj.write(cr, uid, [rule.id], {'account_debit': debit_account}) if not rule.account_credit.id: rule_obj.write(cr, uid, [rule.id], {'account_credit': credit_account}) + #Assigning Debit/Credit account on payslip lines for value in result: if value['salary_rule_id'] == rule.id: if rule.category_id.name == 'Deduction': From 3682e3df408ec587305a415956fbbcc234cc1c62 Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 12 May 2011 11:06:37 +0530 Subject: [PATCH 27/33] [IMP] hr_payroll_account: made account_id unrequired field on contribution register bzr revid: mtr@mtr-20110512053637-2yudj4rinjtwayy1 --- addons/hr_payroll_account/hr_payroll_account_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll_account/hr_payroll_account_view.xml b/addons/hr_payroll_account/hr_payroll_account_view.xml index 94af7526192..aec5b6ebee7 100644 --- a/addons/hr_payroll_account/hr_payroll_account_view.xml +++ b/addons/hr_payroll_account/hr_payroll_account_view.xml @@ -93,7 +93,7 @@ - + From b653a74923bb8bb1cade728022ebbb8674d83c7f Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 12 May 2011 10:01:47 +0200 Subject: [PATCH 28/33] [IMP] hr_payroll_account: set the basis for the new version of hr_payroll_account based on our new vision of hr_payroll bzr revid: qdp-launchpad@openerp.com-20110512080147-emqikvpp8idhiwnx --- .../hr_payroll_account/hr_payroll_account.py | 324 +----------------- 1 file changed, 18 insertions(+), 306 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 30252f4592b..5e1e5fc1213 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -27,184 +27,17 @@ from osv import fields, osv from tools import config from tools.translate import _ -#def prev_bounds(cdate=False): -# when = date.fromtimestamp(time.mktime(time.strptime(cdate,"%Y-%m-%d"))) -# this_first = date(when.year, when.month, 1) -# month = when.month + 1 -# year = when.year -# if month > 12: -# month = 1 -# year += 1 -# next_month = date(year, month, 1) -# prev_end = next_month - timedelta(days=1) -# return this_first, prev_end - -class hr_payroll_structure(osv.osv): - _inherit = 'hr.payroll.structure' - _description = 'Salary Structure' - - _columns = { - 'account_id':fields.many2one('account.analytic.account', 'Analytic Account'), - } -hr_payroll_structure() - -class hr_employee(osv.osv): - ''' - Employee - ''' - _inherit = 'hr.employee' - _description = 'Employee' - - _columns = { - 'property_bank_account': fields.property( - 'account.account', - type='many2one', - relation='account.account', - string="Bank Account", - method=True, - domain="[('type', '=', 'liquidity')]", - view_load=True, - help="Select Bank Account from where Salary Expense will be Paid, to be used for payslip verification."), - 'salary_account':fields.property( - 'account.account', - type='many2one', - relation='account.account', - string="Salary Account", - method=True, - domain="[('type', '=', 'other')]", - view_load=True, - help="Expense account when Salary Expense will be recorded"), - 'employee_account':fields.property( - 'account.account', - type='many2one', - relation='account.account', - string="Employee Account", - method=True, - domain="[('type', '=', 'payable')]", - view_load=True, - help="Employee Payable Account"), - 'analytic_account':fields.property( - 'account.analytic.account', - type='many2one', - relation='account.analytic.account', - string="Analytic Account", - method=True, - view_load=True, - help="Analytic Account for Salary Analysis"), - } -hr_employee() - -#class payroll_register(osv.osv): -# _inherit = 'hr.payroll.register' -# _description = 'Payroll Register' -# -# _columns = { -# 'journal_id': fields.many2one('account.journal', 'Expense Journal'), -# 'bank_journal_id': fields.many2one('account.journal', 'Bank Journal'), -# 'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), -# } -# -# def compute_sheet(self, cr, uid, ids, context=None): -# emp_pool = self.pool.get('hr.employee') -# slip_pool = self.pool.get('hr.payslip') -# func_pool = self.pool.get('hr.payroll.structure') -# slip_line_pool = self.pool.get('hr.payslip.line') -# wf_service = netsvc.LocalService("workflow") -# vals = self.browse(cr, uid, ids, context=context)[0] -# emp_ids = emp_pool.search(cr, uid, []) -# -# for emp in emp_pool.browse(cr, uid, emp_ids, context=context): -# old_slips = slip_pool.search(cr, uid, [('employee_id','=', emp.id), ('date','=',vals.date)]) -# if old_slips: -# slip_pool.write(cr, uid, old_slips, {'register_id':ids[0]}) -# for sid in old_slips: -# wf_service.trg_validate(uid, 'hr.payslip', sid, 'compute_sheet', cr) -# else: -# res = { -# 'employee_id':emp.id, -# 'basic':0.0, -# 'register_id':ids[0], -# 'name':vals.name, -# 'date':vals.date, -# 'journal_id':vals.journal_id.id, -# 'bank_journal_id':vals.bank_journal_id.id -# } -# slip_id = slip_pool.create(cr, uid, res) -# wf_service.trg_validate(uid, 'hr.payslip', slip_id, 'compute_sheet', cr) -# -# number = self.pool.get('ir.sequence').get(cr, uid, 'salary.register') -# self.write(cr, uid, ids, {'state':'draft', 'number':number}) -# return True -# -#payroll_register() - -#class payroll_advice(osv.osv): -# _inherit = 'hr.payroll.advice' -# _description = 'Bank Advice Note' -# -# _columns = { -# 'account_id': fields.many2one('account.account', 'Account'), -# } -#payroll_advice() class contrib_register(osv.osv): _inherit = 'hr.contribution.register' _description = 'Contribution Register' - def _total_contrib(self, cr, uid, ids, field_names, arg, context=None): -# line_pool = self.pool.get('hr.contibution.register.line') - period_id = self.pool.get('account.period').search(cr,uid,[('date_start','<=',time.strftime('%Y-%m-%d')),('date_stop','>=',time.strftime('%Y-%m-%d'))])[0] - fiscalyear_id = self.pool.get('account.period').browse(cr, uid, period_id, context=context).fiscalyear_id - res = {} -# for cur in self.browse(cr, uid, ids, context=context): -# current = line_pool.search(cr, uid, [('period_id','=',period_id),('register_id','=',cur.id)]) -# years = line_pool.search(cr, uid, [('period_id.fiscalyear_id','=',fiscalyear_id.id), ('register_id','=',cur.id)]) -# -# e_month = 0.0 -# c_month = 0.0 -# for i in line_pool.browse(cr, uid, current, context=context): -# e_month += i.emp_deduction -# c_month += i.comp_deduction -# -# e_year = 0.0 -# c_year = 0.0 -# for j in line_pool.browse(cr, uid, years, context=context): -# e_year += i.emp_deduction -# c_year += i.comp_deduction -# -# res[cur.id]={ -# 'monthly_total_by_emp':e_month, -# 'monthly_total_by_comp':c_month, -# 'yearly_total_by_emp':e_year, -# 'yearly_total_by_comp':c_year -# } - return res - _columns = { 'account_id': fields.many2one('account.account', 'Account'), 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'), - 'yearly_total_by_emp': fields.function(_total_contrib, method=True, multi='dc', store=True, string='Total By Employee', digits=(16, 4)), - 'yearly_total_by_comp': fields.function(_total_contrib, method=True, multi='dc', store=True, string='Total By Company', digits=(16, 4)), } contrib_register() -#class contrib_register_line(osv.osv): -# _inherit = 'hr.contibution.register.line' -# _description = 'Contribution Register Line' -# -# _columns = { -# 'period_id': fields.many2one('account.period', 'Period'), -# } -#contrib_register_line() - -#class hr_holidays_status(osv.osv): -# _inherit = 'hr.holidays.status' -# _columns = { -# 'account_id': fields.many2one('account.account', 'Account'), -# 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'), -# } -#hr_holidays_status() - class hr_payslip(osv.osv): ''' Pay Slip @@ -213,12 +46,10 @@ class hr_payslip(osv.osv): _description = 'Pay Slip' _columns = { - 'journal_id': fields.many2one('account.journal', 'Expense Journal',states={'draft': [('readonly', False)]}, readonly=True), - 'bank_journal_id': fields.many2one('account.journal', 'Bank Journal', states={'draft': [('readonly', False)]}, readonly=True), - 'move_ids':fields.one2many('hr.payslip.account.move', 'slip_id', 'Accounting vouchers'), - 'move_line_ids':fields.many2many('account.move.line', 'payslip_lines_rel', 'slip_id', 'line_id', 'Accounting Lines', readonly=True), - 'move_payment_ids':fields.many2many('account.move.line', 'payslip_payment_rel', 'slip_id', 'payment_id', 'Payment Lines', readonly=True), 'period_id': fields.many2one('account.period', 'Force Period',states={'draft': [('readonly', False)]}, readonly=True, domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), + 'journal_id': fields.many2one('account.journal', 'Expense Journal',states={'draft': [('readonly', False)]}, readonly=True), + #TOCHECK: should we have a link to account.move or account.move.line? + #'move_line_ids':fields.many2many('account.move.line', 'payslip_lines_rel', 'slip_id', 'line_id', 'Accounting Lines', readonly=True), 'account_move_ids': fields.many2many('account.move', 'payslip_move_rel', 'slip_id', 'move_id', 'Accounting Entries', readonly=True), } @@ -229,15 +60,7 @@ class hr_payslip(osv.osv): res['value'].update({'journal_id': journal_id}) return res -# def onchange_employee_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None): -# contract_obj = self.pool.get('hr.contract') -# res = super(hr_payslip, self).onchange_employee_id(cr, uid, ids, date_from=date_from, date_to=date_to, employee_id=employee_id, contract_id=contract_id, context=context) -# contract_id = res['value']['contract_id'] -# if res['value']['contract_id']: -# journal_id = contract_obj.browse(cr, uid, res['value']['contract_id'], context=context).journal_id.id -# res['value'].update({'journal_id': journal_id}) -# return res - +#FIXME: we need to overwrite a smaller code def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): journal_obj = self.pool.get('account.journal') rule_obj = self.pool.get('hr.salary.rule') @@ -279,17 +102,7 @@ class hr_payslip(osv.osv): value['analytic_account_id'] = rule.analytic_account_id.id return result - def create_voucher(self, cr, uid, ids, name, voucher, sequence=5): - slip_move = self.pool.get('hr.payslip.account.move') - for slip in ids: - res = { - 'slip_id':slip, - 'move_id':voucher, - 'sequence':sequence, - 'name':name - } - slip_move.create(cr, uid, res) - +#TODO: to correct def cancel_sheet(self, cr, uid, ids, context=None): move_pool = self.pool.get('account.move') slip_move = self.pool.get('hr.payslip.account.move') @@ -304,6 +117,7 @@ class hr_payslip(osv.osv): slip_move.unlink(cr, uid, move_ids, context=context) return self.write(cr, uid, ids, {'state':'cancel'}, context=context) +#TODO: to correct def process_sheet(self, cr, uid, ids, context=None): move_pool = self.pool.get('account.move') movel_pool = self.pool.get('account.move.line') @@ -386,69 +200,6 @@ class hr_payslip(osv.osv): } line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)] -# other_pay = slip.other_pay - #Process all Reambuse Entries -# for line in slip.line_ids: -# if line.type == 'otherpay' and line.expanse_id.invoice_id: -# if not line.expanse_id.invoice_id.move_id: -# raise osv.except_osv(_('Warning !'), _('Please Confirm all Expense Invoice appear for Reimbursement')) -# invids = [line.expanse_id.invoice_id.id] -# amount = line.total -# acc_id = slip.bank_journal_id.default_credit_account_id and slip.bank_journal_id.default_credit_account_id.id -# period_id = slip.period_id.id -# journal_id = slip.bank_journal_id.id -# name = '[%s]-%s' % (slip.number, line.name) -# invoice_pool.pay_and_reconcile(cr, uid, invids, amount, acc_id, period_id, journal_id, False, period_id, False, context, name) -# other_pay -= amount -# #TODO: link this account entries to the Payment Lines also Expense Entries to Account Lines -# l_ids = movel_pool.search(cr, uid, [('name','=',name)], context=context) -# line_ids += l_ids -# -# l_ids = movel_pool.search(cr, uid, [('invoice','=',line.expanse_id.invoice_id.id)], context=context) -# exp_ids += l_ids - - #Process for Other payment if any -# other_move_id = False -# if slip.other_pay > 0: -# narration = 'Payment of Other Payeble amounts to %s' % (slip.employee_id.name) -# move = { -# 'journal_id': slip.bank_journal_id.id, -# 'period_id': period_id, -# 'date': slip.date_from, -# 'type':'bank_pay_voucher', -# 'ref':slip.number, -# 'narration': narration -# } -# other_move_id = move_pool.create(cr, uid, move, context=context) -# self.create_voucher(cr, uid, [slip.id], narration, move_id) -# -# name = "To %s account" % (slip.employee_id.name) -# ded_rec = { -# 'move_id':other_move_id, -# 'name':name, -# 'date':slip.date_from, -# 'account_id':slip.employee_id.property_bank_account.id, -# 'debit': 0.0, -# 'credit': other_pay, -# 'journal_id':slip.journal_id.id, -# 'period_id':period_id, -# 'ref':slip.number -# } -# line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] -# name = "By %s account" % (slip.employee_id.property_bank_account.name) -# cre_rec = { -# 'move_id':other_move_id, -# 'name':name, -# 'partner_id':partner_id, -# 'date':slip.date_from, -# 'account_id':partner.property_account_payable.id, -# 'debit': other_pay, -# 'credit':0.0, -# 'journal_id':slip.journal_id.id, -# 'period_id':period_id, -# 'ref':slip.number -# } -# line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)] rec = { 'state':'done', @@ -462,12 +213,15 @@ class hr_payslip(osv.osv): return True +#TODO: to clean def account_check_sheet(self, cr, uid, ids, context=None): return self.write(cr, uid, ids, {'state':'accont_check'}, context=context) +#TODO: to clean def hr_check_sheet(self, cr, uid, ids, context=None): return self.write(cr, uid, ids, {'state':'hr_check'}, context=context) +#TODO: to clean def verify_sheet(self, cr, uid, ids, context=None): move_pool = self.pool.get('account.move') movel_pool = self.pool.get('account.move.line') @@ -542,7 +296,6 @@ class hr_payslip(osv.osv): 'account_id': slip.employee_id.salary_account.id, 'debit': basic_amt, 'credit': 0.0, -# 'quantity':slip.working_days, 'journal_id': slip.journal_id.id, 'period_id': period_id, 'analytic_account_id': False, @@ -565,7 +318,6 @@ class hr_payslip(osv.osv): 'date': slip.date_from, 'account_id': slip.employee_id.employee_account.id, 'debit': 0.0, -# 'quantity':slip.working_days, 'credit': basic_amt, 'journal_id': slip.journal_id.id, 'period_id': period_id, @@ -577,10 +329,6 @@ class hr_payslip(osv.osv): continue name = "[%s] - %s / %s" % (line.code, line.name, slip.employee_id.name) amount = line.total - -# if line.type == 'leaves': -# continue - rec = { 'move_id': move_id, 'name': name, @@ -598,10 +346,6 @@ class hr_payslip(osv.osv): #Setting Analysis Account for Salary Slip Lines if line.analytic_account_id: rec['analytic_account_id'] = line.analytic_account_id.id -# else: -# rec['analytic_account_id'] = slip.deg_id.account_id.id - -# if line.type == 'allowance' or line.type == 'otherpay': if line.category_id.name == 'Allowance' : rec['debit'] = amount if not partner.property_account_payable: @@ -641,9 +385,6 @@ class hr_payslip(osv.osv): } line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] line_ids += [movel_pool.create(cr, uid, rec, context=context)] - # if self._debug: - # for contrib in line.category_id.contribute_ids: - # _log.debug("%s %s %s %s %s", contrib.name, contrub.code, contrub.amount_type, contrib.contribute_per, line.total) adj_move_id = False if total_deduct > 0: move = { @@ -695,39 +436,24 @@ class hr_payslip(osv.osv): if not slip.period_id: rec['period_id'] = period_id -# dates = prev_bounds(slip.date) exp_ids = exp_pool.search(cr, uid, [('date_valid','>=',slip.date_from), ('date_valid','<=',slip.date_to), ('state','=','invoiced')], context=context) -# if exp_ids: -# acc = property_pool.get(cr, uid, 'property_account_expense_categ', 'product.category') -# for exp in exp_pool.browse(cr, uid, exp_ids, context=context): -# exp_res = { -# 'name':exp.name, -# 'amount_type':'fix', -# 'type':'otherpay', -# 'category_id':exp.category_id.id, -# 'amount':exp.amount, -# 'slip_id':slip.id, -# 'expanse_id':exp.id, -# 'account_id':acc -# } -# payslip_pool.create(cr, uid, exp_res, context=context) self.write(cr, uid, [slip.id], rec, context=context) return True hr_payslip() -class hr_payslip_line(osv.osv): - _inherit = 'hr.payslip.line' - _columns = { - 'account_id': fields.many2one('account.account', 'General Account'), - 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'), - } -hr_payslip_line() +#TODO: remove, i don't think it's worth having that information on the payslip line rather than on the salary rule +#class hr_payslip_line(osv.osv): +# _inherit = 'hr.payslip.line' +# _columns = { +# 'account_id': fields.many2one('account.account', 'General Account'), +# 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'), +# } +#hr_payslip_line() class hr_salary_rule(osv.osv): _inherit = 'hr.salary.rule' _columns = { -# 'account_id': fields.many2one('account.account', 'General Account'), 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'), 'account_tax_id':fields.many2one('account.tax.code', 'Tax Code'), 'account_debit': fields.many2one('account.account', 'Debit Account'), @@ -735,27 +461,13 @@ class hr_salary_rule(osv.osv): } hr_salary_rule() -class account_move_link_slip(osv.osv): - ''' - Account Move Link to Pay Slip - ''' - _name = 'hr.payslip.account.move' - _description = 'Account Move Link to Pay Slip' - _columns = { - 'name':fields.char('Name', size=256, required=True, readonly=False), - 'move_id':fields.many2one('account.move', 'Expense Entries', required=False, readonly=True), - 'slip_id':fields.many2one('hr.payslip', 'Pay Slip', required=False), - 'sequence': fields.integer('Sequence'), - } -account_move_link_slip() - class hr_contract(osv.osv): _inherit = 'hr.contract' _description = 'Employee Contract' _columns = { 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'), - 'journal_id': fields.many2one('account.journal', 'Journal'), + 'journal_id': fields.many2one('account.journal', 'Salary Journal'), } hr_contract() From 6b5e01d3ea6827527263c2981e8a498a2802391f Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 12 May 2011 13:01:21 +0200 Subject: [PATCH 29/33] [IMP] hr_payroll_account: cleaning of views and implementation of compute_sheet method bzr revid: qdp-launchpad@openerp.com-20110512110121-mqo8bv40fc54wdp3 --- .../hr_payroll_account/hr_payroll_account.py | 627 ++++++++---------- .../hr_payroll_account_view.xml | 160 +---- 2 files changed, 284 insertions(+), 503 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 5e1e5fc1213..eb132d7595c 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -38,6 +38,14 @@ class contrib_register(osv.osv): } contrib_register() +#class account_move_line(osv.osv): +# +# _inherit = 'account.move.line' +# _columns = { +# 'slip_id': fields.many2one('hr.payslip', 'Payslip'), +# } +#account_move_line() + class hr_payslip(osv.osv): ''' Pay Slip @@ -47,10 +55,11 @@ class hr_payslip(osv.osv): _columns = { 'period_id': fields.many2one('account.period', 'Force Period',states={'draft': [('readonly', False)]}, readonly=True, domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), - 'journal_id': fields.many2one('account.journal', 'Expense Journal',states={'draft': [('readonly', False)]}, readonly=True), + 'journal_id': fields.many2one('account.journal', 'Expense Journal',states={'draft': [('readonly', False)]}, readonly=True, required=True), #TOCHECK: should we have a link to account.move or account.move.line? - #'move_line_ids':fields.many2many('account.move.line', 'payslip_lines_rel', 'slip_id', 'line_id', 'Accounting Lines', readonly=True), - 'account_move_ids': fields.many2many('account.move', 'payslip_move_rel', 'slip_id', 'move_id', 'Accounting Entries', readonly=True), + 'move_id': fields.many2one('account.move', 'Accounting Entry', readonly=True), + #'move_line_ids':fields.one2many('account.move.line', 'slip_id', 'Accounting Lines', readonly=True), + #'account_move_ids': fields.many2many('account.move', 'payslip_move_rel', 'slip_id', 'move_id', 'Accounting Entries', readonly=True), } def onchange_contract_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None): @@ -60,62 +69,17 @@ class hr_payslip(osv.osv): res['value'].update({'journal_id': journal_id}) return res -#FIXME: we need to overwrite a smaller code - def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): - journal_obj = self.pool.get('account.journal') - rule_obj = self.pool.get('hr.salary.rule') - contract_obj = self.pool.get('hr.contract') - structure_obj = self.pool.get('hr.payroll.structure') - vals_account = {} - result = super(hr_payslip, self).get_payslip_lines(cr, uid, contract_ids, payslip_id, context) - structure_ids = contract_obj.get_all_structures(cr, uid, contract_ids, context=context) - #get the rules of the structure and thier children - rule_ids = structure_obj.get_all_rules(cr, uid, structure_ids, context=context) - sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])] - #Fetching Debit/Credit account of the payslip journal. - journal = self.browse(cr, uid, payslip_id, context=context).journal_id - credit_account = journal.default_credit_account_id and journal.default_credit_account_id.id or False - debit_account = journal.default_debit_account_id and journal.default_debit_account_id.id or False - # Assigning above fetched Debit/Credit account on salary rules if not specified - for rule in rule_obj.browse(cr, uid, sorted_rule_ids, context=context): - if not rule.account_debit.id: - rule_obj.write(cr, uid, [rule.id], {'account_debit': debit_account}) - if not rule.account_credit.id: - rule_obj.write(cr, uid, [rule.id], {'account_credit': credit_account}) - #Assigning Debit/Credit account on payslip lines - for value in result: - if value['salary_rule_id'] == rule.id: - if rule.category_id.name == 'Deduction': - if not rule.account_debit.id: - value['account_id'] = debit_account - else: - value['account_id'] = rule.account_debit.id - elif rule.category_id.name == 'Allowance': - if not rule.account_credit.id: - value['account_id'] = credit_account - else: - value['account_id'] = rule.account_credit.id - else: - emp_account_id = self.browse(cr, uid, payslip_id, context=context).employee_id.employee_account.id - value['account_id'] = emp_account_id - if rule.analytic_account_id: - value['analytic_account_id'] = rule.analytic_account_id.id - return result - -#TODO: to correct def cancel_sheet(self, cr, uid, ids, context=None): move_pool = self.pool.get('account.move') - slip_move = self.pool.get('hr.payslip.account.move') move_ids = [] + move_to_cancel = [] for slip in self.browse(cr, uid, ids, context=context): - for line in slip.move_ids: - move_ids.append(line.id) - if line.move_id: - if line.move_id.state == 'posted': - move_pool.button_cancel(cr, uid [line.move_id.id], context) - move_pool.unlink(cr, uid, [line.move_id.id], context=context) - slip_move.unlink(cr, uid, move_ids, context=context) - return self.write(cr, uid, ids, {'state':'cancel'}, context=context) + move_ids.append(slip.move_id.id) + if slip.move_id.state == 'posted': + move_to_cancel.append(slip.move_id.id) + move_pool.button_cancel(cr, uid, move_to_cancel, context=context) + move_pool.unlink(cr, uid, move_ids, context=context) + return super(hr_payslip, self).cancel_sheet(cr, uid, ids, context=context) #TODO: to correct def process_sheet(self, cr, uid, ids, context=None): @@ -126,10 +90,6 @@ class hr_payslip(osv.osv): period_pool = self.pool.get('account.period') for slip in self.browse(cr, uid, ids, context=context): - if not slip.bank_journal_id or not slip.journal_id: - # Call super method to process sheet if journal_id or bank_journal_id are not specified. - super(hr_payslip, self).process_sheet(cr, uid, [slip.id], context=context) - continue line_ids = [] partner = False partner_id = False @@ -137,310 +97,276 @@ class hr_payslip(osv.osv): partner = slip.employee_id.bank_account_id.partner_id partner_id = partner.id - - for line in slip.line_ids: - if line.category_id.name == 'Net': - amt = line.total - - fiscal_year_ids = fiscalyear_pool.search(cr, uid, [], context=context) - if not fiscal_year_ids: - raise osv.except_osv(_('Warning !'), _('Please define fiscal year for perticular contract')) - fiscal_year_objs = fiscalyear_pool.read(cr, uid, fiscal_year_ids, ['date_start','date_stop'], context=context) - year_exist = False - for fiscal_year in fiscal_year_objs: - if ((fiscal_year['date_start'] <= slip.date_from) and (fiscal_year['date_stop'] >= slip.date_to)): - year_exist = True - if not year_exist: - raise osv.except_osv(_('Warning !'), _('Fiscal Year is not defined for slip date %s') % slip.date) - search_periods = period_pool.search(cr, uid, [('date_start','<=',slip.date_from),('date_stop','>=',slip.date_to)], context=context) - if not search_periods: - raise osv.except_osv(_('Warning !'), _('Period is not defined for slip date %s') % slip.date) - period_id = search_periods[0] - name = 'Payment of Salary to %s' % (slip.employee_id.name) - move = { - 'journal_id': slip.bank_journal_id.id, - 'period_id': period_id, - 'date': slip.date_from, - 'type':'bank_pay_voucher', - 'ref':slip.number, - 'narration': name - } - move_id = move_pool.create(cr, uid, move, context=context) - self.create_voucher(cr, uid, [slip.id], name, move_id) - - name = "To %s account" % (slip.employee_id.name) - - if not slip.employee_id.property_bank_account.id: - raise osv.except_osv(_('Warning !'), _('Employee Bank Account is not defined for %s') % slip.employee_id.name) - - ded_rec = { - 'move_id': move_id, - 'name': name, - 'date': slip.date_from, - 'account_id': slip.employee_id.property_bank_account.id, - 'debit': 0.0, - 'credit': amt, - 'journal_id': slip.journal_id.id, - 'period_id': period_id, - 'ref': slip.number - } - line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] - name = "By %s account" % (slip.employee_id.property_bank_account.name) - cre_rec = { - 'move_id': move_id, - 'name': name, - 'partner_id': partner_id, - 'date': slip.date_from, - 'account_id': partner.property_account_payable.id, - 'debit': amt, - 'credit': 0.0, - 'journal_id': slip.journal_id.id, - 'period_id': period_id, - 'ref': slip.number - } - line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)] - - - rec = { - 'state':'done', - 'move_payment_ids':[(6, 0, line_ids)], - 'paid':True, - 'account_move_ids': [(4, move_id)], - } - self.write(cr, uid, [slip.id], rec, context=context) - for exp_id in exp_ids: - self.write(cr, uid, [slip.id], {'move_line_ids':[(4, exp_id)]}, context=context) - - return True - -#TODO: to clean - def account_check_sheet(self, cr, uid, ids, context=None): - return self.write(cr, uid, ids, {'state':'accont_check'}, context=context) -#TODO: to clean - - def hr_check_sheet(self, cr, uid, ids, context=None): - return self.write(cr, uid, ids, {'state':'hr_check'}, context=context) - -#TODO: to clean - def verify_sheet(self, cr, uid, ids, context=None): - move_pool = self.pool.get('account.move') - movel_pool = self.pool.get('account.move.line') - exp_pool = self.pool.get('hr.expense.expense') - fiscalyear_pool = self.pool.get('account.fiscalyear') - period_pool = self.pool.get('account.period') - property_pool = self.pool.get('ir.property') - payslip_pool = self.pool.get('hr.payslip.line') - - for slip in self.browse(cr, uid, ids, context=context): - for line in slip.line_ids: - if line.category_id.name == 'Basic': - basic_amt = line.total - if not slip.journal_id: - # Call super method to verify sheet if journal_id is not specified. - super(hr_payslip, self).verify_sheet(cr, uid, [slip.id], context=context) - continue - total_deduct = 0.0 - - line_ids = [] - move_ids = [] - partner = False - partner_id = False - - if not slip.employee_id.bank_account_id: - raise osv.except_osv(_('Integrity Error !'), _('Please define bank account for %s !') % (slip.employee_id.name)) - - if not slip.employee_id.bank_account_id.partner_id: - raise osv.except_osv(_('Integrity Error !'), _('Please define partner in bank account for %s !') % (slip.employee_id.name)) - - partner = slip.employee_id.bank_account_id.partner_id - partner_id = slip.employee_id.bank_account_id.partner_id.id - - period_id = False - - if slip.period_id: - period_id = slip.period_id.id - else: - fiscal_year_ids = fiscalyear_pool.search(cr, uid, [], context=context) - if not fiscal_year_ids: - raise osv.except_osv(_('Warning !'), _('Please define fiscal year for perticular contract')) - fiscal_year_objs = fiscalyear_pool.read(cr, uid, fiscal_year_ids, ['date_start','date_stop'], context=context) - year_exist = False - for fiscal_year in fiscal_year_objs: - if ((fiscal_year['date_start'] <= slip.date_from) and (fiscal_year['date_stop'] >= slip.date_to)): - year_exist = True - if not year_exist: - raise osv.except_osv(_('Warning !'), _('Fiscal Year is not defined for slip date %s') % slip.date) - search_periods = period_pool.search(cr,uid,[('date_start','=',slip.date_from),('date_stop','=',slip.date_to)], context=context) + if not slip.period_id: + search_periods = period_pool.search(cr, uid, [('date_start','<=',slip.date_from),('date_stop','>=',slip.date_to)], context=context) if not search_periods: raise osv.except_osv(_('Warning !'), _('Period is not defined for slip date %s') % slip.date) period_id = search_periods[0] + else: + period_id = slip.period_id.id + name = _('Payslip of %s') % (slip.employee_id.name) move = { 'journal_id': slip.journal_id.id, 'period_id': period_id, - 'date': slip.date_from, + 'date': timenow, 'ref':slip.number, - 'narration': slip.name + 'narration': name } - move_id = move_pool.create(cr, uid, move, context=context) - move_ids += [move_id] - self.create_voucher(cr, uid, [slip.id], slip.name, move_id) - - if not slip.employee_id.salary_account.id: - raise osv.except_osv(_('Warning !'), _('Please define Salary Account for %s.') % slip.employee_id.name) - - line = { - 'move_id':move_id, - 'name': "By Basic Salary / " + slip.employee_id.name, - 'date': slip.date_from, - 'account_id': slip.employee_id.salary_account.id, - 'debit': basic_amt, - 'credit': 0.0, - 'journal_id': slip.journal_id.id, - 'period_id': period_id, - 'analytic_account_id': False, - 'ref':slip.number - } - #Setting Analysis Account for Basic Salary - if slip.employee_id.analytic_account: - line['analytic_account_id'] = slip.employee_id.analytic_account.id - - move_line_id = movel_pool.create(cr, uid, line, context=context) - line_ids += [move_line_id] - - if not slip.employee_id.employee_account.id: - raise osv.except_osv(_('Warning !'), _('Please define Employee Payable Account for %s.') % slip.employee_id.name) - - line = { - 'move_id':move_id, - 'name': "To Basic Payble Salary / " + slip.employee_id.name, - 'partner_id': partner_id, - 'date': slip.date_from, - 'account_id': slip.employee_id.employee_account.id, - 'debit': 0.0, - 'credit': basic_amt, - 'journal_id': slip.journal_id.id, - 'period_id': period_id, - 'ref':slip.number - } - line_ids += [movel_pool.create(cr, uid, line, context=context)] for line in slip.line_ids: - if line.name == 'Net' or line.name == 'Gross' or line.name == 'Basic': - continue - name = "[%s] - %s / %s" % (line.code, line.name, slip.employee_id.name) - amount = line.total - rec = { - 'move_id': move_id, - 'name': name, - 'date': slip.date_from, - 'account_id': line.account_id.id, - 'debit': 0.0, - 'credit': 0.0, - 'journal_id': slip.journal_id.id, - 'period_id': period_id, - 'analytic_account_id': False, - 'ref': slip.number, - 'quantity': 1 - } - - #Setting Analysis Account for Salary Slip Lines - if line.analytic_account_id: - rec['analytic_account_id'] = line.analytic_account_id.id - if line.category_id.name == 'Allowance' : - rec['debit'] = amount - if not partner.property_account_payable: - raise osv.except_osv(_('Integrity Error !'), _('Please Configure Partners Payable Account!!')) - ded_rec = { - 'move_id': move_id, + if line.salary_rule_id.accounting_select != 'none': + amt = slip.credit_note and -line.total or line.total + partner_id = False + name = line.name + debit_account_id = line.salary_rule_id.debit_account_id.id + credit_account_id = line.salary_rule_id.credit_account_id.id + if line.salary_rule_id.accounting_select == 'third_party': + if line.salary_rule_id.register_id: + credit_account_id = line.salary_rule_id.register_id.account_id.id + else: + partner_id = slip.employee_id.partner_id.id + debit_line = (0,0,{ + 'name': line.name, + 'account_id': debit_account_id, + 'debit': amt > 0.0 and amt or 0.0, + 'credit': amt < 0.0 and -amt or 0.0, + }) + credit_line = (0,0,{ 'name': name, 'partner_id': partner_id, - 'date': slip.date_from, - 'account_id': partner.property_account_payable.id, - 'debit': 0.0, - 'quantity': 1, - 'credit': amount, - 'journal_id': slip.journal_id.id, - 'period_id': period_id, - 'ref': slip.number - } - line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] - elif line.category_id.name == 'Deduction': - if not partner.property_account_receivable: - raise osv.except_osv(_('Integrity Error !'), _('Please Configure Partners Receivable Account!!')) - amount = -(amount) - rec['credit'] = amount - total_deduct += amount - ded_rec = { - 'move_id': move_id, - 'name': name, - 'partner_id': partner_id, - 'date': slip.date_from, - 'quantity': 1, - 'account_id': partner.property_account_receivable.id, - 'debit': amount, - 'credit': 0.0, - 'journal_id': slip.journal_id.id, - 'period_id': period_id, - 'ref': slip.number - } - line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] - line_ids += [movel_pool.create(cr, uid, rec, context=context)] - adj_move_id = False - if total_deduct > 0: - move = { - 'journal_id': slip.journal_id.id, - 'period_id': period_id, - 'date': slip.date_from, - 'ref':slip.number, - 'narration': 'Adjustment: %s' % (slip.name) - } - adj_move_id = move_pool.create(cr, uid, move, context=context) - move_ids += [adj_move_id] - name = "Adjustment Entry - %s" % (slip.employee_id.name) - self.create_voucher(cr, uid, [slip.id], name, adj_move_id) + 'account_id': credit_account_id, + 'debit': amt < 0.0 and -amt or 0.0, + 'credit': amt > 0.0 and amt or 0.0, + }) + if debit_account_id: + line_ids.append(debit_line) + if credit_account_id: + line_ids.append(credit_line) + move.update({'line_ids': line_ids}) + move_id = move_pool.create(cr, uid, move, context=context) + self.write(cr, uid, [slip.id], {'move_id': move_id}, context=context) + return super(hr_payslip, self).process_sheet(cr, uid, [slip.id], context=context) - ded_rec = { - 'move_id': adj_move_id, - 'name': name, - 'partner_id': partner_id, - 'date': slip.date_from, - 'account_id': partner.property_account_receivable.id, - 'debit': 0.0, - 'quantity': 1, - 'credit': total_deduct, - 'journal_id': slip.journal_id.id, - 'period_id': period_id, - 'ref': slip.number - } - line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] - cre_rec = { - 'move_id': adj_move_id, - 'name': name, - 'partner_id': partner_id, - 'date': slip.date_from, - 'account_id': partner.property_account_payable.id, - 'debit': total_deduct, - 'quantity': 1, - 'credit': 0.0, - 'journal_id': slip.journal_id.id, - 'period_id': period_id, - 'ref': slip.number - } - line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)] - - rec = { - 'state':'confirm', - 'move_line_ids':[(6, 0,line_ids)], - 'account_move_ids':[(6, 0, move_ids)] - } - if not slip.period_id: - rec['period_id'] = period_id - - exp_ids = exp_pool.search(cr, uid, [('date_valid','>=',slip.date_from), ('date_valid','<=',slip.date_to), ('state','=','invoiced')], context=context) - self.write(cr, uid, [slip.id], rec, context=context) - return True - -hr_payslip() +#TODO: to clean: the verofying doesn't do anything in the accounting.. +# def verify_sheet(self, cr, uid, ids, context=None): +# move_pool = self.pool.get('account.move') +# movel_pool = self.pool.get('account.move.line') +# exp_pool = self.pool.get('hr.expense.expense') +# fiscalyear_pool = self.pool.get('account.fiscalyear') +# period_pool = self.pool.get('account.period') +# property_pool = self.pool.get('ir.property') +# payslip_pool = self.pool.get('hr.payslip.line') +# +# for slip in self.browse(cr, uid, ids, context=context): +# for line in slip.line_ids: +# if line.category_id.name == 'Basic': +# basic_amt = line.total +# if not slip.journal_id: +# # Call super method to verify sheet if journal_id is not specified. +# super(hr_payslip, self).verify_sheet(cr, uid, [slip.id], context=context) +# continue +# total_deduct = 0.0 +# +# line_ids = [] +# move_ids = [] +# partner = False +# partner_id = False +# +# if not slip.employee_id.bank_account_id: +# raise osv.except_osv(_('Integrity Error !'), _('Please define bank account for %s !') % (slip.employee_id.name)) +# +# if not slip.employee_id.bank_account_id.partner_id: +# raise osv.except_osv(_('Integrity Error !'), _('Please define partner in bank account for %s !') % (slip.employee_id.name)) +# +# partner = slip.employee_id.bank_account_id.partner_id +# partner_id = slip.employee_id.bank_account_id.partner_id.id +# +# period_id = False +# +# if slip.period_id: +# period_id = slip.period_id.id +# else: +# fiscal_year_ids = fiscalyear_pool.search(cr, uid, [], context=context) +# if not fiscal_year_ids: +# raise osv.except_osv(_('Warning !'), _('Please define fiscal year for perticular contract')) +# fiscal_year_objs = fiscalyear_pool.read(cr, uid, fiscal_year_ids, ['date_start','date_stop'], context=context) +# year_exist = False +# for fiscal_year in fiscal_year_objs: +# if ((fiscal_year['date_start'] <= slip.date_from) and (fiscal_year['date_stop'] >= slip.date_to)): +# year_exist = True +# if not year_exist: +# raise osv.except_osv(_('Warning !'), _('Fiscal Year is not defined for slip date %s') % slip.date) +# search_periods = period_pool.search(cr,uid,[('date_start','=',slip.date_from),('date_stop','=',slip.date_to)], context=context) +# if not search_periods: +# raise osv.except_osv(_('Warning !'), _('Period is not defined for slip date %s') % slip.date) +# period_id = search_periods[0] +# +# move = { +# 'journal_id': slip.journal_id.id, +# 'period_id': period_id, +# 'date': slip.date_from, +# 'ref':slip.number, +# 'narration': slip.name +# } +# move_id = move_pool.create(cr, uid, move, context=context) +# move_ids += [move_id] +# self.create_voucher(cr, uid, [slip.id], slip.name, move_id) +# +# if not slip.employee_id.salary_account.id: +# raise osv.except_osv(_('Warning !'), _('Please define Salary Account for %s.') % slip.employee_id.name) +# +# line = { +# 'move_id':move_id, +# 'name': "By Basic Salary / " + slip.employee_id.name, +# 'date': slip.date_from, +# 'account_id': slip.employee_id.salary_account.id, +# 'debit': basic_amt, +# 'credit': 0.0, +# 'journal_id': slip.journal_id.id, +# 'period_id': period_id, +# 'analytic_account_id': False, +# 'ref':slip.number +# } +# #Setting Analysis Account for Basic Salary +# if slip.employee_id.analytic_account: +# line['analytic_account_id'] = slip.employee_id.analytic_account.id +# +# move_line_id = movel_pool.create(cr, uid, line, context=context) +# line_ids += [move_line_id] +# +# if not slip.employee_id.employee_account.id: +# raise osv.except_osv(_('Warning !'), _('Please define Employee Payable Account for %s.') % slip.employee_id.name) +# +# line = { +# 'move_id':move_id, +# 'name': "To Basic Payble Salary / " + slip.employee_id.name, +# 'partner_id': partner_id, +# 'date': slip.date_from, +# 'account_id': slip.employee_id.employee_account.id, +# 'debit': 0.0, +# 'credit': basic_amt, +# 'journal_id': slip.journal_id.id, +# 'period_id': period_id, +# 'ref':slip.number +# } +# line_ids += [movel_pool.create(cr, uid, line, context=context)] +# for line in slip.line_ids: +# if line.name == 'Net' or line.name == 'Gross' or line.name == 'Basic': +# continue +# name = "[%s] - %s / %s" % (line.code, line.name, slip.employee_id.name) +# amount = line.total +# rec = { +# 'move_id': move_id, +# 'name': name, +# 'date': slip.date_from, +# 'account_id': line.account_id.id, +# 'debit': 0.0, +# 'credit': 0.0, +# 'journal_id': slip.journal_id.id, +# 'period_id': period_id, +# 'analytic_account_id': False, +# 'ref': slip.number, +# 'quantity': 1 +# } +# +# #Setting Analysis Account for Salary Slip Lines +# if line.analytic_account_id: +# rec['analytic_account_id'] = line.analytic_account_id.id +# if line.category_id.name == 'Allowance' : +# rec['debit'] = amount +# if not partner.property_account_payable: +# raise osv.except_osv(_('Integrity Error !'), _('Please Configure Partners Payable Account!!')) +# ded_rec = { +# 'move_id': move_id, +# 'name': name, +# 'partner_id': partner_id, +# 'date': slip.date_from, +# 'account_id': partner.property_account_payable.id, +# 'debit': 0.0, +# 'quantity': 1, +# 'credit': amount, +# 'journal_id': slip.journal_id.id, +# 'period_id': period_id, +# 'ref': slip.number +# } +# line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] +# elif line.category_id.name == 'Deduction': +# if not partner.property_account_receivable: +# raise osv.except_osv(_('Integrity Error !'), _('Please Configure Partners Receivable Account!!')) +# amount = -(amount) +# rec['credit'] = amount +# total_deduct += amount +# ded_rec = { +# 'move_id': move_id, +# 'name': name, +# 'partner_id': partner_id, +# 'date': slip.date_from, +# 'quantity': 1, +# 'account_id': partner.property_account_receivable.id, +# 'debit': amount, +# 'credit': 0.0, +# 'journal_id': slip.journal_id.id, +# 'period_id': period_id, +# 'ref': slip.number +# } +# line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] +# line_ids += [movel_pool.create(cr, uid, rec, context=context)] +# adj_move_id = False +# if total_deduct > 0: +# move = { +# 'journal_id': slip.journal_id.id, +# 'period_id': period_id, +# 'date': slip.date_from, +# 'ref':slip.number, +# 'narration': 'Adjustment: %s' % (slip.name) +# } +# adj_move_id = move_pool.create(cr, uid, move, context=context) +# move_ids += [adj_move_id] +# name = "Adjustment Entry - %s" % (slip.employee_id.name) +# self.create_voucher(cr, uid, [slip.id], name, adj_move_id) +# +# ded_rec = { +# 'move_id': adj_move_id, +# 'name': name, +# 'partner_id': partner_id, +# 'date': slip.date_from, +# 'account_id': partner.property_account_receivable.id, +# 'debit': 0.0, +# 'quantity': 1, +# 'credit': total_deduct, +# 'journal_id': slip.journal_id.id, +# 'period_id': period_id, +# 'ref': slip.number +# } +# line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] +# cre_rec = { +# 'move_id': adj_move_id, +# 'name': name, +# 'partner_id': partner_id, +# 'date': slip.date_from, +# 'account_id': partner.property_account_payable.id, +# 'debit': total_deduct, +# 'quantity': 1, +# 'credit': 0.0, +# 'journal_id': slip.journal_id.id, +# 'period_id': period_id, +# 'ref': slip.number +# } +# line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)] +# +# rec = { +# 'state':'confirm', +# 'move_line_ids':[(6, 0,line_ids)], +# 'account_move_ids':[(6, 0, move_ids)] +# } +# if not slip.period_id: +# rec['period_id'] = period_id +# +# exp_ids = exp_pool.search(cr, uid, [('date_valid','>=',slip.date_from), ('date_valid','<=',slip.date_to), ('state','=','invoiced')], context=context) +# self.write(cr, uid, [slip.id], rec, context=context) +# return True +# +#hr_payslip() #TODO: remove, i don't think it's worth having that information on the payslip line rather than on the salary rule #class hr_payslip_line(osv.osv): @@ -454,6 +380,7 @@ hr_payslip() class hr_salary_rule(osv.osv): _inherit = 'hr.salary.rule' _columns = { + 'accounting_select':fields.selection([('none', 'No Accounting Entries'), ('third_party', 'To Employee or contribution Register'), ('yes','Regular Entries')], 'Accounting Entries Option'), 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'), 'account_tax_id':fields.many2one('account.tax.code', 'Tax Code'), 'account_debit': fields.many2one('account.account', 'Debit Account'), diff --git a/addons/hr_payroll_account/hr_payroll_account_view.xml b/addons/hr_payroll_account/hr_payroll_account_view.xml index aec5b6ebee7..4b36508138d 100644 --- a/addons/hr_payroll_account/hr_payroll_account_view.xml +++ b/addons/hr_payroll_account/hr_payroll_account_view.xml @@ -2,43 +2,7 @@ - - hr.payslip.line.inherit.tree - hr.payslip.line - - tree - - - - - - - - - hr.payslip.line.inherit.form - hr.payslip.line - - form - - - - - - - - - hr.payslip.inherit.form @@ -46,41 +10,10 @@ form - + + - - - - - - - - - hr.payslip.form.inherit1 - hr.payslip - form - - - - - - - - - - - - - - - hr.contribution.register.inherit.tree - hr.contribution.register - - tree - - - - + @@ -94,91 +27,11 @@ - + - - - - hr.payslip.form - hr.payslip - form - - - - - - - - - - - - -
- - - - - -
- - - - - - - - - - -
- - - - - - - - - -
-
-
- - - - - hr.employee.payroll.property.form - hr.employee - - - - - - - - - - - @@ -188,9 +41,10 @@ + - + @@ -207,7 +61,7 @@ - + From b98ea8905e2a1dd72230665f3126cd4021470392 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 12 May 2011 13:02:43 +0200 Subject: [PATCH 30/33] [IMP] hr_payroll_account: no need of new security rules in the module hr_payroll_account bzr revid: qdp-launchpad@openerp.com-20110512110243-9ixjk1ywyxwn00a6 --- addons/hr_payroll_account/__openerp__.py | 1 - addons/hr_payroll_account/security/ir.model.access.csv | 4 ---- 2 files changed, 5 deletions(-) delete mode 100644 addons/hr_payroll_account/security/ir.model.access.csv diff --git a/addons/hr_payroll_account/__openerp__.py b/addons/hr_payroll_account/__openerp__.py index 99da1d6b451..2c6e5bf51b9 100644 --- a/addons/hr_payroll_account/__openerp__.py +++ b/addons/hr_payroll_account/__openerp__.py @@ -42,7 +42,6 @@ Generic Payroll system Integrated with Accountings. 'init_xml': [ ], 'update_xml': [ - "security/ir.model.access.csv", "hr_payroll_account_view.xml", ], 'demo_xml': [ diff --git a/addons/hr_payroll_account/security/ir.model.access.csv b/addons/hr_payroll_account/security/ir.model.access.csv deleted file mode 100644 index 32f98a3a9ff..00000000000 --- a/addons/hr_payroll_account/security/ir.model.access.csv +++ /dev/null @@ -1,4 +0,0 @@ -"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -"access_hr_payslip_account_move_user","access.hr.payslip.account.move.user","model_hr_payslip_account_move","base.group_user",1,0,0,0 -"access_hr_payslip_user","access.hr.payslip.user","model_hr_payslip","base.group_user",1,0,0,0 -"access_hr_payslip_line_user","access.hr.payslip.line.user","model_hr_payslip_line","base.group_user",1,0,0,0 From e9e490b1fee0c02ccc172cecf2849bc9d8aa83d0 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 12 May 2011 13:07:03 +0200 Subject: [PATCH 31/33] [FIX] hr_payroll_account: removed the reference to old and removed objects bzr revid: qdp-launchpad@openerp.com-20110512110703-9ri4udog0gdmo422 --- .../hr_payroll_account_demo.xml | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account_demo.xml b/addons/hr_payroll_account/hr_payroll_account_demo.xml index 5d246342e53..c038025bb0a 100644 --- a/addons/hr_payroll_account/hr_payroll_account_demo.xml +++ b/addons/hr_payroll_account/hr_payroll_account_demo.xml @@ -105,27 +105,6 @@ - - - property_bank_account - - - - - - - salary_account - - - - - - - employee_account - - - -
From 6abc27ba6d23a075aa6e056acaef2f71e36fd6d3 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 12 May 2011 13:47:49 +0200 Subject: [PATCH 32/33] [FIX] hr_payroll_account: debugged the process_sheet method() bzr revid: qdp-launchpad@openerp.com-20110512114749-bbpukg17a3kad67q --- .../hr_payroll_account/hr_payroll_account.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index eb132d7595c..a58aed22730 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -65,7 +65,7 @@ class hr_payslip(osv.osv): def onchange_contract_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None): contract_obj = self.pool.get('hr.contract') res = super(hr_payslip, self).onchange_contract_id(cr, uid, ids, date_from=date_from, date_to=date_to, employee_id=employee_id, contract_id=contract_id, context=context) - journal_id = contract_obj.browse(cr, uid, contract_id, context=context).journal_id.id + journal_id = contract_id and contract_obj.browse(cr, uid, contract_id, context=context).journal_id.id or False res['value'].update({'journal_id': journal_id}) return res @@ -86,17 +86,12 @@ class hr_payslip(osv.osv): move_pool = self.pool.get('account.move') movel_pool = self.pool.get('account.move.line') invoice_pool = self.pool.get('account.invoice') - fiscalyear_pool = self.pool.get('account.fiscalyear') period_pool = self.pool.get('account.period') + timenow = time.strftime('%Y-%m-%d') for slip in self.browse(cr, uid, ids, context=context): line_ids = [] - partner = False - partner_id = False - exp_ids = [] - partner = slip.employee_id.bank_account_id.partner_id - partner_id = partner.id if not slip.period_id: search_periods = period_pool.search(cr, uid, [('date_start','<=',slip.date_from),('date_stop','>=',slip.date_to)], context=context) if not search_periods: @@ -118,8 +113,8 @@ class hr_payslip(osv.osv): amt = slip.credit_note and -line.total or line.total partner_id = False name = line.name - debit_account_id = line.salary_rule_id.debit_account_id.id - credit_account_id = line.salary_rule_id.credit_account_id.id + debit_account_id = line.salary_rule_id.account_debit.id + credit_account_id = line.salary_rule_id.account_credit.id if line.salary_rule_id.accounting_select == 'third_party': if line.salary_rule_id.register_id: credit_account_id = line.salary_rule_id.register_id.account_id.id @@ -130,8 +125,14 @@ class hr_payslip(osv.osv): 'account_id': debit_account_id, 'debit': amt > 0.0 and amt or 0.0, 'credit': amt < 0.0 and -amt or 0.0, + 'date': timenow, + 'journal_id': slip.journal_id.id, + 'period_id': period_id, }) credit_line = (0,0,{ + 'date': timenow, + 'journal_id': slip.journal_id.id, + 'period_id': period_id, 'name': name, 'partner_id': partner_id, 'account_id': credit_account_id, @@ -142,7 +143,7 @@ class hr_payslip(osv.osv): line_ids.append(debit_line) if credit_account_id: line_ids.append(credit_line) - move.update({'line_ids': line_ids}) + move.update({'line_id': line_ids}) move_id = move_pool.create(cr, uid, move, context=context) self.write(cr, uid, [slip.id], {'move_id': move_id}, context=context) return super(hr_payslip, self).process_sheet(cr, uid, [slip.id], context=context) @@ -366,7 +367,7 @@ class hr_payslip(osv.osv): # self.write(cr, uid, [slip.id], rec, context=context) # return True # -#hr_payslip() +hr_payslip() #TODO: remove, i don't think it's worth having that information on the payslip line rather than on the salary rule #class hr_payslip_line(osv.osv): From 211844634fbc5da084f49981f55d6d5768c93228 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Thu, 12 May 2011 19:09:40 +0530 Subject: [PATCH 33/33] [IMP] pass details_by_salary_rule_category instead of line_ids so the report will show payslip_lines with rule as Appear on payslip checked bzr revid: psi@tinyerp.co.in-20110512133940-cwmcdbtl3rz8giru --- addons/hr_payroll/report/report_payslip.rml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/hr_payroll/report/report_payslip.rml b/addons/hr_payroll/report/report_payslip.rml index 5be4e17a875..02c97e1ec62 100644 --- a/addons/hr_payroll/report/report_payslip.rml +++ b/addons/hr_payroll/report/report_payslip.rml @@ -404,7 +404,7 @@
- [[repeatIn(get_details_by_rule_category(o.line_ids),'h') ]] + [[repeatIn(get_details_by_rule_category(o.details_by_salary_rule_category),'h') ]] @@ -452,7 +452,7 @@
- [[repeatIn(get_lines_by_contribution_register(o.line_ids),'r') ]] + [[repeatIn(get_lines_by_contribution_register(o.details_by_salary_rule_category),'r') ]]