diff --git a/addons/hr/hr_view.xml b/addons/hr/hr_view.xml index 55415ed8088..6d826db1a6b 100644 --- a/addons/hr/hr_view.xml +++ b/addons/hr/hr_view.xml @@ -4,10 +4,9 @@ - - - + + + diff --git a/addons/hr_evaluation/hr_evaluation.py b/addons/hr_evaluation/hr_evaluation.py index 429b492131d..21ca0423c9a 100644 --- a/addons/hr_evaluation/hr_evaluation.py +++ b/addons/hr_evaluation/hr_evaluation.py @@ -104,18 +104,22 @@ class hr_employee(osv.osv): } def run_employee_evaluation(self, cr, uid, automatic=False, use_new_cursor=False, context=None): + obj_evaluation = self.pool.get('hr_evaluation.evaluation') if context is None: context = {} for id in self.browse(cr, uid, self.search(cr, uid, [], context=context), context=context): if id.evaluation_plan_id and id.evaluation_date: if (dt.ISO.ParseAny(id.evaluation_date) + dt.RelativeDateTime(months = int(id.evaluation_plan_id.month_next))).strftime('%Y-%m-%d') <= time.strftime("%Y-%m-%d"): self.write(cr, uid, id.id, {'evaluation_date' : (dt.ISO.ParseAny(id.evaluation_date) + dt.RelativeDateTime(months =+ int(id.evaluation_plan_id.month_next))).strftime('%Y-%m-%d')}, context=context) - self.pool.get("hr_evaluation.evaluation").create(cr, uid, {'employee_id' : id.id, 'plan_id': id.evaluation_plan_id}, context) + obj_evaluation.create(cr, uid, {'employee_id' : id.id, 'plan_id': id.evaluation_plan_id}, context=context) return True def onchange_evaluation_plan_id(self, cr, uid, ids, evaluation_plan_id, evaluation_date, context=None): evaluation_date = evaluation_date or False evaluation_plan_obj=self.pool.get('hr_evaluation.plan') + obj_evaluation = self.pool.get('hr_evaluation.evaluation') + if context is None: + context = {} if evaluation_plan_id: flag = False evaluation_plan = evaluation_plan_obj.browse(cr, uid, [evaluation_plan_id], context=context)[0] @@ -131,9 +135,11 @@ class hr_employee(osv.osv): return {'value': {'evaluation_date': evaluation_date}} def create(self, cr, uid, vals, context=None): + if context is None: + context = {} id = super(hr_employee, self).create(cr, uid, vals, context=context) if vals.get('evaluation_plan_id', False): - self.pool.get("hr_evaluation.evaluation").create(cr, uid, {'employee_id' : id, 'plan_id': vals['evaluation_plan_id']}, context=context) + obj_evaluation.create(cr, uid, {'employee_id' : id, 'plan_id': vals['evaluation_plan_id']}, context=context) return id hr_employee() @@ -173,10 +179,12 @@ class hr_evaluation(osv.osv): 'state' : lambda *a: 'draft', } - def name_get(self, cr, uid, ids, context={}): + def name_get(self, cr, uid, ids, context=None): + if context is None: + context = {} if not len(ids): return [] - reads = self.browse(cr, uid, ids, context) + reads = self.browse(cr, uid, ids, context=context) res = [] for record in reads: name = record.plan_id.name @@ -185,6 +193,8 @@ class hr_evaluation(osv.osv): def onchange_employee_id(self, cr, uid, ids, employee_id, context=None): employee_obj=self.pool.get('hr.employee') + if context is None: + context = {} evaluation_plan_id='' if employee_id: for employee in employee_obj.browse(cr, uid, [employee_id], context=context): @@ -194,8 +204,11 @@ class hr_evaluation(osv.osv): return {'value': {'plan_id':evaluation_plan_id}} def button_plan_in_progress(self, cr, uid, ids, context=None): + hr_eval_inter_obj = self.pool.get('hr.evaluation.interview') + if context is None: + context = {} apprai_id = [] - for evaluation in self.browse(cr, uid, ids, context): + for evaluation in self.browse(cr, uid, ids, context=context): wait = False for phase in evaluation.plan_id.phase_ids: childs = [] @@ -210,7 +223,6 @@ class hr_evaluation(osv.osv): if not child.user_id: continue - hr_eval_inter_obj = self.pool.get('hr.evaluation.interview') int_id = hr_eval_inter_obj.create(cr, uid, { 'evaluation_id': evaluation.id, 'survey_id': phase.survey_id.id, @@ -235,18 +247,24 @@ class hr_evaluation(osv.osv): return True def button_final_validation(self, cr, uid, ids, context=None): - self.write(cr, uid, ids, {'state':'progress'}) request_obj = self.pool.get('hr.evaluation.interview') - for id in self.browse(cr, uid ,ids,context=context): - if len(id.survey_request_ids) != len(request_obj.search(cr, uid, [('evaluation_id', '=', id.id),('state', '=', 'done')],context=context)): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'progress'}, context=context) + for id in self.browse(cr, uid ,ids, context=context): + if len(id.survey_request_ids) != len(request_obj.search(cr, uid, [('evaluation_id', '=', id.id),('state', '=', 'done')], context=context)): raise osv.except_osv(_('Warning !'),_("You cannot change state, because some appraisal in waiting answer or draft state")) return True def button_done(self,cr, uid, ids, context=None): - self.write(cr,uid,ids,{'state':'done', 'date_close': time.strftime('%Y-%m-%d')}, context=context) + if context is None: + context = {} + self.write(cr, uid, ids,{'state':'done', 'date_close': time.strftime('%Y-%m-%d')}, context=context) return True def button_cancel(self, cr, uid, ids, context=None): + if context is None: + context = {} self.write(cr, uid, ids,{'state':'cancel'}, context=context) return True @@ -277,20 +295,22 @@ class hr_evaluation_interview(osv.osv): } def survey_req_waiting_answer(self, cr, uid, ids, context=None): - self.write(cr, uid, ids, { 'state' : 'waiting_answer'}) + if context is None: + context = {} + self.write(cr, uid, ids, { 'state' : 'waiting_answer'}, context=context) return True def survey_req_done(self, cr, uid, ids, context=None): + hr_eval_obj = self.pool.get('hr_evaluation.evaluation') if context is None: context = {} - hr_eval_obj = self.pool.get('hr_evaluation.evaluation') for id in self.browse(cr, uid, ids, context=context): flag = False wating_id = 0 tot_done_req = 0 if not id.evaluation_id.id: raise osv.except_osv(_('Warning !'),_("You cannot start evaluation without Evaluation.")) - records = hr_eval_obj.browse(cr, uid, [id.evaluation_id.id],context=context)[0].survey_request_ids + records = hr_eval_obj.browse(cr, uid, [id.evaluation_id.id], context=context)[0].survey_request_ids for child in records: if child.state == "draft" : wating_id = child.id @@ -300,16 +320,20 @@ class hr_evaluation_interview(osv.osv): else : tot_done_req += 1 if not flag and wating_id: - self.survey_req_waiting_answer(cr, uid, [wating_id], context) + self.survey_req_waiting_answer(cr, uid, [wating_id], context=context) hr_eval_obj.write(cr, uid, [id.evaluation_id.id], {'progress': tot_done_req * 100 / len(records)}, context=context) - self.write(cr, uid, ids, { 'state': 'done'}) + self.write(cr, uid, ids, { 'state': 'done'}, context=context) return True def survey_req_draft(self, cr, uid, ids, context=None): + if context is None: + context = {} self.write(cr, uid, ids, { 'state': 'draft'}, context=context) return True def survey_req_cancel(self, cr, uid, ids, context=None): + if context is None: + context = {} self.write(cr, uid, ids, { 'state': 'cancel'}, context=context) return True @@ -326,7 +350,7 @@ class hr_evaluation_interview(osv.osv): """ if not context: context = {} - record = self.browse(cr, uid, ids, context) + record = self.browse(cr, uid, ids, context=context) record = record and record[0] context.update({'survey_id': record.survey_id.id, 'response_id': [record.response.id], 'response_no':0,}) value = self.pool.get("survey").action_print_survey(cr, uid, ids, context) diff --git a/addons/hr_evaluation/hr_evaluation_view.xml b/addons/hr_evaluation/hr_evaluation_view.xml index 225295c3a56..a2ddebc5f20 100644 --- a/addons/hr_evaluation/hr_evaluation_view.xml +++ b/addons/hr_evaluation/hr_evaluation_view.xml @@ -238,7 +238,7 @@ + help="Evaluations that overpassed the deadline" domain="[('date','>=',str(datetime.date.today()))]" /> diff --git a/addons/hr_evaluation/wizard/hr_evaluation_mail.py b/addons/hr_evaluation/wizard/hr_evaluation_mail.py index 97dd1ca01c7..75aecf6a9f1 100644 --- a/addons/hr_evaluation/wizard/hr_evaluation_mail.py +++ b/addons/hr_evaluation/wizard/hr_evaluation_mail.py @@ -30,6 +30,8 @@ class hr_evaluation_reminder(osv.osv_memory): def send_mail(self, cr, uid, ids, context=None): hr_evaluation_obj = self.pool.get('hr_evaluation.evaluation') + if context is None: + context = {} evaluation_data = self.read(cr, uid, ids, context=context)[0] for waiting_id in hr_evaluation_obj.browse(cr, uid, evaluation_data['evaluation_id'], context=context).survey_request_ids: if waiting_id.state == "waiting_answer" and waiting_id.user_to_review_id.work_email : diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index d1d151c08f3..98eb7b9dc52 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -25,7 +25,9 @@ from osv import fields, osv from tools.translate import _ def _employee_get(obj, cr, uid, context=None): - ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)]) + if context is None: + context = {} + ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) if ids: return ids[0] return False @@ -33,21 +35,27 @@ def _employee_get(obj, cr, uid, context=None): class hr_expense_expense(osv.osv): def copy(self, cr, uid, id, default=None, context=None): + if context is None: + context = {} if not default: default = {} default.update({'invoice_id': False, 'date_confirm': False, 'date_valid': False, 'user_valid': False}) - return super(hr_expense_expense, self).copy(cr, uid, id, default, context) + return super(hr_expense_expense, self).copy(cr, uid, id, default, context=context) def _amount(self, cr, uid, ids, field_name, arg, context=None): + if context is None: + context = {} cr.execute("SELECT s.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_expense s LEFT OUTER JOIN hr_expense_line l ON (s.id=l.expense_id) WHERE s.id IN %s GROUP BY s.id ", (tuple(ids),)) res = dict(cr.fetchall()) return res def _get_currency(self, cr, uid, context=None): - user = self.pool.get('res.users').browse(cr, uid, [uid])[0] + if context is None: + context = {} + user = self.pool.get('res.users').browse(cr, uid, [uid], context=context)[0] if user.company_id: return user.company_id.currency_id.id else: - return self.pool.get('res.currency').search(cr, uid, [('rate','=',1.0)])[0] + return self.pool.get('res.currency').search(cr, uid, [('rate','=',1.0)], context=context)[0] _name = "hr.expense.expense" _description = "Expense" @@ -115,6 +123,8 @@ class hr_expense_expense(osv.osv): def action_invoice_create(self, cr, uid, ids): res = False invoice_obj = self.pool.get('account.invoice') + property_obj = self.pool.get('ir.property') + sequence_obj = self.pool.get('ir.sequence') for exp in self.browse(cr, uid, ids): lines = [] for l in exp.line_ids: @@ -125,7 +135,7 @@ class hr_expense_expense(osv.osv): acc = l.product_id.categ_id.property_account_expense_categ tax_id = [x.id for x in l.product_id.supplier_taxes_id] else: - acc = self.pool.get('ir.property').get(cr, uid, 'property_account_expense_categ', 'product.category') + acc = property_obj.get(cr, uid, 'property_account_expense_categ', 'product.category') if not acc: raise osv.except_osv(_('Error !'), _('Please configure Default Expanse account for Product purchase, `property_account_expense_categ`')) @@ -145,7 +155,7 @@ class hr_expense_expense(osv.osv): payment_term_id = exp.employee_id.address_id.partner_id.property_payment_term.id inv = { 'name': exp.name, - 'reference': self.pool.get('ir.sequence').get(cr, uid, 'hr.expense.invoice'), + 'reference': sequence_obj.get(cr, uid, 'hr.expense.invoice'), 'account_id': acc, 'type': 'in_invoice', 'partner_id': exp.employee_id.address_id.partner_id.id, @@ -184,6 +194,8 @@ class hr_expense_line(osv.osv): _description = "Expense Line" def _amount(self, cr, uid, ids, field_name, arg, context=None): + if context is None: + context = {} if not len(ids): return {} cr.execute("SELECT l.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_line l WHERE id IN %s GROUP BY l.id ",(tuple(ids),)) @@ -215,16 +227,16 @@ class hr_expense_line(osv.osv): context = {} v = {} if product_id: - product=self.pool.get('product.product').browse(cr, uid, product_id, context=context) - v['name']=product.name + product = self.pool.get('product.product').browse(cr, uid, product_id, context=context) + v['name'] = product.name # Compute based on pricetype of employee company - pricetype_id = self.pool.get('hr.employee').browse(cr, uid, employee_id).user_id.company_id.property_valuation_price_type.id - context['currency_id']=self.pool.get('hr.employee').browse(cr, uid, employee_id).user_id.company_id.currency_id.id - pricetype=self.pool.get('product.price.type').browse(cr, uid, pricetype_id) - amount_unit=product.price_get(pricetype.field, context)[product.id] - v['unit_amount']=amount_unit + pricetype_id = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context).user_id.company_id.property_valuation_price_type.id + context['currency_id'] = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context).user_id.company_id.currency_id.id + pricetype = self.pool.get('product.price.type').browse(cr, uid, pricetype_id, context=context) + amount_unit = product.price_get(pricetype.field, context)[product.id] + v['unit_amount'] = amount_unit if not uom_id: - v['uom_id']=product.uom_id.id + v['uom_id'] = product.uom_id.id return {'value': v} hr_expense_line() diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index a5ffdbdfc49..59264aec693 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -33,8 +33,10 @@ class hr_holidays_status(osv.osv): _description = "Leave Type" def get_days_cat(self, cr, uid, ids, category_id, return_false, context=None): + if context is None: + context = {} res = {} - for record in self.browse(cr, uid, ids, context): + for record in self.browse(cr, uid, ids, context=context): res[record.id] = {} max_leaves = leaves_taken = 0 if not return_false: @@ -50,6 +52,8 @@ class hr_holidays_status(osv.osv): return res def get_days(self, cr, uid, ids, employee_id, return_false, context=None): + if context is None: + context = {} res = {} for record in self.browse(cr, uid, ids, context=context): res[record.id] = {} @@ -67,16 +71,18 @@ class hr_holidays_status(osv.osv): return res def _user_left_days(self, cr, uid, ids, name, args, context=None): + if context is None: + context = {} return_false = False employee_id = False res = {} - + if context and context.has_key('employee_id'): if not context['employee_id']: return_false = True employee_id = context['employee_id'] else: - employee_ids = self.pool.get('hr.employee').search(cr, uid, [('user_id','=',uid)]) + employee_ids = self.pool.get('hr.employee').search(cr, uid, [('user_id','=',uid)], context=context) if employee_ids: employee_id = employee_ids[0] else: @@ -112,7 +118,9 @@ class hr_holidays(osv.osv): _order = "type desc, date_from asc" def _employee_get(obj, cr, uid, context=None): - ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)]) + if context is None: + context = {} + ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) if ids: return ids[0] return False @@ -152,13 +160,17 @@ class hr_holidays(osv.osv): def _create_resource_leave(self, cr, uid, vals, context=None): '''This method will create entry in resource calendar leave object at the time of holidays validated ''' + if context is None: + context = {} obj_res_leave = self.pool.get('resource.calendar.leaves') - return obj_res_leave.create(cr, uid, vals) + return obj_res_leave.create(cr, uid, vals, context=context) def _remove_resouce_leave(self, cr, uid, ids, context=None): '''This method will create entry in resource calendar leave object at the time of holidays cancel/removed''' obj_res_leave = self.pool.get('resource.calendar.leaves') - leave_ids = obj_res_leave.search(cr, uid, [('holiday_id', 'in', ids)]) + if context is None: + context = {} + leave_ids = obj_res_leave.search(cr, uid, [('holiday_id', 'in', ids)], context=context) return obj_res_leave.unlink(cr, uid, leave_ids) def create(self, cr, uid, vals, context=None): @@ -231,6 +243,8 @@ class hr_holidays(osv.osv): _constraints = [(_check_date, 'Start date should not be larger than end date!\nNumber of Days should be greater than 1!', ['number_of_days_temp'])] def unlink(self, cr, uid, ids, context=None): + if context is None: + context = {} self._update_user_holidays(cr, uid, ids) self._remove_resouce_leave(cr, uid, ids, context=context) return super(hr_holidays, self).unlink(cr, uid, ids, context) @@ -252,9 +266,11 @@ class hr_holidays(osv.osv): return self.onchange_date_from(cr, uid, ids, date_to, date_from) def onchange_sec_id(self, cr, uid, ids, status, context=None): + if context is None: + context = {} warning = {} if status: - brows_obj = self.pool.get('hr.holidays.status').browse(cr, uid, [status])[0] + brows_obj = self.pool.get('hr.holidays.status').browse(cr, uid, [status], context=context)[0] if brows_obj.categ_id and brows_obj.categ_id.section_id and not brows_obj.categ_id.section_id.allow_unlink: warning = { 'title': "Warning for ", @@ -369,6 +385,9 @@ class hr_holidays(osv.osv): return True def check_holidays(self, cr, uid, ids): + holi_status_obj = self.pool.get('hr.holidays.status') + emp_obj = self.pool.get('hr.employee') + meeting_obj = self.pool.get('crm.meeting') for record in self.browse(cr, uid, ids): if not record.number_of_days: raise osv.except_osv(_('Warning!'), _('Wrong leave definition.')) @@ -376,14 +395,14 @@ class hr_holidays(osv.osv): leave_asked = record.number_of_days if leave_asked < 0.00: if not record.holiday_status_id.limit: - leaves_rest = self.pool.get('hr.holidays.status').get_days(cr, uid, [record.holiday_status_id.id], record.employee_id.id, False)[record.holiday_status_id.id]['remaining_leaves'] + leaves_rest = holi_status_obj.get_days(cr, uid, [record.holiday_status_id.id], record.employee_id.id, False)[record.holiday_status_id.id]['remaining_leaves'] if leaves_rest < -(leave_asked): raise osv.except_osv(_('Warning!'),_('You Cannot Validate leaves while available leaves are less than asked leaves.')) elif record.holiday_type == 'category' and record.category_id: leave_asked = record.number_of_days if leave_asked < 0.00: if not record.holiday_status_id.limit: - leaves_rest = self.pool.get('hr.holidays.status').get_days_cat(cr, uid, [record.holiday_status_id.id], record.category_id.id, False)[record.holiday_status_id.id]['remaining_leaves'] + leaves_rest = holi_status_obj.get_days_cat(cr, uid, [record.holiday_status_id.id], record.category_id.id, False)[record.holiday_status_id.id]['remaining_leaves'] if leaves_rest < -(leave_asked): raise osv.except_osv(_('Warning!'),_('You Cannot Validate leaves while available leaves are less than asked leaves.')) else:# This condition will never meet!! @@ -401,10 +420,10 @@ class hr_holidays(osv.osv): 'allocation_type': record.allocation_type, 'parent_id': record.id, } - employee_ids = self.pool.get('hr.employee').search(cr, uid, []) + employee_ids = emp_obj.search(cr, uid, []) for employee in employee_ids: vals['employee_id'] = employee - user_id = self.pool.get('hr.employee').search(cr, uid, [('user_id','=',uid)]) + user_id = emp_obj.search(cr, uid, [('user_id','=',uid)]) if user_id: vals['user_id'] = user_id[0] holiday_ids.append(self.create(cr, uid, vals, context=None)) @@ -435,7 +454,7 @@ class hr_holidays(osv.osv): 'user_id' : record.user_id.id, 'date' : record.date_from, } - case_id = self.pool.get('crm.meeting').create(cr, uid, vals) + case_id = meeting_obj.create(cr, uid, vals) self.write(cr, uid, ids, {'case_id': case_id}) return True diff --git a/addons/hr_holidays/wizard/hr_holidays_summary_department.py b/addons/hr_holidays/wizard/hr_holidays_summary_department.py index b95b85c7d5b..a08354fd40d 100644 --- a/addons/hr_holidays/wizard/hr_holidays_summary_department.py +++ b/addons/hr_holidays/wizard/hr_holidays_summary_department.py @@ -41,7 +41,7 @@ class hr_holidays_summary_dept(osv.osv_memory): def print_report(self, cr, uid, ids, context=None): if context is None: context = {} - data = self.read(cr, uid, ids, [])[0] + data = self.read(cr, uid, ids, [], context=context)[0] if not data['depts']: raise osv.except_osv(_('Error'), _('You have to select at least 1 Department. And try again')) datas = { diff --git a/addons/hr_holidays/wizard/hr_holidays_summary_employees.py b/addons/hr_holidays/wizard/hr_holidays_summary_employees.py index 7e8d66108d4..ca9ccc83db7 100644 --- a/addons/hr_holidays/wizard/hr_holidays_summary_employees.py +++ b/addons/hr_holidays/wizard/hr_holidays_summary_employees.py @@ -40,7 +40,7 @@ class hr_holidays_summary_employee(osv.osv_memory): def print_report(self, cr, uid, ids, context=None): if context is None: context = {} - data = self.read(cr, uid, ids, [])[0] + data = self.read(cr, uid, ids, [], context=context)[0] data['emp'] = context['active_ids'] datas = { 'ids': [], diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 22e5061023f..a7984d7c7fa 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -21,15 +21,14 @@ ############################################################################## import time +from datetime import date, datetime, timedelta import netsvc -from osv import osv -from osv import fields + +from osv import fields, osv from tools import config from tools.translate import _ -from datetime import date -from datetime import datetime -from datetime import timedelta + def prev_bounds(cdate=False): when = date.fromtimestamp(time.mktime(time.strptime(cdate,"%Y-%m-%d"))) @@ -114,12 +113,14 @@ class hr_payroll_structure(osv.osv): @return: returns a id of newly created record """ - code = self.browse(cr, uid, id).code + if context is None: + context = {} + code = self.browse(cr, uid, id, context=context).code default = { 'code':code+"(copy)", 'company_id':self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id } - res_id = super(hr_payroll_structure, self).copy(cr, uid, id, default, context) + res_id = super(hr_payroll_structure, self).copy(cr, uid, id, default, context=context) return res_id hr_payroll_structure() @@ -153,13 +154,13 @@ class payroll_register(osv.osv): _name = 'hr.payroll.register' _description = 'Payroll Register' - def _calculate(self, cr, uid, ids, field_names, arg, context): + def _calculate(self, cr, uid, ids, field_names, arg, context=None): res = {} allounce = 0.0 deduction = 0.0 net = 0.0 grows = 0.0 - for register in self.browse(cr, uid, ids, context): + for register in self.browse(cr, uid, ids, context=context): for slip in register.line_ids: allounce += slip.allounce deduction += slip.deduction @@ -210,21 +211,23 @@ class payroll_register(osv.osv): context=context).company_id.id, } - def compute_sheet(self, cr, uid, ids, context={}): + 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") + if context is None: + context = {} - vals = self.browse(cr, uid, ids)[0] + vals = self.browse(cr, uid, ids, context=context)[0] - emp_ids = emp_pool.search(cr, uid, []) + emp_ids = emp_pool.search(cr, uid, [], context=context) - for emp in emp_pool.browse(cr, uid, emp_ids): - old_slips = slip_pool.search(cr, uid, [('employee_id','=', emp.id), ('date','=',vals.date)]) + 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)], context=context) if old_slips: - slip_pool.write(cr, uid, old_slips, {'register_id':ids[0]}) + slip_pool.write(cr, uid, old_slips, {'register_id':ids[0]}, context=context) for sid in old_slips: wf_service.trg_validate(uid, 'hr.payslip', sid, 'compute_sheet', cr) else: @@ -237,48 +240,54 @@ class payroll_register(osv.osv): 'journal_id':vals.journal_id.id, 'bank_journal_id':vals.bank_journal_id.id } - slip_id = slip_pool.create(cr, uid, res) + slip_id = slip_pool.create(cr, uid, res, context=context) 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}) + self.write(cr, uid, ids, {'state':'draft', 'number':number}, context=context) return True - def verify_sheet(self, cr, uid, ids, context={}): + def verify_sheet(self, cr, uid, ids, context=None): + if context is None: + context = {} slip_pool = self.pool.get('hr.payslip') for id in ids: - sids = slip_pool.search(cr, uid, [('register_id','=',id)]) + sids = slip_pool.search(cr, uid, [('register_id','=',id)], context=context) wf_service = netsvc.LocalService("workflow") for sid in sids: wf_service.trg_validate(uid, 'hr.payslip', sid, 'verify_sheet', cr) - self.write(cr, uid, ids, {'state':'hr_check'}) + self.write(cr, uid, ids, {'state':'hr_check'}, context=context) return True - def final_verify_sheet(self, cr, uid, ids, context={}): + def final_verify_sheet(self, cr, uid, ids, context=None): slip_pool = self.pool.get('hr.payslip') advice_pool = self.pool.get('hr.payroll.advice') advice_line_pool = self.pool.get('hr.payroll.advice.line') + sequence_pool = self.pool.get('ir.sequence') + users_pool = self.pool.get('res.users') + if context is None: + context = {} for id in ids: - sids = slip_pool.search(cr, uid, [('register_id','=',id), ('state','=','hr_check')]) + sids = slip_pool.search(cr, uid, [('register_id','=',id), ('state','=','hr_check')], context=context) wf_service = netsvc.LocalService("workflow") for sid in sids: wf_service.trg_validate(uid, 'hr.payslip', sid, 'final_verify_sheet', cr) - for reg in self.browse(cr, uid, ids): + for reg in self.browse(cr, uid, ids, context=context): accs = {} for slip in reg.line_ids: pid = False if accs.get(slip.employee_id.property_bank_account.code, False) == False: advice = { - 'name': 'Payment Advice from %s / Bank Account %s' % (self.pool.get('res.users').browse(cr, uid, uid).company_id.name, slip.employee_id.property_bank_account.name), - 'number': self.pool.get('ir.sequence').get(cr, uid, 'payment.advice'), + 'name': 'Payment Advice from %s / Bank Account %s' % (users_pool.browse(cr, uid, uid, context=context).company_id.name, slip.employee_id.property_bank_account.name), + 'number': sequence_pool.get(cr, uid, 'payment.advice'), 'register_id':reg.id, 'account_id':slip.employee_id.property_bank_account.id } - pid = advice_pool.create(cr, uid, advice) + pid = advice_pool.create(cr, uid, advice, context=context) accs[slip.employee_id.property_bank_account.code] = pid else: pid = accs[slip.employee_id.property_bank_account.code] @@ -290,21 +299,21 @@ class payroll_register(osv.osv): 'amount':slip.other_pay + slip.net, 'bysal':slip.net } - id = advice_line_pool.create(cr, uid, pline) + id = advice_line_pool.create(cr, uid, pline, context=context) #, 'advice_ids':[(6, 0, [pid])] - self.write(cr, uid, ids, {'state':'confirm'}) + self.write(cr, uid, ids, {'state':'confirm'}, context=context) return True - def process_sheet(self, cr, uid, ids, context={}): + def process_sheet(self, cr, uid, ids, context=None): slip_pool = self.pool.get('hr.payslip') for id in ids: - sids = slip_pool.search(cr, uid, [('register_id','=',id), ('state','=','confirm')]) + sids = slip_pool.search(cr, uid, [('register_id','=',id), ('state','=','confirm')], context=context) wf_service = netsvc.LocalService("workflow") for sid in sids: wf_service.trg_validate(uid, 'hr.payslip', sid, 'process_sheet', cr) - self.write(cr, uid, ids, {'state':'done'}) + self.write(cr, uid, ids, {'state':'done'}, context=context) return True payroll_register() @@ -341,16 +350,22 @@ class payroll_advice(osv.osv): context=context).company_id.id, } - def confirm_sheet(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state':'confirm'}) + def confirm_sheet(self, cr, uid, ids, context=None): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'confirm'}, context=context) return True - def set_to_draft(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state':'draft'}) + def set_to_draft(self, cr, uid, ids, context=None): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'draft'}, context=context) return True - def cancel_sheet(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state':'cancel'}) + def cancel_sheet(self, cr, uid, ids, context=None): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'cancel'}, context=context) return True payroll_advice() @@ -374,15 +389,17 @@ class payroll_advice_line(osv.osv): 'flag': lambda *a: 'C', } - def onchange_employee_id(self, cr, uid, ids, ddate, employee_id, context={}): + def onchange_employee_id(self, cr, uid, ids, ddate, employee_id, context=None): vals = {} slip_pool = self.pool.get('hr.payslip') + if context is None: + context = {} if employee_id: dates = prev_bounds(ddate) sids = False - sids = slip_pool.search(cr, uid, [('paid','=',False),('state','=','confirm'),('date','>=',dates[0]), ('employee_id','=',employee_id), ('date','<=',dates[1])]) + sids = slip_pool.search(cr, uid, [('paid','=',False),('state','=','confirm'),('date','>=',dates[0]), ('employee_id','=',employee_id), ('date','<=',dates[1])], context=context) if sids: - slip = slip_pool.browse(cr, uid, sids[0]) + slip = slip_pool.browse(cr, uid, sids[0], context=context) vals['name'] = slip.employee_id.otherid vals['amount'] = slip.net + slip.other_pay vals['bysal'] = slip.net @@ -398,24 +415,26 @@ class contrib_register(osv.osv): _name = 'hr.contibution.register' _description = 'Contribution Register' - def _total_contrib(self, cr, uid, ids, field_names, arg, context={}): + 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).fiscalyear_id + if context is None: + context = {} + period_id = self.pool.get('account.period').search(cr,uid,[('date_start','<=',time.strftime('%Y-%m-%d')),('date_stop','>=',time.strftime('%Y-%m-%d'))], context=context)[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): - 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)]) + for cur in self.browse(cr, uid, ids, context=context): + current = line_pool.search(cr, uid, [('period_id','=',period_id),('register_id','=',cur.id)], context=context) + years = line_pool.search(cr, uid, [('period_id.fiscalyear_id','=',fiscalyear_id.id), ('register_id','=',cur.id)], context=context) e_month = 0.0 c_month = 0.0 - for i in line_pool.browse(cr, uid, current): + 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): + for j in line_pool.browse(cr, uid, years, context=context): e_year += i.emp_deduction c_year += i.comp_deduction @@ -454,9 +473,11 @@ class contrib_register_line(osv.osv): _name = 'hr.contibution.register.line' _description = 'Contribution Register Line' - def _total(self, cr, uid, ids, field_names, arg, context): + def _total(self, cr, uid, ids, field_names, arg, context=None): + if context is None: + context = {} res={} - for line in self.browse(cr, uid, ids, context): + for line in self.browse(cr, uid, ids, context=context): res[line.id] = line.emp_deduction + line.comp_deduction return res @@ -564,22 +585,23 @@ class company_contribution(osv.osv): context=context).company_id.id, } - def execute_function(self, cr, uid, id, value, context): + def execute_function(self, cr, uid, id, value, context=None): """ self: pointer to self object cr: cursor to database uid: user id of current executer """ - line_pool = self.pool.get('company.contribution.line') + if context is None: + context = {} res = 0 - ids = line_pool.search(cr, uid, [('category_id','=',id), ('to_val','>=',value),('from_val','<=',value)]) + ids = line_pool.search(cr, uid, [('category_id','=',id), ('to_val','>=',value),('from_val','<=',value)], context=context) if not ids: - ids = line_pool.search(cr, uid, [('category_id','=',id), ('from','<=',value)]) + ids = line_pool.search(cr, uid, [('category_id','=',id), ('from','<=',value)], context=context) if not ids: res = 0 else: - res = line_pool.browse(cr, uid, ids)[0].value + res = line_pool.browse(cr, uid, ids, context=context)[0].value return res company_contribution() @@ -645,9 +667,12 @@ class hr_payslip(osv.osv): _name = 'hr.payslip' _description = 'Pay Slip' - def _calculate(self, cr, uid, ids, field_names, arg, context): + def _calculate(self, cr, uid, ids, field_names, arg, context=None): + slip_line_obj = self.pool.get('hr.payslip.line') + if context is None: + context = {} res = {} - for rs in self.browse(cr, uid, ids, context): + for rs in self.browse(cr, uid, ids, context=context): allow = 0.0 deduct = 0.0 others = 0.0 @@ -698,7 +723,7 @@ class hr_payslip(osv.osv): elif line.type == 'otherpay': others += amount - self.pool.get('hr.payslip.line').write(cr, uid, [line.id], {'total':amount}) + slip_line_obj.write(cr, uid, [line.id], {'total':amount}, context=context) record = { 'allounce':round(allow), @@ -759,6 +784,8 @@ class hr_payslip(osv.osv): } def copy(self, cr, uid, id, default=None, context=None): + if context is None: + context = {} company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id default = { 'line_ids': False, @@ -770,7 +797,7 @@ class hr_payslip(osv.osv): 'basic_before_leaves':0, 'basic':0 } - res_id = super(hr_payslip, self).copy(cr, uid, id, default, context) + res_id = super(hr_payslip, self).copy(cr, uid, id, default, context=context) return res_id def create_voucher(self, cr, uid, ids, name, voucher, sequence=5): @@ -784,31 +811,45 @@ class hr_payslip(osv.osv): } slip_move.create(cr, uid, res) - def set_to_draft(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state':'draft'}) + def set_to_draft(self, cr, uid, ids, context=None): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'draft'}, context=context) return True - def cancel_sheet(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state':'cancel'}) + def cancel_sheet(self, cr, uid, ids, context=None): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'cancel'}, context=context) return True - def account_check_sheet(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state':'accont_check'}) + def account_check_sheet(self, cr, uid, ids, context=None): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'accont_check'}, context=context) return True - def hr_check_sheet(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state':'hr_check'}) + def hr_check_sheet(self, cr, uid, ids, context=None): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'hr_check'}, context=context) return True - - def process_sheet(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state':'done'}) + + def process_sheet(self, cr, uid, ids, context=None): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'done'}, context=context) return True - - def verify_sheet(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state':'confirm'}) + + def verify_sheet(self, cr, uid, ids, context=None): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'confirm'}, context=context) return True - - def get_contract(self, cr, uid, employee, date, context={}): + + def get_contract(self, cr, uid, employee, date, context=None): + if context is None: + context = {} sql_req= ''' SELECT c.id as id, c.wage as wage, struct_id as function FROM hr_contract c @@ -828,7 +869,7 @@ class hr_payslip(osv.osv): return contract - def _get_leaves(self, cr, user, slip, employee, context={}): + def _get_leaves(self, cr, user, slip, employee, context=None): """ Compute leaves for an employee @@ -840,7 +881,8 @@ class hr_payslip(osv.osv): @return: return a result """ - + if context is None: + context = {} result = [] dates = prev_bounds(slip.date) @@ -856,14 +898,17 @@ class hr_payslip(osv.osv): return result - def compute_sheet(self, cr, uid, ids, context={}): + 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') holiday_pool = self.pool.get('hr.holidays') - - date = self.read(cr, uid, ids, ['date'])[0]['date'] + contract_obj = self.pool.get('hr.contract') + sequence_obj = self.pool.get('ir.sequence') + if context is None: + context = {} + date = self.read(cr, uid, ids, ['date'], context=context)[0]['date'] #Check for the Holidays def get_days(start, end, month, year, calc_day): @@ -874,25 +919,25 @@ class hr_payslip(osv.osv): count += 1 return count - for slip in self.browse(cr, uid, ids): + for slip in self.browse(cr, uid, ids, context=context): contracts = self.get_contract(cr, uid, slip.employee_id, date, context) if contracts.get('id', False) == False: continue - contract = self.pool.get('hr.contract').browse(cr, uid, contracts.get('id')) + contract = contract_obj.browse(cr, uid, contracts.get('id'), context=context) sal_type = contract.wage_type_id.type function = contract.struct_id.id lines = [] if function: - func = func_pool.read(cr, uid, function, ['line_ids']) - lines = slip_line_pool.browse(cr, uid, func['line_ids']) + func = func_pool.read(cr, uid, function, ['line_ids'], context=context) + lines = slip_line_pool.browse(cr, uid, func['line_ids'], context=context) lines += slip.employee_id.line_ids - old_slip_id = slip_line_pool.search(cr, uid, [('slip_id','=',slip.id)]) - slip_line_pool.unlink(cr, uid, old_slip_id) + old_slip_ids = slip_line_pool.search(cr, uid, [('slip_id','=',slip.id)], context=context) + slip_line_pool.unlink(cr, uid, old_slip_ids, context=context) ad = [] lns = {} @@ -972,14 +1017,14 @@ class hr_payslip(osv.osv): value = line.amount elif line.amount_type == 'func': - value = self.pool.get('hr.payslip.line').execute_function(cr, uid, line.id, amt, context) + value = slip_line_pool.execute_function(cr, uid, line.id, amt, context) line.amount = value else: if line.amount_type in ('fix', 'per'): value = line.amount - + elif line.amount_type == 'func': - value = self.pool.get('hr.payslip.line').execute_function(cr, uid, line.id, amt, context) + value = slip_line_pool.execute_function(cr, uid, line.id, amt, context) line.amount = value if line.type == 'allowance': @@ -997,7 +1042,7 @@ class hr_payslip(osv.osv): 'base':base } slip_line_pool.copy(cr, uid, line.id, vals, {}) - + if sal_type in ('gross', 'net'): sal = contract.wage if sal_type == 'net': @@ -1015,7 +1060,7 @@ class hr_payslip(osv.osv): else: basic = contract.wage - number = self.pool.get('ir.sequence').get(cr, uid, 'salary.slip') + number = sequence_obj.get(cr, uid, 'salary.slip') ttyme = datetime.fromtimestamp(time.mktime(time.strptime(slip.date,"%Y-%m-%d"))) update.update({ 'deg_id':function, @@ -1027,9 +1072,9 @@ class hr_payslip(osv.osv): 'contract_id':contract.id, 'company_id':slip.employee_id.company_id.id }) - self.write(cr, uid, [slip.id], update) + self.write(cr, uid, [slip.id], update, context=context) - for slip in self.browse(cr, uid, ids): + for slip in self.browse(cr, uid, ids, context=context): if not slip.contract_id : continue @@ -1055,7 +1100,7 @@ class hr_payslip(osv.osv): total_leave = 0.0 paid_leave = 0.0 - for hday in holiday_pool.browse(cr, uid, leave_ids): + for hday in holiday_pool.browse(cr, uid, leave_ids, context=context): res = { 'slip_id':slip.id, 'name':hday.holiday_status_id.name + '-%s' % (hday.number_of_days), @@ -1089,7 +1134,7 @@ class hr_payslip(osv.osv): leave += days total += perday * days - slip_line_pool.create(cr, uid, res) + slip_line_pool.create(cr, uid, res, context=context) basic = basic - total leaves = total @@ -1100,7 +1145,7 @@ class hr_payslip(osv.osv): 'worked_days':working_day - leave, 'working_days':working_day, }) - self.write(cr, uid, [slip.id], update) + self.write(cr, uid, [slip.id], update, context=context) return True @@ -1203,18 +1248,20 @@ class hr_payslip_line(osv.osv): } _order = 'sequence' - def execute_function(self, cr, uid, id, value, context): + def execute_function(self, cr, uid, id, value, context=None): + if context is None: + context = {} line_pool = self.pool.get('hr.payslip.line.line') res = 0 - ids = line_pool.search(cr, uid, [('slipline_id','=',id), ('from_val','<=',value), ('to_val','>=',value)]) + ids = line_pool.search(cr, uid, [('slipline_id','=',id), ('from_val','<=',value), ('to_val','>=',value)], context=context) if not ids: - ids = line_pool.search(cr, uid, [('slipline_id','=',id), ('from_val','<=',value)]) + ids = line_pool.search(cr, uid, [('slipline_id','=',id), ('from_val','<=',value)], context=context) if not ids: return res - res = line_pool.browse(cr, uid, ids)[-1].value + res = line_pool.browse(cr, uid, ids, context=context)[-1].value return res hr_payslip_line() diff --git a/addons/hr_payroll/wizard/hr_payroll_create_analytic.py b/addons/hr_payroll/wizard/hr_payroll_create_analytic.py index cded95390f4..45c2d2c495e 100644 --- a/addons/hr_payroll/wizard/hr_payroll_create_analytic.py +++ b/addons/hr_payroll/wizard/hr_payroll_create_analytic.py @@ -32,37 +32,38 @@ class hr_payroll_create_analytic(osv.osv_memory): } def do_duplicate(self, cr, uid, ids, context=None): - - account_pool =self.pool.get('account.analytic.account') + account_pool = self.pool.get('account.analytic.account') func_pool = self.pool.get('hr.employee.grade') ad_pool = self.pool.get('hr.allounce.deduction.categoty') - data = self.read(cr,uid,ids)[0] + if context is None: + context = {} + data = self.read(cr, uid, ids, context=context)[0] tpy = data['type'] company = data['company_id'] - function_ids = func_pool.search(cr, uid, []) - ad_ids = ad_pool.search(cr, uid, []) + function_ids = func_pool.search(cr, uid, [], context=context) + ad_ids = ad_pool.search(cr, uid, [], context=context) if tpy == 'bydeg': - for function in func_pool.browse(cr, uid, function_ids): + for function in func_pool.browse(cr, uid, function_ids, context=context): res = { 'name':function.name, 'company_id':company } - fid = account_pool.create(cr, uid, res) + fid = account_pool.create(cr, uid, res, context=context) res = { 'name':'Basic Salary', 'company_id':company, 'parent_id': fid } - account_pool.create(cr, uid, res) - for ad in ad_pool.browse(cr, uid, ad_ids): + account_pool.create(cr, uid, res, context=context) + for ad in ad_pool.browse(cr, uid, ad_ids, context=context): res = { 'name':ad.name, 'company_id':company, 'parent_id': fid } - account_pool.create(cr, uid, res) + account_pool.create(cr, uid, res, context=context) @@ -71,28 +72,28 @@ class hr_payroll_create_analytic(osv.osv_memory): 'name':'Basic Salary', 'company_id':company } - adid = account_pool.create(cr, uid, res) - for function in func_pool.browse(cr, uid, function_ids): + adid = account_pool.create(cr, uid, res, context=context) + for function in func_pool.browse(cr, uid, function_ids, context=context): res = { 'name':function.name, 'company_id':company, 'parent_id': adid } - account_pool.create(cr, uid, res) + account_pool.create(cr, uid, res, context=context) - for ad in ad_pool.browse(cr, uid, ad_ids): + for ad in ad_pool.browse(cr, uid, ad_ids, context=context): res = { 'name':ad.name, 'company_id':company, } - adid = account_pool.create(cr, uid, res) - for function in func_pool.browse(cr, uid, function_ids): + adid = account_pool.create(cr, uid, res, context=context) + for function in func_pool.browse(cr, uid, function_ids, context=context): res = { 'name':function.name, 'company_id':company, 'parent_id': adid } - account_pool.create(cr, uid, res) + account_pool.create(cr, uid, res, context=context) return {} hr_payroll_create_analytic() diff --git a/addons/hr_payroll/wizard/hr_payroll_employees_detail.py b/addons/hr_payroll/wizard/hr_payroll_employees_detail.py index 7c14aa82dd5..314dcfa94bb 100755 --- a/addons/hr_payroll/wizard/hr_payroll_employees_detail.py +++ b/addons/hr_payroll/wizard/hr_payroll_employees_detail.py @@ -31,8 +31,10 @@ class hr_payroll_employees_detail(osv.osv_memory): 'employee_ids': fields.many2many('hr.employee', 'payroll_emp_rel','payroll_id','emp_id', 'Employees',required=True), 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', required=True) } - def _get_fiscalyear(self, cr, uid, ids, context={}): - fiscal_ids=self.pool.get('account.fiscalyear').search(cr,uid,[]) + def _get_fiscalyear(self, cr, uid, ids, context=None): + if context is None: + context = {} + fiscal_ids = self.pool.get('account.fiscalyear').search(cr,uid,[], context=context) if fiscal_ids: return fiscal_ids[0] return False @@ -50,7 +52,8 @@ class hr_payroll_employees_detail(osv.osv_memory): @param context: A standard dictionary @return : return report """ - + if context is None: + context = {} datas = {'ids': context.get('active_ids', [])} res = self.read(cr, uid, ids, ['employee_ids', 'fiscalyear_id'], context=context) diff --git a/addons/hr_payroll/wizard/hr_payroll_year_salary.py b/addons/hr_payroll/wizard/hr_payroll_year_salary.py index e58cdc8fc1b..0445d559f58 100755 --- a/addons/hr_payroll/wizard/hr_payroll_year_salary.py +++ b/addons/hr_payroll/wizard/hr_payroll_year_salary.py @@ -33,7 +33,9 @@ class hr_payroll_year_salary(osv.osv_memory): } def _get_fiscalyear(self, cr, uid, ids, context=None): - fiscal_ids=self.pool.get('account.fiscalyear').search(cr,uid,[],context=context) + if context is None: + context = {} + fiscal_ids=self.pool.get('account.fiscalyear').search(cr, uid, [], context=context) if fiscal_ids: return fiscal_ids[0] return False @@ -52,7 +54,8 @@ class hr_payroll_year_salary(osv.osv_memory): @param context: A standard dictionary @return : return report """ - + if context is None: + context = {} datas = {'ids': context.get('active_ids', [])} res = self.read(cr, uid, ids, ['employee_ids', 'fiscalyear_id','salary_on'], context=context) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 063090cbe83..f07a0493b4f 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -1,7 +1,7 @@ #-*- coding:utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution +# OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved # d$ # @@ -22,14 +22,13 @@ import time import netsvc -from osv import osv -from osv import fields +from datetime import date, datetime, timedelta + +from osv import fields, osv from tools import config from tools.translate import _ -from datetime import date -from datetime import datetime -from datetime import timedelta + def prev_bounds(cdate=False): when = date.fromtimestamp(time.mktime(time.strptime(cdate,"%Y-%m-%d"))) @@ -49,14 +48,14 @@ class hr_payslip(osv.osv): ''' _inherit = 'hr.payslip' _description = 'Pay Slip' - + _columns = { 'move_ids':fields.one2many('hr.payslip.account.move', 'slip_id', 'Accounting vouchers', required=False), '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."), } - + def create_voucher(self, cr, uid, ids, name, voucher, sequence=5): slip_move = self.pool.get('hr.payslip.account.move') for slip in ids: @@ -67,78 +66,83 @@ class hr_payslip(osv.osv): 'name':name } slip_move.create(cr, uid, res) - - def cancel_sheet(self, cr, uid, ids, context={}): + + 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') - + if context is None: + context = {} move_ids = [] - for slip in self.browse(cr, uid, ids, context): + 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]) - - slip_move.unlink(cr, uid, move_ids) - self.write(cr, uid, ids, {'state':'cancel'}) + 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 - - def process_sheet(self, cr, uid, ids, context={}): + + def process_sheet(self, cr, uid, ids, context=None): move_pool = self.pool.get('account.move') movel_pool = self.pool.get('account.move.line') invoice_pool = self.pool.get('account.invoice') - - for slip in self.browse(cr,uid,ids): + fiscalyear_pool = self.pool.get('account.fiscalyear') + period_pool = self.pool.get('account.period') + if context is None: + context = {} + + 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 - - fiscal_year_ids = self.pool.get('account.fiscalyear').search(cr, uid, []) + + 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 = self.pool.get('account.fiscalyear').read(cr, uid, fiscal_year_ids, ['date_start','date_stop']) + 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)): year_exist = True if not year_exist: raise osv.except_osv(_('Warning !'), _('Fiscal Year is not defined for slip date %s'%slip.date)) - search_period = self.pool.get('account.period').search(cr,uid,[('date_start','<=',slip.date),('date_stop','>=',slip.date)]) - if not search_period: + search_periods = period_pool.search(cr, uid, [('date_start','<=',slip.date),('date_stop','>=',slip.date)], context=context) + if not search_periods: raise osv.except_osv(_('Warning !'), _('Period is not defined for slip date %s'%slip.date)) - period_id = search_period[0] + 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, + 'period_id': period_id, 'date': slip.date, 'type':'bank_pay_voucher', 'ref':slip.number, 'narration': name } - move_id = move_pool.create(cr, uid, move) + 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) ded_rec = { 'move_id':move_id, 'name': name, #'partner_id': partner_id, - 'date': slip.date, - 'account_id': slip.employee_id.property_bank_account.id, + 'date': slip.date, + 'account_id': slip.employee_id.property_bank_account.id, 'debit': 0.0, 'credit' : slip.total_pay, 'journal_id' : slip.journal_id.id, 'period_id' :period_id, 'ref':slip.number } - line_ids += [movel_pool.create(cr, uid, ded_rec)] + 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, @@ -152,8 +156,8 @@ class hr_payslip(osv.osv): 'period_id' :period_id, 'ref':slip.number } - line_ids += [movel_pool.create(cr, uid, cre_rec)] - + 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: @@ -169,40 +173,40 @@ class hr_payslip(osv.osv): 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 Expanse Entries to Account Lines - l_ids = movel_pool.search(cr, uid, [('name','=',name)]) + 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)]) + + 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, + '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) + 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, + '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)] + 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, @@ -216,85 +220,94 @@ class hr_payslip(osv.osv): 'period_id':period_id, 'ref':slip.number } - line_ids += [movel_pool.create(cr, uid, cre_rec)] - + line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)] + rec = { 'state':'done', 'move_payment_ids':[(6, 0, line_ids)], 'paid':True } - self.write(cr, uid, [slip.id], rec) + 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)]}) - + self.write(cr, uid, [slip.id], {'move_line_ids':[(4, exp_id)]}, context=context) + return True - - def account_check_sheet(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state':'accont_check'}) + + def account_check_sheet(self, cr, uid, ids, context=None): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'accont_check'}, context=context) return True - - def hr_check_sheet(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state':'hr_check'}) + + def hr_check_sheet(self, cr, uid, ids, context=None): + if context is None: + context = {} + self.write(cr, uid, ids, {'state':'hr_check'}, context=context) return True - - def verify_sheet(self, cr, uid, ids, context={}): - + + 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') - - for slip in self.browse(cr,uid,ids): + 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') + + if context is None: + context = {} + for slip in self.browse(cr, uid, ids, context=context): total_deduct = 0.0 - + line_ids = [] partner = False partner_id = False - + if not slip.employee_id.bank_account_id: raise osv.except_osv(_('Integrity Error !'), _('Please defined 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 defined 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 = self.pool.get('account.fiscalyear').search(cr, uid, []) + 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 = self.pool.get('account.fiscalyear').read(cr, uid, fiscal_year_ids, ['date_start','date_stop']) + 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)): year_exist = True if not year_exist: raise osv.except_osv(_('Warning !'), _('Fiscal Year is not defined for slip date %s'%slip.date)) - search_period = self.pool.get('account.period').search(cr,uid,[('date_start','<=',slip.date),('date_stop','>=',slip.date)]) - if not search_period: + search_periods = period_pool.search(cr,uid,[('date_start','<=',slip.date),('date_stop','>=',slip.date)], context=context) + if not search_periods: raise osv.except_osv(_('Warning !'), _('Period is not defined for slip date %s'%slip.date)) - period_id = search_period[0] - + period_id = search_periods[0] + move = { - #'name': slip.name, + #'name': slip.name, 'journal_id': slip.journal_id.id, - 'period_id': period_id, + 'period_id': period_id, 'date': slip.date, 'ref':slip.number, 'narration': slip.name } - move_id = move_pool.create(cr, uid, move) + move_id = move_pool.create(cr, uid, move, context=context) self.create_voucher(cr, uid, [slip.id], slip.name, move_id) - + line = { 'move_id':move_id, 'name': "By Basic Salary / " + slip.employee_id.name, 'date': slip.date, - 'account_id': slip.employee_id.salary_account.id, + 'account_id': slip.employee_id.salary_account.id, 'debit': slip.basic, 'credit': 0.0, 'quantity':slip.working_days, @@ -303,20 +316,20 @@ 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 - - move_line_id = movel_pool.create(cr, uid, line) + + move_line_id = movel_pool.create(cr, uid, line, context=context) line_ids += [move_line_id] - + line = { 'move_id':move_id, 'name': "To Basic Paysble Salary / " + slip.employee_id.name, 'partner_id': partner_id, - 'date': slip.date, - 'account_id': slip.employee_id.employee_account.id, + 'date': slip.date, + 'account_id': slip.employee_id.employee_account.id, 'debit': 0.0, 'quantity':slip.working_days, 'credit': slip.basic, @@ -324,20 +337,20 @@ class hr_payslip(osv.osv): 'period_id': period_id, 'ref':slip.number } - line_ids += [movel_pool.create(cr, uid, line)] - + line_ids += [movel_pool.create(cr, uid, line, context=context)] + for line in slip.line_ids: 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, - 'date': slip.date, - 'account_id': line.account_id.id, + 'date': slip.date, + 'account_id': line.account_id.id, 'debit': 0.0, 'credit' : 0.0, 'journal_id' : slip.journal_id.id, @@ -346,13 +359,13 @@ class hr_payslip(osv.osv): '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 - else: + else: rec['analytic_account_id'] = slip.deg_id.account_id.id - + if line.type == 'allowance' or line.type == 'otherpay': rec['debit'] = amount if not partner.property_account_payable: @@ -361,8 +374,8 @@ class hr_payslip(osv.osv): 'move_id':move_id, 'name': name, 'partner_id': partner_id, - 'date': slip.date, - 'account_id': partner.property_account_payable.id, + 'date': slip.date, + 'account_id': partner.property_account_payable.id, 'debit': 0.0, 'quantity':1, 'credit' : amount, @@ -370,7 +383,7 @@ class hr_payslip(osv.osv): 'period_id' :period_id, 'ref':slip.number } - line_ids += [movel_pool.create(cr, uid, ded_rec)] + line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] elif line.type == 'deduction' or line.type == 'otherdeduct': if not partner.property_account_receivable: raise osv.except_osv(_('Integrity Error !'), _('Please Configure Partners Receivable Account!!')) @@ -380,24 +393,24 @@ class hr_payslip(osv.osv): 'move_id':move_id, 'name': name, 'partner_id': partner_id, - 'date': slip.date, + 'date': slip.date, 'quantity':1, - 'account_id': partner.property_account_receivable.id, + '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)] - - line_ids += [movel_pool.create(cr, uid, rec)] - + line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)] + + line_ids += [movel_pool.create(cr, uid, rec, context=context)] + for contrub in line.category_id.contribute_ids: print contrib.name, contrub.code, contrub.amount_type, contrib.contribute_per, line.total - - - + + + # if line.company_contrib > 0: # company_contrib = line.company_contrib ## if line.category_id.amount_type == 'per': @@ -405,9 +418,9 @@ class hr_payslip(osv.osv): # narration = """Company Contribution of %s Encode same as a Company Expanse @ %s""" % (line.name, company_contrib) # move = { -# #'name': slip.name, +# #'name': slip.name, # 'journal_id': slip.journal_id.id, -# 'period_id': period_id, +# 'period_id': period_id, # 'date': slip.date, # 'ref':slip.number, # 'narration': narration @@ -415,11 +428,11 @@ class hr_payslip(osv.osv): # company_contrib_move_id = move_pool.create(cr, uid, move) # name = "[%s] - %s / %s - Company Contribution" % (line.code, line.name, slip.employee_id.name) # self.create_voucher(cr, uid, [slip.id], name, company_contrib_move_id) -# +# # ded_deb = { # 'move_id':company_contrib_move_id, # 'name': name, -# 'date': slip.date, +# 'date': slip.date, # 'quantity':1, # 'account_id': line.category_id.account_id.id, # 'debit': company_contrib, @@ -432,7 +445,7 @@ class hr_payslip(osv.osv): # ded_cre = { # 'move_id':company_contrib_move_id, # 'name': name, -# 'date': slip.date, +# 'date': slip.date, # 'quantity':1, # 'account_id': line.category_id.register_id.account_id.id, # 'debit': 0.0, @@ -442,26 +455,26 @@ class hr_payslip(osv.osv): # 'ref':slip.number # } # line_ids += [movel_pool.create(cr, uid, ded_cre)] -# +# # if line.category_id.include_in_salary: # narration = """Company Contribution of %s Deducted from Employee %s""" % (line.name, company_contrib) # move = { -# #'name': slip.name, +# #'name': slip.name, # 'journal_id': slip.journal_id.id, -# 'period_id': period_id, +# 'period_id': period_id, # 'date': slip.date, # 'ref':slip.number, # 'narration': narration # } # include_in_salary_move_id = move_pool.create(cr, uid, move) # self.create_voucher(cr, uid, [slip.id], narration, include_in_salary_move_id) -# +# # total_deduct += company_contrib # ded_deb = { # 'move_id':include_in_salary_move_id, # 'name': name, # 'partner_id': partner_id, -# 'date': slip.date, +# 'date': slip.date, # 'quantity':1, # 'account_id': partner.property_account_receivable.id, # 'debit': company_contrib, @@ -474,7 +487,7 @@ class hr_payslip(osv.osv): # ded_cre = { # 'move_id':include_in_salary_move_id, # 'name': name, -# 'date': slip.date, +# 'date': slip.date, # 'quantity':1, # 'account_id': line.category_id.account_id.id, # 'debit': 0.0, @@ -497,14 +510,14 @@ class hr_payslip(osv.osv): # } # if line.category_id.contribute: # ctr['comp_deduction'] = amount -# +# # company = 0.0 # employee = 0.0 # if line.category_id.contribute and line.category_id.include_in_salary and line.category_id.amount_type == 'per': # new_amount = (amount * (line.category_id.contribute_per / (1+line.category_id.contribute_per))) # company = new_amount # employee = amount - company -# +# # elif line.category_id.contribute and line.category_id.include_in_salary and line.category_id.amount_type == 'fix': # company = line.category_id.contribute_per # employee = amount - company @@ -512,11 +525,11 @@ class hr_payslip(osv.osv): # elif line.category_id.contribute and line.category_id.include_in_salary and line.category_id.amount_type == 'func': # company = self.pool.get('hr.allounce.deduction.categoty').execute_function(cr, uid, line.category_id.id, line.slip_id.basic, context) # employee = amount -# +# # elif line.category_id.contribute and not line.category_id.include_in_salary and line.category_id.amount_type == 'per': # company = amount * line.category_id.contribute_per # employee = amount -# +# # elif line.category_id.contribute and not line.category_id.include_in_salary and line.category_id.amount_type == 'fix': # company = line.category_id.contribute_per # employee = amount @@ -524,10 +537,10 @@ class hr_payslip(osv.osv): # elif line.category_id.contribute and not line.category_id.include_in_salary and line.category_id.amount_type == 'func': # company = self.pool.get('hr.allounce.deduction.categoty').execute_function(cr, uid, line.category_id.id, line.slip_id.basic, context) # employee = amount -# +# # ctr['emp_deduction'] = employee # ctr['comp_deduction'] = company -# +# # self.pool.get('hr.contibution.register.line').create(cr, uid, ctr) adj_move_id = False @@ -539,16 +552,16 @@ class hr_payslip(osv.osv): 'ref':slip.number, 'narration': 'Adjustment : %s' % (slip.name) } - adj_move_id = move_pool.create(cr, uid, move) + adj_move_id = move_pool.create(cr, uid, move, context=context) 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, - 'account_id': partner.property_account_receivable.id, + 'date': slip.date, + 'account_id': partner.property_account_receivable.id, 'debit': 0.0, 'quantity':1, 'credit' : total_deduct, @@ -556,13 +569,13 @@ class hr_payslip(osv.osv): 'period_id' :period_id, 'ref':slip.number } - line_ids += [movel_pool.create(cr, uid, ded_rec)] + 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, - 'account_id': partner.property_account_payable.id, + 'account_id': partner.property_account_payable.id, 'debit': total_deduct, 'quantity':1, 'credit' : 0.0, @@ -570,7 +583,7 @@ class hr_payslip(osv.osv): 'period_id' :period_id, 'ref':slip.number } - line_ids += [movel_pool.create(cr, uid, cre_rec)] + line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)] rec = { 'state':'confirm', @@ -578,12 +591,12 @@ 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')]) + exp_ids = exp_pool.search(cr, uid, [('date_valid','>=',dates[0]), ('date_valid','<=',dates[1]), ('state','=','invoiced')], context=context) if exp_ids: - acc = self.pool.get('ir.property').get(cr, uid, 'property_account_expense_categ', 'product.category') - for exp in exp_pool.browse(cr, uid, 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', @@ -594,12 +607,12 @@ class hr_payslip(osv.osv): 'expanse_id':exp.id, 'account_id':acc } - self.pool.get('hr.payslip.line').create(cr, uid, exp_res) - - self.write(cr, uid, [slip.id], rec) - + payslip_pool.create(cr, uid, exp_res, context=context) + + self.write(cr, uid, [slip.id], rec, context=context) + return True - + hr_payslip() class account_move_link_slip(osv.osv): diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py index 4297f8eb6c5..5be33854c57 100644 --- a/addons/hr_recruitment/hr_recruitment.py +++ b/addons/hr_recruitment/hr_recruitment.py @@ -136,11 +136,14 @@ class hr_applicant(osv.osv, crm.crm_case): 'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0], } - def onchange_job(self,cr, uid, ids, job, context={}): + def onchange_job(self,cr, uid, ids, job, context=None): + job_obj = self.pool.get('hr.job') + if context is None: + context = {} result = {} + if job: - job_obj = self.pool.get('hr.job') - result['department_id'] = job_obj.browse(cr, uid, job).department_id.id + result['department_id'] = job_obj.browse(cr, uid, job, context=context).department_id.id return {'value': result} return {'value': {'department_id': []}} @@ -152,14 +155,15 @@ class hr_applicant(osv.osv, crm.crm_case): @param uid: the current user’s ID for security checks, @param ids: List of case IDs @param context: A standard dictionary for contextual values""" + stage_obj = self.pool.get('hr.recruitment.stage') if not context: context = {} - for case in self.browse(cr, uid, ids, context): + for case in self.browse(cr, uid, ids, context=context): department = (case.department_id.id or False) st = case.stage_id.id or False - stage_ids = self.pool.get('hr.recruitment.stage').search(cr, uid, ['|',('department_id','=',department),('department_id','=',False)]) + stage_ids = stage_obj.search(cr, uid, ['|',('department_id','=',department),('department_id','=',False)], context=context) if st and stage_ids.index(st): - self.write(cr, uid, [case.id], {'stage_id': stage_ids[stage_ids.index(st)-1]}) + self.write(cr, uid, [case.id], {'stage_id': stage_ids[stage_ids.index(st)-1]}, context=context) return True def stage_next(self, cr, uid, ids, context=None): @@ -170,14 +174,15 @@ class hr_applicant(osv.osv, crm.crm_case): @param uid: the current user’s ID for security checks, @param ids: List of case IDs @param context: A standard dictionary for contextual values""" + stage_obj = self.pool.get('hr.recruitment.stage') if not context: context = {} - for case in self.browse(cr, uid, ids, context): + for case in self.browse(cr, uid, ids, context=context): department = (case.department_id.id or False) st = case.stage_id.id or False - stage_ids = self.pool.get('hr.recruitment.stage').search(cr, uid, ['|',('department_id','=',department),('department_id','=',False)]) + stage_ids = stage_obj.search(cr, uid, ['|',('department_id','=',department),('department_id','=',False)], context=context) if st and len(stage_ids) != stage_ids.index(st)+1: - self.write(cr, uid, [case.id], {'stage_id': stage_ids[stage_ids.index(st)+1]}) + self.write(cr, uid, [case.id], {'stage_id': stage_ids[stage_ids.index(st)+1]}, context=context) return True def action_makeMeeting(self, cr, uid, ids, context=None): @@ -191,13 +196,14 @@ class hr_applicant(osv.osv, crm.crm_case): @return : Dictionary value for created Meeting view """ + data_obj = self.pool.get('ir.model.data') + if context is None: + context = {} value = {} - for opp in self.browse(cr, uid, ids): - data_obj = self.pool.get('ir.model.data') - + for opp in self.browse(cr, uid, ids, context=context): # Get meeting views result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_meetings_filter') - res = data_obj.read(cr, uid, result, ['res_id']) + res = data_obj.read(cr, uid, result, ['res_id'], context=context) id1 = data_obj._get_id(cr, uid, 'crm', 'crm_case_calendar_view_meet') id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_meet') id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_meet') @@ -243,13 +249,13 @@ class hr_applicant(osv.osv, crm.crm_case): """ if not context: context = {} - record = self.browse(cr, uid, ids, context) + record = self.browse(cr, uid, ids, context=context) record = record and record[0] context.update({'survey_id': record.survey.id, 'response_id' : [record.response], 'response_no':0, }) value = self.pool.get("survey").action_print_survey(cr, uid, ids, context) return value - def message_new(self, cr, uid, msg, context): + def message_new(self, cr, uid, msg, context=None): """ Automatically calls when new email message arrives @@ -257,8 +263,10 @@ class hr_applicant(osv.osv, crm.crm_case): @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks """ - mailgate_pool = self.pool.get('email.server.tools') + attach_obj = self.pool.get('ir.attachment') + if context is None: + context = {} subject = msg.get('subject') body = msg.get('body') @@ -278,7 +286,7 @@ class hr_applicant(osv.osv, crm.crm_case): res = mailgate_pool.get_partner(cr, uid, msg.get('from')) if res: vals.update(res) - res = self.create(cr, uid, vals, context) + res = self.create(cr, uid, vals, context=context) message = _('A Job Request created') + " '" + subject + "' " + _("from Mailgate.") self.log(cr, uid, res, message) @@ -293,17 +301,19 @@ class hr_applicant(osv.osv, crm.crm_case): 'res_model': self._name, 'res_id': res, } - self.pool.get('ir.attachment').create(cr, uid, data_attach) + attach_obj.create(cr, uid, data_attach, context=context) return res - def message_update(self, cr, uid, ids, vals={}, msg="", default_act='pending', context={}): + def message_update(self, cr, uid, ids, vals={}, msg="", default_act='pending', context=None): """ @param self: The object pointer @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param ids: List of update mail’s IDs """ + if context is None: + context = {} if isinstance(ids, (str, int, long)): ids = [ids] @@ -329,7 +339,7 @@ class hr_applicant(osv.osv, crm.crm_case): vls[key] = res.group(2).lower() vals.update(vls) - res = self.write(cr, uid, ids, vals) + res = self.write(cr, uid, ids, vals, context=context) return res def msg_send(self, cr, uid, id, *args, **argv): diff --git a/addons/hr_recruitment/hr_recruitment_menu.xml b/addons/hr_recruitment/hr_recruitment_menu.xml index ec6b719c973..e49afdee833 100644 --- a/addons/hr_recruitment/hr_recruitment_menu.xml +++ b/addons/hr_recruitment/hr_recruitment_menu.xml @@ -1,50 +1,47 @@ - - + - ######################## JOB OPPORTUNITIES (menu) ########################### - - Applicants - hr.applicant - tree,form,graph,calendar - - {"search_default_user_id":uid, 'search_default_current': 1} - + ######################## JOB OPPORTUNITIES (menu) ########################### + + Applicants + hr.applicant + tree,form,graph,calendar + + {"search_default_user_id":uid, 'search_default_current': 1} + + - - - - tree - - - - - - form - - - - - - graph - - - - - + + + tree + + + - - + + + form + + + - + + + graph + + + + + + + + + + + diff --git a/addons/hr_recruitment/wizard/hr_recruitment_create_partner_job.py b/addons/hr_recruitment/wizard/hr_recruitment_create_partner_job.py index e9b68de37ea..28de96db4e4 100644 --- a/addons/hr_recruitment/wizard/hr_recruitment_create_partner_job.py +++ b/addons/hr_recruitment/wizard/hr_recruitment_create_partner_job.py @@ -31,9 +31,11 @@ class hr_recruitment_partner_create(osv.osv_memory): def view_init(self, cr , uid , fields_list, context=None): case_obj = self.pool.get('hr.applicant') - for case in case_obj.browse(cr, uid, context['active_ids']): + if context is None: + context = {} + for case in case_obj.browse(cr, uid, context['active_ids'], context=context): if case.partner_id: - raise osv.except_osv(_('Warning !'), + raise osv.except_osv(_('Error !'), _('A partner is already defined on this job request.')) pass @@ -45,31 +47,31 @@ class hr_recruitment_partner_create(osv.osv_memory): if context is None: context = {} - data = self.read(cr, uid, ids, [], context)[0] + data = self.read(cr, uid, ids, [], context=context)[0] result = mod_obj._get_id(cr, uid, 'base', 'view_res_partner_filter') - res = mod_obj.read(cr, uid, result, ['res_id']) + res = mod_obj.read(cr, uid, result, ['res_id'], context=context) - for case in case_obj.browse(cr, uid, context['active_ids']): - partner_id = partner_obj.search(cr, uid, [('name', '=', case.partner_name or case.name)]) + for case in case_obj.browse(cr, uid, context['active_ids'], context=context): + partner_id = partner_obj.search(cr, uid, [('name', '=', case.partner_name or case.name)], context=context) if partner_id: - raise osv.except_osv(_('Warning !'),_('A partner is already existing with the same name.')) + raise osv.except_osv(_('Error !'),_('A partner is already existing with the same name.')) partner_id = partner_obj.create(cr, uid, { 'name': case.partner_name or case.name, 'user_id': case.user_id.id, 'comment': case.description, - }) + }, context=context) contact_id = contact_obj.create(cr, uid, { 'partner_id': partner_id, 'name': case.partner_name, 'phone': case.partner_phone, 'mobile': case.partner_mobile, 'email': case.email_from - }) + }, context=context) case_obj.write(cr, uid, case.id, { 'partner_id': partner_id, 'partner_address_id': contact_id - }) + }, context=context) if data['close']: case_obj.case_close(cr, uid, context['active_ids']) diff --git a/addons/hr_recruitment/wizard/hr_recruitment_create_partner_job_view.xml b/addons/hr_recruitment/wizard/hr_recruitment_create_partner_job_view.xml index 63aaed34493..23e30d76113 100644 --- a/addons/hr_recruitment/wizard/hr_recruitment_create_partner_job_view.xml +++ b/addons/hr_recruitment/wizard/hr_recruitment_create_partner_job_view.xml @@ -9,9 +9,7 @@
- @@ -31,15 +29,5 @@ new - - \ No newline at end of file diff --git a/addons/hr_recruitment/wizard/hr_recruitment_phonecall.py b/addons/hr_recruitment/wizard/hr_recruitment_phonecall.py index 0517d7d7965..4d3917178d7 100644 --- a/addons/hr_recruitment/wizard/hr_recruitment_phonecall.py +++ b/addons/hr_recruitment/wizard/hr_recruitment_phonecall.py @@ -36,16 +36,22 @@ class job2phonecall(osv.osv_memory): def _date_user(self, cr, uid, context=None): case_obj = self.pool.get('hr.applicant') - case = case_obj.browse(cr, uid, context['active_id']) + if context is None: + context = {} + case = case_obj.browse(cr, uid, context['active_id'], context=context) return case.user_id and case.user_id.id or False def _date_category(self, cr, uid, context=None): - categ_id = self.pool.get('crm.case.categ').search(cr, uid, [('name','=','Outbound')]) + if context is None: + context = {} + categ_id = self.pool.get('crm.case.categ').search(cr, uid, [('name','=','Outbound')], context=context) return categ_id and categ_id[0] or case.categ_id and case.categ_id.id or False def _get_note(self, cr, uid, context=None): case_obj = self.pool.get('hr.applicant') - case = case_obj.browse(cr, uid, context['active_id']) + if context is None: + context = {} + case = case_obj.browse(cr, uid, context['active_id'], context=context) return case.description or '' _defaults = { @@ -59,11 +65,12 @@ class job2phonecall(osv.osv_memory): job_case_obj = self.pool.get('hr.applicant') data_obj = self.pool.get('ir.model.data') phonecall_case_obj = self.pool.get('crm.phonecall') - + if context is None: + context = {} form = self.read(cr, uid, ids, [], context=context)[0] # form = data['form'] result = mod_obj._get_id(cr, uid, 'crm', 'view_crm_case_phonecalls_filter') - res = mod_obj.read(cr, uid, result, ['res_id']) + res = mod_obj.read(cr, uid, result, ['res_id'], context=context) # Select the view id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_phone_tree_view') @@ -73,7 +80,7 @@ class job2phonecall(osv.osv_memory): if id3: id3 = data_obj.browse(cr, uid, id3, context=context).res_id - for job in job_case_obj.browse(cr, uid, context['active_ids']): + for job in job_case_obj.browse(cr, uid, context['active_ids'], context=context): #TODO : Take other info from job new_phonecall_id = phonecall_case_obj.create(cr, uid, { 'name' : job.name, @@ -90,11 +97,11 @@ class job2phonecall(osv.osv_memory): 'description':job.description, 'date':job.date, }, context=context) - new_phonecall = phonecall_case_obj.browse(cr, uid, new_phonecall_id) + new_phonecall = phonecall_case_obj.browse(cr, uid, new_phonecall_id, context=context) vals = {} # if not job.case_id: # vals.update({'phonecall_id' : new_phonecall.id}) - job_case_obj.write(cr, uid, [job.id], vals) + job_case_obj.write(cr, uid, [job.id], vals, context=context) job_case_obj.case_cancel(cr, uid, [job.id]) phonecall_case_obj.case_open(cr, uid, [new_phonecall_id]) @@ -111,4 +118,4 @@ class job2phonecall(osv.osv_memory): job2phonecall() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:>>>>>>> MERGE-SOURCE +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py index 2190a1c8149..a848fc6d352 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## @@ -39,13 +39,16 @@ hr_timesheet_invoice_factor() class account_analytic_account(osv.osv): - def _invoiced_calc(self, cr, uid, ids, name, arg, context={}): + def _invoiced_calc(self, cr, uid, ids, name, arg, context=None): + obj_invoice = self.pool.get('account.invoice') + if context is None: + context = {} res = {} - for account in self.browse(cr, uid, ids): + for account in self.browse(cr, uid, ids, context=context): invoiced = {} cr.execute('select distinct(l.invoice_id) from hr_analytic_timesheet h left join account_analytic_line l on (h.line_id=l.id) where account_id=%s', (account.id,)) invoice_ids = filter(None, map(lambda x: x[0], cr.fetchall())) - for invoice in self.pool.get('account.invoice').browse(cr, uid, invoice_ids, context): + for invoice in obj_invoice.browse(cr, uid, invoice_ids, context=context): res.setdefault(account.id, 0.0) res[account.id] += invoice.amount_untaxed for id in ids: @@ -73,20 +76,24 @@ account_analytic_account() class account_analytic_line(osv.osv): _inherit = 'account.analytic.line' _columns = { - 'invoice_id': fields.many2one('account.invoice', 'Invoice', ondelete="set null"), + 'invoice_id': fields.many2one('account.invoice', 'Invoice', ondelete="set null"), 'to_invoice': fields.many2one('hr_timesheet_invoice.factor', 'Type of Invoicing'), } def unlink(self, cursor, user, ids, context=None): + if context is None: + context = {} return super(account_analytic_line,self).unlink(cursor, user, ids, context=context) def write(self, cr, uid, ids, vals, context=None): - self._check_inv(cr, uid, ids,vals) + if context is None: + context = {} + self._check_inv(cr, uid, ids, vals) return super(account_analytic_line,self).write(cr, uid, ids, vals, context=context) - def _check_inv(self, cr, uid, ids,vals): + def _check_inv(self, cr, uid, ids, vals): select = ids if isinstance(select, (int, long)): select = [ids] @@ -98,12 +105,14 @@ class account_analytic_line(osv.osv): return True def copy(self, cursor, user, obj_id, default=None, context=None): + if context is None: + context = {} if default is None: default = {} default = default.copy() default.update({'invoice_id': False}) return super(account_analytic_line, self).copy(cursor, user, obj_id, - default, context) + default, context=context) account_analytic_line() @@ -126,12 +135,14 @@ class hr_analytic_timesheet(osv.osv): return res def copy(self, cursor, user, obj_id, default=None, context=None): + if context is None: + context = {} if default is None: default = {} default = default.copy() default.update({'invoice_id': False}) return super(hr_analytic_timesheet, self).copy(cursor, user, obj_id, - default, context) + default, context=context) hr_analytic_timesheet() diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_cost_ledger_report.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_cost_ledger_report.py index 418aac5edd3..892c93252ee 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_cost_ledger_report.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_cost_ledger_report.py @@ -39,7 +39,7 @@ class hr_timesheet_analytic_cost_ledger(osv.osv_memory): datas = { 'ids': 'active_ids' in context and context['active_ids'] or [], 'model': 'account.analytic.account', - 'form': self.read(cr, uid, ids)[0] + 'form': self.read(cr, uid, ids, context=context)[0] } return { 'type': 'ir.actions.report.xml', diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit.py index b83b84746d2..1ead36be0a7 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit.py @@ -48,16 +48,16 @@ class account_analytic_profit(osv.osv_memory): line_obj = self.pool.get('account.analytic.line') product_obj = self.pool.get('product.product') price_obj = self.pool.get('product.pricelist') - data = {} - data['form'] = self.read(cr, uid , ids, [], context=context)[0] if context is None: context = {} + data = {} + data['form'] = self.read(cr, uid , ids, [], context=context)[0] ids_chk = line_obj.search(cr, uid, [ ('date', '>=', data['form']['date_from']), ('date', '<=', data['form']['date_to']), ('journal_id', 'in', data['form']['journal_ids']), ('user_id', 'in', data['form']['employee_ids']), - ]) + ], context=context) if not ids_chk: raise osv.except_osv(_('Data Insufficient!'), _('No Records Found for Report!')) diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py index e8309d84921..4878a6634b2 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_final_invoice_create.py @@ -46,17 +46,21 @@ class final_invoice_create(osv.osv_memory): analytic_account_obj = self.pool.get('account.analytic.account') res_partner_obj = self.pool.get('res.partner') account_payment_term_obj = self.pool.get('account.payment.term') + invoice_obj = self.pool.get('account.invoice') + product_obj = self.pool.get('product.product') + fiscal_pos_obj = self.pool.get('account.fiscal.position') + invoice_line_obj = self.pool.get('account.invoice.line') invoices = [] if context is None: context = {} result = mod_obj._get_id(cr, uid, 'account', 'view_account_invoice_filter') - res = mod_obj.read(cr, uid, result, ['res_id']) + res = mod_obj.read(cr, uid, result, ['res_id'], context=context) - data = self.read(cr, uid, ids, [], context)[0] + data = self.read(cr, uid, ids, [], context=context)[0] account_ids = 'active_ids' in context and context['active_ids'] or [] - for account in analytic_account_obj.browse(cr, uid, account_ids, context): + for account in analytic_account_obj.browse(cr, uid, account_ids, context=context): partner = account.partner_id amount_total=0.0 if (not partner) or not (account.pricelist_id): @@ -77,15 +81,15 @@ class final_invoice_create(osv.osv_memory): curr_invoice = { 'name': time.strftime('%D')+' - '+account.name, 'partner_id': account.partner_id.id, - 'address_contact_id': self.pool.get('res.partner').address_get(cr, uid, [account.partner_id.id], adr_pref=['contact'])['contact'], - 'address_invoice_id': self.pool.get('res.partner').address_get(cr, uid, [account.partner_id.id], adr_pref=['invoice'])['invoice'], + 'address_contact_id': res_partner_obj.address_get(cr, uid, [account.partner_id.id], adr_pref=['contact'])['contact'], + 'address_invoice_id': res_partner_obj.address_get(cr, uid, [account.partner_id.id], adr_pref=['invoice'])['invoice'], 'payment_term': partner.property_payment_term.id or False, 'account_id': partner.property_account_receivable.id, 'currency_id': account.pricelist_id.currency_id.id, 'date_due': date_due, 'fiscal_position': account.partner_id.property_account_position.id } - last_invoice = self.pool.get('account.invoice').create(cr, uid, curr_invoice) + last_invoice = invoice_obj.create(cr, uid, curr_invoice, context=context) invoices.append(last_invoice) context2=context.copy() @@ -116,14 +120,14 @@ class final_invoice_create(osv.osv_memory): line.product_uom_id, move_line.ref""", (account.id,)) for product_id, amount, account_id, product_uom_id, ref in cr.fetchall(): - product = self.pool.get('product.product').browse(cr, uid, product_id, context2) + product = product_obj.browse(cr, uid, product_id, context2) if product: taxes = product.taxes_id else: taxes = [] - tax = self.pool.get('account.fiscal.position').map_tax(cr, uid, account.partner_id.property_account_position, taxes) + tax = fiscal_pos_obj.map_tax(cr, uid, account.partner_id.property_account_position, taxes) curr_line = { 'price_unit': -amount, 'quantity': 1.0, @@ -136,14 +140,13 @@ class final_invoice_create(osv.osv_memory): 'account_id': account_id, 'account_analytic_id': account.id } - self.pool.get('account.invoice.line').create(cr, uid, curr_line) + invoice_line_obj.create(cr, uid, curr_line, context=context) if not data['balance_product']: raise osv.except_osv(_('Balance product needed'), _('Please fill a Balance product in the wizard')) - product = self.pool.get('product.product').browse(cr, uid, data['balance_product'], context2) - + product = product_obj.browse(cr, uid, data['balance_product'], context2) taxes = product.taxes_id - tax = self.pool.get('account.fiscal.position').map_tax(cr, uid, account.partner_id.property_account_position, taxes) + tax = fiscal_pos_obj.map_tax(cr, uid, account.partner_id.property_account_position, taxes) account_id = product.product_tmpl_id.property_account_income.id or product.categ_id.property_account_income_categ.id curr_line = { 'price_unit': account.amount_max - amount_total, @@ -157,9 +160,9 @@ class final_invoice_create(osv.osv_memory): 'account_id': account_id, 'account_analytic_id': account.id } - self.pool.get('account.invoice.line').create(cr, uid, curr_line) + invoice_line_obj.create(cr, uid, curr_line, context=context) if account.amount_max < amount_total: - self.pool.get('account.invoice').write(cr, uid, [last_invoice], {'type': 'out_refund',}) + invoice_obj.write(cr, uid, [last_invoice], {'type': 'out_refund',}, context=context) cr.execute('update account_analytic_line set invoice_id=%s where invoice_id is null and account_id=%s', (last_invoice, account.id)) return { diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py index a5b2e35622c..1ed01c53281 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py @@ -49,7 +49,7 @@ class hr_timesheet_invoice_create(osv.osv_memory): if not len(context['active_ids']): return {} #Checking whether the analytic line is invoiced or not - analytic_line_obj = self.pool.get('account.analytic.line').browse(cr, uid, context['active_ids'], context) + analytic_line_obj = self.pool.get('account.analytic.line').browse(cr, uid, context['active_ids'], context=context) for obj_acc in analytic_line_obj: if obj_acc.invoice_id and obj_acc.invoice_id.state !='cancel': raise osv.except_osv(_('Warning'),_('The analytic entry "%s" is already invoiced!')%(obj_acc.name,)) @@ -67,13 +67,21 @@ class hr_timesheet_invoice_create(osv.osv_memory): analytic_account_obj = self.pool.get('account.analytic.account') res_partner_obj = self.pool.get('res.partner') account_payment_term_obj = self.pool.get('account.payment.term') + invoice_obj = self.pool.get('account.invoice') + product_obj = self.pool.get('product.product') + invoice_factor_obj = self.pool.get('hr_timesheet_invoice.factor') + pro_price_obj = self.pool.get('product.pricelist') + fiscal_pos_obj = self.pool.get('account.fiscal.position') + product_uom_obj = self.pool.get('product.uom') + invoice_line_obj = self.pool.get('account.invoice.line') invoices = [] - + if context is None: + context = {} result = mod_obj._get_id(cr, uid, 'account', 'view_account_invoice_filter') - res = mod_obj.read(cr, uid, result, ['res_id']) - data = self.read(cr, uid, ids, [], context)[0] + res = mod_obj.read(cr, uid, result, ['res_id'], context=context) + data = self.read(cr, uid, ids, [], context=context)[0] account_ids = data['accounts'] - for account in analytic_account_obj.browse(cr, uid, account_ids, context): + for account in analytic_account_obj.browse(cr, uid, account_ids, context=context): partner = account.partner_id if (not partner) or not (account.pricelist_id): raise osv.except_osv(_('Analytic Account incomplete'), @@ -106,7 +114,7 @@ class hr_timesheet_invoice_create(osv.osv_memory): 'date_due': date_due, 'fiscal_position': account.partner_id.property_account_position.id } - last_invoice = self.pool.get('account.invoice').create(cr, uid, curr_invoice) + last_invoice = invoice_obj.create(cr, uid, curr_invoice, context=context) invoices.append(last_invoice) context2 = context.copy() @@ -115,14 +123,14 @@ class hr_timesheet_invoice_create(osv.osv_memory): "FROM account_analytic_line as line " \ "WHERE account_id = %s " \ "AND id IN %s AND to_invoice IS NOT NULL " \ - "GROUP BY product_id,to_invoice", (account.id,tuple(context['active_ids']),)) + "GROUP BY product_id,to_invoice", (account.id, tuple(context['active_ids']),)) - for product_id,factor_id,qty in cr.fetchall(): - product = self.pool.get('product.product').browse(cr, uid, product_id, context2) + for product_id, factor_id, qty in cr.fetchall(): + product = product_obj.browse(cr, uid, product_id, context2) if not product: raise osv.except_osv(_('Error'), _('At least one line has no product !')) factor_name = '' - factor = self.pool.get('hr_timesheet_invoice.factor').browse(cr, uid, factor_id, context2) + factor = invoice_factor_obj.browse(cr, uid, factor_id, context2) if not data['product']: if factor.customer_name: @@ -130,16 +138,16 @@ class hr_timesheet_invoice_create(osv.osv_memory): else: factor_name = product.name else: - factor_name = self.pool.get('product.product').name_get(cr, uid, [data['product']], context=context)[0][1] + factor_name = product_obj.name_get(cr, uid, [data['product']], context=context)[0][1] if account.pricelist_id: pl = account.pricelist_id.id - price = self.pool.get('product.pricelist').price_get(cr,uid,[pl], data['product'] or product_id, qty or 1.0, account.partner_id.id)[pl] + price = pro_price_obj.price_get(cr,uid,[pl], data['product'] or product_id, qty or 1.0, account.partner_id.id)[pl] else: price = 0.0 taxes = product.taxes_id - tax = self.pool.get('account.fiscal.position').map_tax(cr, uid, account.partner_id.property_account_position, taxes) + tax = fiscal_pos_obj.map_tax(cr, uid, account.partner_id.property_account_position, taxes) account_id = product.product_tmpl_id.property_account_income.id or product.categ_id.property_account_income_categ.id curr_line = { 'price_unit': price, @@ -169,7 +177,7 @@ class hr_timesheet_invoice_create(osv.osv_memory): details.append(line['date']) if data['time']: if line['product_uom_id']: - details.append("%s %s" % (line['unit_amount'], self.pool.get('product.uom').browse(cr, uid, [line['product_uom_id']],context2)[0].name)) + details.append("%s %s" % (line['unit_amount'], product_uom_obj.browse(cr, uid, [line['product_uom_id']],context2)[0].name)) else: details.append("%s" % (line['unit_amount'], )) if data['name']: @@ -179,17 +187,17 @@ class hr_timesheet_invoice_create(osv.osv_memory): note.append(u' - '.join(map(lambda x: unicode(x) or '',details))) curr_line['note'] = "\n".join(map(lambda x: unicode(x) or '',note)) - self.pool.get('account.invoice.line').create(cr, uid, curr_line) + invoice_line_obj.create(cr, uid, curr_line, context=context) cr.execute("update account_analytic_line set invoice_id=%s WHERE account_id = %s and id IN %s" ,(last_invoice, account.id,tuple(data['ids']))) - self.pool.get('account.invoice').button_reset_taxes(cr, uid, [last_invoice], context) + invoice_obj.button_reset_taxes(cr, uid, [last_invoice], context) mod_obj = self.pool.get('ir.model.data') act_obj = self.pool.get('ir.actions.act_window') - mod_id = mod_obj.search(cr, uid, [('name', '=', 'action_invoice_tree1')])[0] - res_id = mod_obj.read(cr, uid, mod_id, ['res_id'])['res_id'] - act_win = act_obj.read(cr, uid, res_id, []) + mod_ids = mod_obj.search(cr, uid, [('name', '=', 'action_invoice_tree1')], context=context)[0] + res_id = mod_obj.read(cr, uid, mod_ids, ['res_id'], context=context)['res_id'] + act_win = act_obj.read(cr, uid, res_id, [], context=context) act_win['domain'] = [('id','in',invoices),('type','=','out_invoice')] act_win['name'] = _('Invoices') return act_win diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index 62dce204c4d..8b9744877b9 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -20,10 +20,9 @@ ############################################################################## import time -from osv import fields -from osv import osv import netsvc +from osv import fields, osv from mx import DateTime from tools.translate import _ @@ -139,7 +138,7 @@ class hr_timesheet_sheet(osv.osv): for sheet in self.browse(cr, uid, ids, context=context): result[sheet.id] = 'none' emp_ids2 = emp_obj.search(cr, uid, - [('user_id', '=', sheet.user_id.id)]) + [('user_id', '=', sheet.user_id.id)], context=context) if emp_ids2: link_emp[emp_ids2[0]] = sheet.id emp_ids.append(emp_ids2[0]) @@ -169,11 +168,11 @@ class hr_timesheet_sheet(osv.osv): context = {} for sheet in self.browse(cr, uid, ids, context=context): if DateTime.now() <= DateTime.strptime(sheet.date_from, '%Y-%m-%d'): - self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,}) + self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,}, context=context) elif DateTime.now() >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'): - self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,}) + self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,}, context=context) else: - self.write(cr, uid, [sheet.id], {'date_current': time.strftime('%Y-%m-%d')}) + self.write(cr, uid, [sheet.id], {'date_current': time.strftime('%Y-%m-%d')}, context=context) return True def date_previous(self, cr, uid, ids, context=None): @@ -181,11 +180,11 @@ class hr_timesheet_sheet(osv.osv): context = {} for sheet in self.browse(cr, uid, ids, context=context): if DateTime.strptime(sheet.date_current, '%Y-%m-%d') <= DateTime.strptime(sheet.date_from, '%Y-%m-%d'): - self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,}) + self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,}, context=context) else: self.write(cr, uid, [sheet.id], { 'date_current': (DateTime.strptime(sheet.date_current, '%Y-%m-%d') + DateTime.RelativeDateTime(days=-1)).strftime('%Y-%m-%d'), - }) + }, context=context) return True def date_next(self, cr, uid, ids, context=None): @@ -193,11 +192,11 @@ class hr_timesheet_sheet(osv.osv): context = {} for sheet in self.browse(cr, uid, ids, context=context): if DateTime.strptime(sheet.date_current, '%Y-%m-%d') >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'): - self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,}) + self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,}, context=context) else: self.write(cr, uid, [sheet.id], { 'date_current': (DateTime.strptime(sheet.date_current, '%Y-%m-%d') + DateTime.RelativeDateTime(days=1)).strftime('%Y-%m-%d'), - }) + }, context=context) return True def button_dummy(self, cr, uid, ids, context=None): @@ -205,31 +204,31 @@ class hr_timesheet_sheet(osv.osv): context = {} for sheet in self.browse(cr, uid, ids, context=context): if DateTime.strptime(sheet.date_current, '%Y-%m-%d') <= DateTime.strptime(sheet.date_from, '%Y-%m-%d'): - self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,}) + self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,}, context=context) elif DateTime.strptime(sheet.date_current, '%Y-%m-%d') >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'): - self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,}) + self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,}, context=context) return True def sign_in(self, cr, uid, ids, context=None): emp_obj = self.pool.get('hr.employee') if context is None: context = {} - if not self.browse(cr, uid, ids, context)[0].date_current == time.strftime('%Y-%m-%d'): + if not self.browse(cr, uid, ids, context=context)[0].date_current == time.strftime('%Y-%m-%d'): raise osv.except_osv(_('Error !'), _('You can not sign in from an other date than today')) - emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)]) + emp_ids = emp_obj.search(cr, uid, [('user_id', '=', uid)], context=context) context['sheet_id']=ids[0] - success = emp_obj.attendance_action_change(cr, uid, emp_id, type='sign_in', context=context,) + success = emp_obj.attendance_action_change(cr, uid, emp_ids, type='sign_in', context=context,) return True def sign_out(self, cr, uid, ids, context=None): emp_obj = self.pool.get('hr.employee') if context is None: context = {} - if not self.browse(cr, uid, ids, context)[0].date_current == time.strftime('%Y-%m-%d'): + if not self.browse(cr, uid, ids, context=context)[0].date_current == time.strftime('%Y-%m-%d'): raise osv.except_osv(_('Error !'), _('You can not sign out from an other date than today')) - emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)]) + emp_ids = emp_obj.search(cr, uid, [('user_id', '=', uid)]) context['sheet_id']=ids[0] - success = emp_obj.attendance_action_change(cr, uid, emp_id, type='sign_out', context=context,) + success = emp_obj.attendance_action_change(cr, uid, emp_ids, type='sign_out', context=context,) return True _columns = { @@ -268,7 +267,9 @@ class hr_timesheet_sheet(osv.osv): 'department_id':fields.many2one('hr.department','Department'), } - def _default_date_from(self,cr, uid, context={}): + def _default_date_from(self,cr, uid, context=None): + if context is None: + context = {} user = self.pool.get('res.users').browse(cr, uid, uid, context=context) r = user.company_id and user.company_id.timesheet_range or 'month' if r=='month': @@ -279,7 +280,7 @@ class hr_timesheet_sheet(osv.osv): return time.strftime('%Y-01-01') return time.strftime('%Y-%m-%d') - def _default_date_to(self,cr, uid, context={}): + def _default_date_to(self,cr, uid, context=None): user = self.pool.get('res.users').browse(cr, uid, uid, context=context) r = user.company_id and user.company_id.timesheet_range or 'month' if r=='month': @@ -330,17 +331,19 @@ class hr_timesheet_sheet(osv.osv): wf_service.trg_create(uid, self._name, id, cr) return True - def name_get(self, cr, uid, ids, context={}): + def name_get(self, cr, uid, ids, context=None): + if context is None: + context = {} if not len(ids): return [] return [(r['id'], r['date_from'] + ' - ' + r['date_to']) \ for r in self.read(cr, uid, ids, ['date_from', 'date_to'], - context, load='_classic_write')] + context=context, load='_classic_write')] def unlink(self, cr, uid, ids, context=None): if context is None: context = {} - sheets = self.read(cr, uid, ids, ['state','total_attendance']) + sheets = self.read(cr, uid, ids, ['state','total_attendance'], context=context) for sheet in sheets: if sheet['state'] in ('confirm', 'done'): raise osv.except_osv(_('Invalid action !'), _('Cannot delete Sheet(s) which are already confirmed !')) @@ -354,14 +357,17 @@ hr_timesheet_sheet() class hr_timesheet_line(osv.osv): _inherit = "hr.analytic.timesheet" - def _get_default_date(self, cr, uid, context={}): + def _get_default_date(self, cr, uid, context=None): + if context is None: + context = {} if 'date' in context: return context['date'] return time.strftime('%Y-%m-%d') - def _sheet(self, cursor, user, ids, name, args, context): + def _sheet(self, cursor, user, ids, name, args, context=None): sheet_obj = self.pool.get('hr_timesheet_sheet.sheet') - + if context is None: + context = {} cursor.execute('SELECT l.id, COALESCE(MAX(s.id), 0) \ FROM hr_timesheet_sheet_sheet s \ LEFT JOIN (hr_analytic_timesheet l \ @@ -386,6 +392,8 @@ class hr_timesheet_line(osv.osv): return res def _sheet_search(self, cursor, user, obj, name, args, context=None): + if context is None: + context = {} if not len(args): return [] sheet_obj = self.pool.get('hr_timesheet_sheet.sheet') @@ -395,7 +403,7 @@ class hr_timesheet_line(osv.osv): fargs = args[i][0].split('.', 1) if len(fargs) > 1: args[i] = (fargs[0], 'in', sheet_obj.search(cursor, user, - [(fargs[1], args[i][1], args[i][2])])) + [(fargs[1], args[i][1], args[i][2])], context=context)) i += 1 continue if isinstance(args[i][2], basestring): @@ -472,12 +480,16 @@ hr_timesheet_line() class hr_attendance(osv.osv): _inherit = "hr.attendance" - def _get_default_date(self, cr, uid, context={}): + def _get_default_date(self, cr, uid, context=None): + if context is None: + context = {} if 'name' in context: return context['name'] + time.strftime(' %H:%M:%S') return time.strftime('%Y-%m-%d %H:%M:%S') - def _sheet(self, cursor, user, ids, name, args, context): + def _sheet(self, cursor, user, ids, name, args, context=None): + if context is None: + context = {} sheet_obj = self.pool.get('hr_timesheet_sheet.sheet') cursor.execute("SELECT a.id, COALESCE(MAX(s.id), 0) \ FROM hr_timesheet_sheet_sheet s \ @@ -506,14 +518,16 @@ class hr_attendance(osv.osv): def _sheet_search(self, cursor, user, obj, name, args, context=None): if not len(args): return [] - sheet_obj = self.pool.get('hr_timesheet_sheet.sheet') + sheet_obj = self.pool.get('hr_timesheet_sheet.sheet') + if context is None: + context = {} i = 0 while i < len(args): fargs = args[i][0].split('.', 1) if len(fargs) > 1: args[i] = (fargs[0], 'in', sheet_obj.search(cursor, user, - [(fargs[1], args[i][1], args[i][2])])) + [(fargs[1], args[i][1], args[i][2])], context=context)) i += 1 continue if isinstance(args[i][2], basestring): @@ -570,7 +584,7 @@ class hr_attendance(osv.osv): if context is None: context = {} if 'sheet_id' in context: - ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, context['sheet_id']) + ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, context['sheet_id'], context=context) if ts.state not in ('draft', 'new'): raise osv.except_osv(_('Error !'), _('You cannot modify an entry in a confirmed timesheet !')) res = super(hr_attendance,self).create(cr, uid, vals, context=context) @@ -584,7 +598,7 @@ class hr_attendance(osv.osv): self._check(cr, uid, ids) return super(hr_attendance,self).unlink(cr, uid, ids,*args, **kwargs) - def write(self, cr, uid, ids, vals, context={}): + def write(self, cr, uid, ids, vals, context=None): if context is None: context = {} self._check(cr, uid, ids) diff --git a/addons/hr_timesheet_sheet/wizard/hr_timesheet_current.py b/addons/hr_timesheet_sheet/wizard/hr_timesheet_current.py index 4d9998014c8..6ec2dd5b1e8 100644 --- a/addons/hr_timesheet_sheet/wizard/hr_timesheet_current.py +++ b/addons/hr_timesheet_sheet/wizard/hr_timesheet_current.py @@ -29,18 +29,20 @@ class hr_timesheet_current_open(osv.osv_memory): def open_timesheet(self, cr, uid, ids, context=None): ts = self.pool.get('hr_timesheet_sheet.sheet') + if context is None: + context = {} view_type = 'form,tree' - user_ids = self.pool.get('hr.employee').search(cr, uid, [('user_id','=',uid)]) + user_ids = self.pool.get('hr.employee').search(cr, uid, [('user_id','=',uid)], context=context) if not len(user_ids): raise osv.except_osv(_('Error !'), _('No employee defined for your user !')) - ids = ts.search(cr, uid, [('user_id','=',uid),('state','=','draft'),('date_from','<=',time.strftime('%Y-%m-%d')), ('date_to','>=',time.strftime('%Y-%m-%d'))]) + ids = ts.search(cr, uid, [('user_id','=',uid),('state','=','draft'),('date_from','<=',time.strftime('%Y-%m-%d')), ('date_to','>=',time.strftime('%Y-%m-%d'))], context=context) if len(ids) > 1: view_type = 'tree,form' domain = "[('id','in',["+','.join(map(str, ids))+"]),('user_id', '=', uid)]" elif len(ids)==1: - ts.write(cr, uid, ids, {'date_current': time.strftime('%Y-%m-%d')}) + ts.write(cr, uid, ids, {'date_current': time.strftime('%Y-%m-%d')}, context=context) domain = "[('user_id', '=', uid)]" else: domain = "[('user_id', '=', uid)]"