diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index ce6341cc9b2..fa28f13b42e 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.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 . # ############################################################################## @@ -42,23 +42,23 @@ class account_analytic_line(osv.osv): } _defaults = { 'date': lambda *a: time.strftime('%Y-%m-%d'), - 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', c), + 'company_id': lambda self,cr,uid,context: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context=context), } _order = 'date' - + def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): if context is None: context = {} if context.get('from_date',False): args.append(['date', '>=',context['from_date']]) - + if context.get('to_date',False): args.append(['date','<=',context['to_date']]) - + return super(account_analytic_line, self).search(cr, uid, args, offset, limit, order, context=context, count=count) - + def _check_company(self, cr, uid, ids): lines = self.browse(cr, uid, ids) for l in lines: @@ -68,7 +68,7 @@ class account_analytic_line(osv.osv): _constraints = [ # (_check_company, 'You can not create analytic line that is not in the same company than the account line', ['account_id']) ] - + # Compute the cost based on the price type define into company # property_valuation_price_type property def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount,company_id, @@ -90,7 +90,7 @@ class account_analytic_line(osv.osv): (prod.name, prod.id,)) if not company_id: company_id=company_obj._company_default_get(cr, uid, 'account.analytic.line', context) - + # Compute based on pricetype pricetype=self.pool.get('product.price.type').browse(cr,uid,company_obj.browse(cr,uid,company_id).property_valuation_price_type.id) # Take the company currency as the reference one @@ -164,10 +164,10 @@ timesheet_invoice() class res_partner(osv.osv): """ Inherits partner and adds contract information in the partner form """ _inherit = 'res.partner' - + _columns = { 'contract_ids': fields.one2many('account.analytic.account', \ - 'partner_id', 'Contracts'), + 'partner_id', 'Contracts'), } res_partner() diff --git a/addons/hr_contract/hr_contract_view.xml b/addons/hr_contract/hr_contract_view.xml index 9951a9e3982..66e1fba946a 100644 --- a/addons/hr_contract/hr_contract_view.xml +++ b/addons/hr_contract/hr_contract_view.xml @@ -142,13 +142,12 @@ - - + @@ -203,6 +202,7 @@ + diff --git a/addons/hr_timesheet/hr_timesheet.py b/addons/hr_timesheet/hr_timesheet.py index 25c61483391..9b53eaa8828 100644 --- a/addons/hr_timesheet/hr_timesheet.py +++ b/addons/hr_timesheet/hr_timesheet.py @@ -43,16 +43,16 @@ class hr_analytic_timesheet(osv.osv): _inherits = {'account.analytic.line': 'line_id'} _order = "id desc" _columns = { - 'line_id' : fields.many2one('account.analytic.line', 'Analytic line', ondelete='cascade'), + 'line_id' : fields.many2one('account.analytic.line', 'Analytic line', ondelete='cascade'), 'partner_id': fields.related('account_id', 'partner_id', type='many2one', string='Partner Id',relation='account.analytic.account',store=True), } def unlink(self, cr, uid, ids, context={}): toremove = {} - for obj in self.browse(cr, uid, ids, context): + for obj in self.browse(cr, uid, ids, context=context): toremove[obj.line_id.id] = True - self.pool.get('account.analytic.line').unlink(cr, uid, toremove.keys(), context) - return super(hr_analytic_timesheet, self).unlink(cr, uid, ids, context) + self.pool.get('account.analytic.line').unlink(cr, uid, toremove.keys(), context=context) + return super(hr_analytic_timesheet, self).unlink(cr, uid, ids, context=context) def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount, unit, context={}): @@ -60,30 +60,34 @@ class hr_analytic_timesheet(osv.osv): # if prod_id and unit_amount: if prod_id: # find company - company_id=self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context) - res = self.pool.get('account.analytic.line').on_change_unit_amount(cr, uid, id, prod_id, unit_amount,company_id,unit, context) + company_id = self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context=context) + res = self.pool.get('account.analytic.line').on_change_unit_amount(cr, uid, id, prod_id, unit_amount, company_id, unit, context=context) return res - def _getEmployeeProduct(self, cr, uid, context): + def _getEmployeeProduct(self, cr, uid, context={}): emp_obj = self.pool.get('hr.employee') emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id', uid))]) if emp_id: - emp=emp_obj.browse(cr, uid, emp_id[0], context) + emp=emp_obj.browse(cr, uid, emp_id[0], context=context) if emp.product_id: return emp.product_id.id return False - def _getEmployeeUnit(self, cr, uid, context): + def _getEmployeeUnit(self, cr, uid, context=None): emp_obj = self.pool.get('hr.employee') + if context is None: + context = {} emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id', uid))]) if emp_id: - emp=emp_obj.browse(cr, uid, emp_id[0], context) + emp=emp_obj.browse(cr, uid, emp_id[0], context=context) if emp.product_id: return emp.product_id.uom_id.id return False - def _getGeneralAccount(self, cr, uid, context): + def _getGeneralAccount(self, cr, uid, context=None): emp_obj = self.pool.get('hr.employee') + if context is None: + context = {} emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id', uid))]) if emp_id: emp = emp_obj.browse(cr, uid, emp_id[0], context=context) @@ -95,8 +99,10 @@ class hr_analytic_timesheet(osv.osv): return a return False - def _getAnalyticJournal(self, cr, uid, context): + def _getAnalyticJournal(self, cr, uid, context=None): emp_obj = self.pool.get('hr.employee') + if context is None: + context = {} emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id', uid))]) if emp_id: emp = emp_obj.browse(cr, uid, emp_id[0], context=context) @@ -110,7 +116,7 @@ class hr_analytic_timesheet(osv.osv): 'product_id' : _getEmployeeProduct, 'general_account_id' : _getGeneralAccount, 'journal_id' : _getAnalyticJournal, - 'date' : lambda self,cr,uid,ctx: ctx.get('date', time.strftime('%Y-%m-%d')), + 'date' : lambda self, cr, uid, ctx : ctx.get('date', time.strftime('%Y-%m-%d')), 'user_id' : lambda obj, cr, uid, ctx : ctx.get('user_id', uid), } def on_change_account_id(self, cr, uid, ids, account_id): @@ -147,5 +153,4 @@ class hr_analytic_timesheet(osv.osv): }} hr_analytic_timesheet() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/hr_timesheet_invoice/report/hr_timesheet_invoice_report_view.xml b/addons/hr_timesheet_invoice/report/hr_timesheet_invoice_report_view.xml index cb6c8d5771c..373bd3c7907 100644 --- a/addons/hr_timesheet_invoice/report/hr_timesheet_invoice_report_view.xml +++ b/addons/hr_timesheet_invoice/report/hr_timesheet_invoice_report_view.xml @@ -61,10 +61,6 @@ help="Timesheet lines during last 7 days"/> - - - - - + + + + + + + + + + - - - - - - - - - - + + + + @@ -100,7 +96,7 @@ report.timesheet.line form tree,graph - {'search_default_month':1,'search_default_User':1,'group_by_no_leaf':1,'group_by':[]} + {'search_default_month':1,'search_default_User':1,'search_default_user_id':uid,'group_by_no_leaf':1,'group_by':[]} @@ -491,6 +487,7 @@ random.timesheet.lines form tree,form + {'search_default_user_id':uid } diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index b7d395ac2e0..26e16da955a 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -27,6 +27,8 @@ import netsvc from mx import DateTime from tools.translate import _ +import sql_db + class one2many_mod2(fields.one2many): def get(self, cr, obj, ids, name, user=None, offset=0, context={}, values={}): @@ -34,7 +36,7 @@ class one2many_mod2(fields.one2many): for id in ids: res[id] = [] - res5 = obj.read(cr, user, ids, ['date_current', 'user_id'], context) + res5 = obj.read(cr, user, ids, ['date_current', 'user_id'], context=context) res6 = {} for r in res5: res6[r['id']] = (r['date_current'], r['user_id'][0]) @@ -71,7 +73,7 @@ class one2many_mod(fields.one2many): for id in ids: res[id] = [] - res5 = obj.read(cr, user, ids, ['date_current', 'user_id'], context) + res5 = obj.read(cr, user, ids, ['date_current', 'user_id'], context=context) res6 = {} for r in res5: res6[r['id']] = (r['date_current'], r['user_id'][0]) @@ -111,8 +113,10 @@ class hr_timesheet_sheet(osv.osv): res[record[0]]['total_difference_day'] = record[3] return res - def _total(self, cr, uid, ids, name, args, context): + def _total(self, cr, uid, ids, name, args, context=None): res = {} + if context is None: + context = {} cr.execute('SELECT s.id, COALESCE(SUM(d.total_attendance),0), COALESCE(SUM(d.total_timesheet),0), COALESCE(SUM(d.total_difference),0) \ FROM hr_timesheet_sheet_sheet s \ LEFT JOIN hr_timesheet_sheet_sheet_day d \ @@ -125,13 +129,15 @@ class hr_timesheet_sheet(osv.osv): res[record[0]]['total_difference'] = record[3] return res - def _state_attendance(self, cr, uid, ids, name, args, context): + def _state_attendance(self, cr, uid, ids, name, args, context=None): + emp_obj = self.pool.get('hr.employee') result = {} link_emp = {} emp_ids = [] - emp_obj = self.pool.get('hr.employee') + if context is None: + context = {} - for sheet in self.browse(cr, uid, ids, context): + 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)]) @@ -147,8 +153,10 @@ class hr_timesheet_sheet(osv.osv): def copy(self, cr, uid, ids, *args, **argv): raise osv.except_osv(_('Error !'), _('You can not duplicate a timesheet !')) - def button_confirm(self, cr, uid, ids, context): - for sheet in self.browse(cr, uid, ids, context): + def button_confirm(self, cr, uid, ids, context=None): + if context is None: + context = {} + for sheet in self.browse(cr, uid, ids, context=context): di = sheet.user_id.company_id.timesheet_max_difference if (abs(sheet.total_difference) < di) or not di: wf_service = netsvc.LocalService("workflow") @@ -157,8 +165,10 @@ class hr_timesheet_sheet(osv.osv): raise osv.except_osv(_('Warning !'), _('Please verify that the total difference of the sheet is lower than %.2f !') %(di,)) return True - def date_today(self, cr, uid, ids, context): - for sheet in self.browse(cr, uid, ids, context): + def date_today(self, cr, uid, ids, context=None): + if context is None: + 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,}) elif DateTime.now() >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'): @@ -167,8 +177,10 @@ class hr_timesheet_sheet(osv.osv): self.write(cr, uid, [sheet.id], {'date_current': time.strftime('%Y-%m-%d')}) return True - def date_previous(self, cr, uid, ids, context): - for sheet in self.browse(cr, uid, ids, context): + def date_previous(self, cr, uid, ids, context=None): + if context is None: + 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,}) else: @@ -177,8 +189,10 @@ class hr_timesheet_sheet(osv.osv): }) return True - def date_next(self, cr, uid, ids, context): - for sheet in self.browse(cr, uid, ids, context): + def date_next(self, cr, uid, ids, context=None): + if context is None: + 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,}) else: @@ -187,27 +201,33 @@ class hr_timesheet_sheet(osv.osv): }) return True - def button_dummy(self, cr, uid, ids, context): - for sheet in self.browse(cr, uid, ids, context): + def button_dummy(self, cr, uid, ids, context=None): + if context is None: + 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,}) 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,}) return True - def sign_in(self, cr, uid, ids, context): + 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'): raise osv.except_osv(_('Error !'), _('You can not sign in from an other date than today')) - emp_obj = self.pool.get('hr.employee') emp_id = 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_in', context=context,) return True - def sign_out(self, cr, uid, ids, context): + 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'): raise osv.except_osv(_('Error !'), _('You can not sign out from an other date than today')) - emp_obj = self.pool.get('hr.employee') emp_id = 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,) @@ -250,7 +270,7 @@ class hr_timesheet_sheet(osv.osv): } def _default_date_from(self,cr, uid, context={}): - user = self.pool.get('res.users').browse(cr, uid, uid, 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': return time.strftime('%Y-%m-01') @@ -261,7 +281,7 @@ class hr_timesheet_sheet(osv.osv): return time.strftime('%Y-%m-%d') def _default_date_to(self,cr, uid, context={}): - user = self.pool.get('res.users').browse(cr, uid, uid, 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': return (DateTime.now() + DateTime.RelativeDateTime(months=+1,day=1,days=-1)).strftime('%Y-%m-%d') @@ -276,8 +296,8 @@ class hr_timesheet_sheet(osv.osv): 'date_from' : _default_date_from, 'date_current' : lambda *a: time.strftime('%Y-%m-%d'), 'date_to' : _default_date_to, - 'state': lambda *a: 'new', - 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr_timesheet_sheet.sheet', context=c) + 'state': 'new', + 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr_timesheet_sheet.sheet', context=c) } def _sheet_date(self, cr, uid, ids): @@ -301,7 +321,7 @@ class hr_timesheet_sheet(osv.osv): _constraints = [ (_sheet_date, 'You can not have 2 timesheets that overlaps !\nPlease use the menu \'My Current Timesheet\' to avoid this problem.', ['date_from','date_to']), - (_date_current_check, 'You must select a Current date wich is in the timesheet dates !', ['date_current']), + (_date_current_check, 'You must select a Current date which is in the timesheet dates !', ['date_current']), ] def action_set_to_draft(self, cr, uid, ids, *args): @@ -319,6 +339,8 @@ class hr_timesheet_sheet(osv.osv): 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']) for sheet in sheets: if sheet['state'] in ('confirm', 'done'): diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml b/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml index eae4e8e1e9a..4ea4fdb1c75 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml @@ -220,7 +220,7 @@ hr_timesheet_sheet.sheet form - {'search_default_my_timesheet':1} + {'search_default_my_timesheet':1, 'search_default_user_id':uid } diff --git a/addons/hr_timesheet_sheet/report/timesheet_report_view.xml b/addons/hr_timesheet_sheet/report/timesheet_report_view.xml index 976b2a6f8ea..1f9e70970a3 100644 --- a/addons/hr_timesheet_sheet/report/timesheet_report_view.xml +++ b/addons/hr_timesheet_sheet/report/timesheet_report_view.xml @@ -68,10 +68,6 @@ domain="[('state','=','done')]"/> - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + @@ -111,7 +107,7 @@ timesheet.report form tree,graph - {'search_default_month':1,'search_default_User':1,'group_by_no_leaf':1,'group_by':[]} + {'search_default_month':1, 'search_default_User':1, 'search_default_user_id':uid, 'group_by_no_leaf':1,'group_by':[]} diff --git a/addons/project/project_view.xml b/addons/project/project_view.xml index cec9ed95c0c..005e76e44ab 100644 --- a/addons/project/project_view.xml +++ b/addons/project/project_view.xml @@ -122,6 +122,7 @@ + @@ -418,7 +419,6 @@ - @@ -444,7 +444,7 @@ tree,form,calendar,gantt,graph - {"search_default_project_id":context.get('project_id',False)} + {"search_default_project_id":project_id,'search_default_user_id':uid} @@ -607,12 +607,10 @@ - - @@ -631,7 +629,7 @@ form tree,form - {"search_default_project_id":context.get('project_id',False), "search_default_my_msg":1} + {"search_default_project_id":project_id, "search_default_my_msg":1, "search_default_user_id":uid} diff --git a/addons/project/report/project_report_view.xml b/addons/project/report/project_report_view.xml index a4a072849b9..1da8311f363 100644 --- a/addons/project/report/project_report_view.xml +++ b/addons/project/report/project_report_view.xml @@ -79,20 +79,12 @@ help = "Pending tasks"/> - - form tree,graph - {'search_default_month':1,'search_default_User':1,'group_by_no_leaf':1,'group_by':[]} + {'search_default_month':1,'search_default_User':1,'search_default_project_id':project_id,'search_default_user_id':uid,'group_by_no_leaf':1,'group_by':[]}