[FIX] Timesheets Modules : Issues could appear due to the change of method signature in account.analytic.line.on_change_account_id(). To prevent such issues without building a bridge module, this method always takes the right number of arguments, even if analytic_user_function is not installed
This commit is contained in:
@@ -53,9 +53,9 @@ class account_analytic_line(osv.osv):
|
||||
|
||||
# Look in account, if no value for the user => look in parent until there is no more parent to look
|
||||
# Take the first found... if nothing found => return False
|
||||
def _get_related_user_account_recursiv(self, cr, uid, user_id, account_id, context):
|
||||
user_function_id = self.pool.get('analytic.user.funct.grid').search(cr, uid, [('user_id', '=', user_id), ('account_id', '=', account_id)])
|
||||
account = self.pool['account.analytic.account'].browse(cr, uid, account_id)
|
||||
def _get_related_user_account_recursiv(self, cr, uid, user_id, account_id, context=None):
|
||||
user_function_id = self.pool.get('analytic.user.funct.grid').search(cr, uid, [('user_id', '=', user_id), ('account_id', '=', account_id)], context=context)
|
||||
account = self.pool['account.analytic.account'].browse(cr, uid, account_id, context=context)
|
||||
if user_function_id:
|
||||
return user_function_id
|
||||
elif account.parent_id:
|
||||
@@ -68,16 +68,16 @@ class account_analytic_line(osv.osv):
|
||||
if not (account_id):
|
||||
return res
|
||||
if not (user_id):
|
||||
return super(account_analytic_line, self).on_change_account_id(cr, uid, ids, account_id, user_id, is_timesheet, context)
|
||||
return super(account_analytic_line, self).on_change_account_id(cr, uid, ids, account_id, user_id, unit_amount, is_timesheet, context)
|
||||
|
||||
# get the browse record related to user_id and account_id
|
||||
user_function_id = self._get_related_user_account_recursiv(cr, uid, user_id, account_id, context)
|
||||
if not user_function_id:
|
||||
# if there isn't any record for this user_id and account_id
|
||||
return super(account_analytic_line, self).on_change_account_id(cr, uid, ids, account_id, user_id, is_timesheet, context)
|
||||
return super(account_analytic_line, self).on_change_account_id(cr, uid, ids, account_id, user_id, unit_amount, is_timesheet, context)
|
||||
else:
|
||||
# get the old values from super and add the value from the new relation analytic_user_funct_grid
|
||||
res['value'] = super(account_analytic_line, self).on_change_account_id(cr, uid, ids, account_id, user_id, is_timesheet, context)['value']
|
||||
res['value'] = super(account_analytic_line, self).on_change_account_id(cr, uid, ids, account_id, user_id, unit_amount, is_timesheet, context)['value']
|
||||
res['value'].update(self._get_values_based_on_user_function(cr, uid, ids, user_function_id, unit_amount, context=context))
|
||||
return res
|
||||
|
||||
|
||||
@@ -58,64 +58,11 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- hr_timesheet_sheet.sheet inherited view -->
|
||||
<record model="ir.ui.view" id="hr_timesheet_sheet_form_inherit">
|
||||
<field name="name">hr.timesheet.sheet.form.tree</field>
|
||||
<field name="model">hr_timesheet_sheet.sheet</field>
|
||||
<field name="priority" eval="18"/>
|
||||
<field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='timesheet_ids']/tree/field[@name='account_id']" position="attributes">
|
||||
<attribute name="on_change">on_change_account_id(account_id, user_id, unit_amount, is_timesheet, context)</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- hr_timesheet_sheet.sheet inherited view -->
|
||||
<record model="ir.ui.view" id="hr_timesheet_sheet_form_inherit1">
|
||||
<field name="name">hr.timesheet.sheet.form.form</field>
|
||||
<field name="model">hr_timesheet_sheet.sheet</field>
|
||||
<field name="priority" eval="19"/>
|
||||
<field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='timesheet_ids']/form/field[@name='account_id']" position="attributes">
|
||||
<attribute name="on_change">on_change_account_id(account_id, user_id, unit_amount, is_timesheet, context)</attribute>
|
||||
<attribute name="context">{'default_invoice_on_timesheets': 1}</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- hr.analytic.timesheet inherited views -->
|
||||
<record model="ir.ui.view" id="hr_timesheet_line_form_inherit">
|
||||
<field name="name">account.analytic.line.form</field>
|
||||
<field name="model">account.analytic.line</field>
|
||||
<field name="inherit_id" ref="hr_timesheet_invoice.hr_timesheet_line_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='account_id']" position="attributes">
|
||||
<attribute name="on_change">on_change_account_id(account_id, user_id, unit_amount, is_timesheet, context)</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="hr_timesheet_line_form_inherit_2">
|
||||
<field name="name">account.analytic.line.form</field>
|
||||
<field name="model">account.analytic.line</field>
|
||||
<field name="inherit_id" ref="hr_timesheet_invoice.hr_timesheet_line_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='user_id']" position="replace">
|
||||
<field name="user_id" required="1" on_change="on_change_user_id(user_id, unit_amount, account_id, is_timesheet, context)"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="hr_timesheet_line_tree_inherit">
|
||||
<field name="name">account.analytic.line.tree</field>
|
||||
<field name="model">account.analytic.line</field>
|
||||
<field name="inherit_id" ref="hr_timesheet_invoice.hr_timesheet_line_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="/tree/field[@name='account_id']" position="attributes">
|
||||
<attribute name="on_change">on_change_account_id(account_id, user_id, unit_amount, is_timesheet, context)</attribute>
|
||||
</xpath>
|
||||
<xpath expr="/tree/field[@name='user_id']" position="replace">
|
||||
<field name="user_id" required="1" on_change="on_change_user_id(user_id, unit_amount, account_id, is_timesheet, context)" context="{'default_groups_ref': ['base.group_user']}"/>
|
||||
</xpath>
|
||||
|
||||
@@ -288,7 +288,7 @@ class account_analytic_line(osv.osv):
|
||||
invoice_obj.compute_taxes(cr, uid, [last_invoice], context)
|
||||
return invoices
|
||||
|
||||
def on_change_account_id(self, cr, uid, ids, account_id, user_id=False, is_timesheet=False, context=None):
|
||||
def on_change_account_id(self, cr, uid, ids, account_id, user_id=False, unit_amount=0, is_timesheet=False, context=None):
|
||||
res = {'value': {}}
|
||||
if is_timesheet and account_id:
|
||||
acc = self.pool.get('account.analytic.account').browse(cr, uid, account_id, context=context)
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
</xpath>
|
||||
<field name="account_id" position="attributes">
|
||||
<attribute name="domain">[('type','in',['normal','contract']),('state', '!=', 'close'),('invoice_on_timesheets','=',1)]</attribute>
|
||||
<attribute name="on_change">on_change_account_id(account_id, user_id, is_timesheet, context)</attribute>
|
||||
<attribute name="on_change">on_change_account_id(account_id, user_id, unit_amount, is_timesheet, context)</attribute>
|
||||
<attribute name="context">{'default_invoice_on_timesheets': 1}</attribute>
|
||||
</field>
|
||||
</field>
|
||||
@@ -56,7 +56,7 @@
|
||||
</field>
|
||||
<field name="account_id" position="attributes">
|
||||
<attribute name="domain">[('type','in',['normal','contract']),('state', '!=', 'close'),('invoice_on_timesheets','=',1)]</attribute>
|
||||
<attribute name="on_change">on_change_account_id(account_id, user_id, is_timesheet, context)</attribute>
|
||||
<attribute name="on_change">on_change_account_id(account_id, user_id, unit_amount, is_timesheet, context)</attribute>
|
||||
<attribute name="context">{'default_invoice_on_timesheets': 1}</attribute>
|
||||
</field>
|
||||
</field>
|
||||
|
||||
@@ -350,7 +350,7 @@ class account_analytic_line(osv.osv):
|
||||
return True
|
||||
|
||||
def multi_on_change_account_id(self, cr, uid, ids, account_ids, context=None):
|
||||
return dict([(account_id, self.on_change_account_id(cr, uid, ids, account_id, user_id=context.get('user_id', uid), is_timesheet=True, context=context)) for account_id in account_ids])
|
||||
return dict([(account_id, self.on_change_account_id(cr, uid, ids, account_id, user_id=context.get('user_id', uid), unit_amount=0, is_timesheet=True, context=context)) for account_id in account_ids])
|
||||
|
||||
|
||||
class hr_attendance(osv.osv):
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
<field context="{'employee_id': employee_id, 'user_id':user_id, 'timesheet_date_from': date_from, 'timesheet_date_to': date_to, 'default_is_timesheet' : 1}" name="timesheet_ids" nolabel="1">
|
||||
<tree editable="top" string="Timesheet Activities">
|
||||
<field name="date"/>
|
||||
<field domain="[('type','in',['normal', 'contract']), ('state', '!=', 'close'),('invoice_on_timesheets','=',1)]" name="account_id" on_change="on_change_account_id(account_id, user_id)" options="{'no_open': True, 'no_create': True}" context="{'default_use_timesheets': 1}"/>
|
||||
<field domain="[('type','in',['normal', 'contract']), ('state', '!=', 'close'),('invoice_on_timesheets','=',1)]" name="account_id" on_change="on_change_account_id(account_id, user_id, unit_amount, is_timesheet, context)" options="{'no_open': True, 'no_create': True}" context="{'default_use_timesheets': 1}"/>
|
||||
<field name="name"/>
|
||||
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" widget="float_time" string="Hours" sum="Hours"/>
|
||||
<field name="to_invoice" widget="selection"/>
|
||||
@@ -144,7 +144,7 @@
|
||||
</tree>
|
||||
<form string="Timesheet Activities">
|
||||
<field name="date"/>
|
||||
<field domain="[('type','=','normal'), ('state', '!=', 'close')]" name="account_id" on_change="on_change_account_id(account_id, user_id)"/>
|
||||
<field domain="[('type','=','normal'), ('state', '!=', 'close')]" name="account_id" on_change="on_change_account_id(account_id, user_id, unit_amount, is_timesheet, context)"/>
|
||||
<field name="name"/>
|
||||
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" widget="float_time"/>
|
||||
<field name="to_invoice"/>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<field name="date"/>
|
||||
<field name="user_id" required="1"/>
|
||||
<field name="name"/>
|
||||
<field name="account_id" invisible="0" domain="[('partner_id', '=', parent.partner_id)]" on_change="on_change_account_id(account_id, context)" groups="analytic.group_analytic_accounting"/>
|
||||
<field name="account_id" invisible="0" domain="[('partner_id', '=', parent.partner_id)]" on_change="on_change_account_id(account_id, user_id, is_timesheet, context)" options="{'no_open': True, 'no_create': True}" groups="analytic.group_analytic_accounting"/>
|
||||
<field name="unit_amount" string="Duration" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id, context)" widget="float_time"/>
|
||||
<field name="to_invoice" invisible="1"/>
|
||||
<field name="product_uom_id" invisible="1" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id, context)"/>
|
||||
|
||||
@@ -161,7 +161,7 @@
|
||||
<field name="date"/>
|
||||
<field name="user_id" required="1"/>
|
||||
<field name="name"/>
|
||||
<field name="account_id" on_change="on_change_account_id(account_id, user_id, is_timesheet, context)"/>
|
||||
<field name="account_id" on_change="on_change_account_id(account_id, user_id, unit_amount, is_timesheet, context)"/>
|
||||
<field name="unit_amount" string="Duration" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id, context)" sum="Total time" widget="float_time"/>
|
||||
<field name="to_invoice"/>
|
||||
<field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id, context)" invisible="1"/>
|
||||
|
||||
Reference in New Issue
Block a user