summaryrefslogtreecommitdiff
path: root/addons/analytic_user_function
diff options
context:
space:
mode:
authorSofia <sahibsofia@gmail.com>2008-09-16 17:15:13 +0530
committerSofia <sahibsofia@gmail.com>2008-09-16 17:15:13 +0530
commita268fad012aba95b9d72b9b9fd05854eb9da43e3 (patch)
tree9d18170b1d07b17fd49e5afc40ce1cb43dc3f18b /addons/analytic_user_function
parent05f980e2a68d0d8bdeaeb133848547f0ac525d3c (diff)
The following modules are merged::
addons-extra/product_procurement -> mrp module addons-extra/inventory_merge -> stock addons-extra/product_pricelist_print -> product addons-extra/invoice_payment -> account bzr revid: sahibsofia@gmail.com-20080916114513-7an9yz59hucjmjk8
Diffstat (limited to 'addons/analytic_user_function')
-rw-r--r--addons/analytic_user_function/__init__.py5
-rw-r--r--addons/analytic_user_function/__terp__.py25
-rw-r--r--addons/analytic_user_function/analytic_user_function.py123
-rw-r--r--addons/analytic_user_function/analytic_user_function_view.xml109
4 files changed, 262 insertions, 0 deletions
diff --git a/addons/analytic_user_function/__init__.py b/addons/analytic_user_function/__init__.py
new file mode 100644
index 00000000000..c0f4bdd4e89
--- /dev/null
+++ b/addons/analytic_user_function/__init__.py
@@ -0,0 +1,5 @@
+# -*- encoding: utf-8 -*-
+import analytic_user_function
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
diff --git a/addons/analytic_user_function/__terp__.py b/addons/analytic_user_function/__terp__.py
new file mode 100644
index 00000000000..6208cd43226
--- /dev/null
+++ b/addons/analytic_user_function/__terp__.py
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+{
+ "name" : "Analytic User Function",
+ "version" : "1.0",
+ "depends" : ["hr_timesheet_sheet"],
+ "author" : "Tiny",
+ "description": """
+
+ This module allows you to define what is the defaut function of a specific user on a given account. This is mostly used when a user encode his timesheet: the values are retrieved and the fields are auto-filled... but the possibility to change these values is still available.
+
+ Obviously if no data has been recorded for the current account, the default value is given as usual by the employee data so that this module is perfectly compatible with older configurations.
+
+ """,
+ "website" : "http://tinyerp.com/",
+ "category" : "Generic Modules/Others",
+ "init_xml" : [],
+ "demo_xml" : [],
+ "update_xml" : [
+ "analytic_user_function_view.xml",
+ ],
+ "active": False,
+ "installable": True
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
diff --git a/addons/analytic_user_function/analytic_user_function.py b/addons/analytic_user_function/analytic_user_function.py
new file mode 100644
index 00000000000..0d5e2200265
--- /dev/null
+++ b/addons/analytic_user_function/analytic_user_function.py
@@ -0,0 +1,123 @@
+# -*- encoding: utf-8 -*-
+from osv import fields,osv
+from osv import orm
+
+class analytic_user_funct_grid(osv.osv):
+
+ _name="analytic_user_funct_grid"
+ _description= "Relation table between users and products on a analytic account"
+ _columns={
+ 'user_id': fields.many2one("res.users","User",required=True,),
+ 'product_id': fields.many2one("product.product","Product",required=True,),
+ 'account_id': fields.many2one("account.analytic.account", "Analytic Account",required=True,),
+ }
+
+analytic_user_funct_grid()
+
+
+class account_analytic_account(osv.osv):
+
+ _inherit = "account.analytic.account"
+ _columns = {
+ 'user_product_ids' : fields.one2many('analytic_user_funct_grid', 'account_id', 'Users/Products Rel.'),
+ }
+
+account_analytic_account()
+
+
+class hr_analytic_timesheet(osv.osv):
+
+ _inherit = "hr.analytic.timesheet"
+
+
+ # 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):
+
+ temp=self.pool.get('analytic_user_funct_grid').search(cr, uid, [('user_id', '=', user_id),('account_id', '=', account_id) ])
+ account=self.pool.get('account.analytic.account').browse(cr,uid,account_id)
+ if temp:
+ return temp
+ else:
+ if account.parent_id:
+ return self._get_related_user_account_recursiv(cr,uid,user_id,account.parent_id.id)
+ else:
+ return False
+
+
+ def on_change_account_id(self, cr, uid, ids,user_id, account_id, unit_amount=0):
+ #{'value': {'to_invoice': False, 'amount': (-162.0,), 'product_id': 7, 'general_account_id': (5,)}}
+ res = {}
+ if not (account_id):
+ #avoid a useless call to super
+ return res
+
+ if not (user_id):
+ return super(hr_analytic_timesheet, self).on_change_account_id(cr, uid, ids,account_id)
+
+ #get the browse record related to user_id and account_id
+ temp = self._get_related_user_account_recursiv(cr,uid,user_id,account_id)
+ # temp = self.pool.get('analytic_user_funct_grid').search(cr, uid, [('user_id', '=', user_id),('account_id', '=', account_id) ])
+ if not temp:
+ #if there isn't any record for this user_id and account_id
+ return super(hr_analytic_timesheet, self).on_change_account_id(cr, uid, ids,account_id)
+ else:
+ #get the old values from super and add the value from the new relation analytic_user_funct_grid
+ r = self.pool.get('analytic_user_funct_grid').browse(cr, uid, temp)[0]
+ res.setdefault('value',{})
+ res['value']= super(hr_analytic_timesheet, self).on_change_account_id(cr, uid, ids,account_id)['value']
+ res['value']['product_id'] = r.product_id.id
+ res['value']['product_uom_id'] = r.product_id.product_tmpl_id.uom_id.id
+
+ #the change of product has to impact the amount, uom and general_account_id
+ a = r.product_id.product_tmpl_id.property_account_expense.id
+ if not a:
+ a = r.product_id.categ_id.property_account_expense_categ.id
+ if not a:
+ raise osv.except_osv('Error !',
+ 'There is no expense account define ' \
+ 'for this product: "%s" (id:%d)' % \
+ (r.product_id.name, r.product_id.id,))
+ amount = unit_amount * r.product_id.uom_id._compute_price(cr, uid,
+ r.product_id.uom_id.id, r.product_id.standard_price, False)
+ res ['value']['amount']= - round(amount, 2)
+ res ['value']['general_account_id']= a
+ return res
+
+ def on_change_user_id(self, cr, uid, ids,user_id, account_id, unit_amount=0):
+ res = {}
+ if not (user_id):
+ #avoid a useless call to super
+ return res
+
+ #get the old values from super
+ res = super(hr_analytic_timesheet, self).on_change_user_id(cr, uid, ids,user_id)
+
+ if account_id:
+ #get the browse record related to user_id and account_id
+ # temp = self.pool.get('analytic_user_funct_grid').search(cr, uid, [('user_id', '=', user_id),('account_id', '=', account_id) ])
+ temp = self._get_related_user_account_recursiv(cr,uid,user_id,account_id)
+ if temp:
+ #add the value from the new relation analytic_user_funct_grid
+ r = self.pool.get('analytic_user_funct_grid').browse(cr, uid, temp)[0]
+ res['value']['product_id'] = r.product_id.id
+
+ #the change of product has to impact the amount, uom and general_account_id
+ a = r.product_id.product_tmpl_id.property_account_expense.id
+ if not a:
+ a = r.product_id.categ_id.property_account_expense_categ.id
+ if not a:
+ raise osv.except_osv('Error !',
+ 'There is no expense account define ' \
+ 'for this product: "%s" (id:%d)' % \
+ (r.product_id.name, r.product_id.id,))
+ amount = unit_amount * r.product_id.uom_id._compute_price(cr, uid,
+ r.product_id.uom_id.id, r.product_id.standard_price, False)
+ res ['value']['amount']= - round(amount, 2)
+ res ['value']['general_account_id']= a
+ return res
+
+hr_analytic_timesheet()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
diff --git a/addons/analytic_user_function/analytic_user_function_view.xml b/addons/analytic_user_function/analytic_user_function_view.xml
new file mode 100644
index 00000000000..340d255f182
--- /dev/null
+++ b/addons/analytic_user_function/analytic_user_function_view.xml
@@ -0,0 +1,109 @@
+<?xml version="1.0" ?>
+<openerp>
+ <data>
+
+ <!-- analytic_user_funct_grid views -->
+ <record model="ir.ui.view" id="analytic_user_funct_grid_tree">
+ <field name="name">analytic_user_funct_grid.tree</field>
+ <field name="model">analytic_user_funct_grid</field>
+ <field name="type">tree</field>
+ <field name="arch" type="xml">
+ <tree string="User's Product for this Analytic Account" editable="bottom">
+ <field name="user_id" required="1"/>
+ <field name="product_id" required="1" />
+ </tree>
+ </field>
+ </record>
+
+ <record model="ir.ui.view" id="analytic_user_funct_grid_form">
+ <field name="name">analytic_user_funct_grid.form</field>
+ <field name="model">analytic_user_funct_grid</field>
+ <field name="type">form</field>
+ <field name="arch" type="xml">
+ <form string="User's Product for this Analytic Account">
+ <field name="user_id" required="1"/>
+ <field name="product_id" required="1"/>
+ </form>
+ </field>
+ </record>
+
+ <!-- account.analytic.account inherited view -->
+ <record model="ir.ui.view" id="view_account_analytic_account_form_inherit">
+ <field name="name">account.analytic.account.form</field>
+ <field name="model">account.analytic.account</field>
+ <field name="type">form</field>
+ <field name="inherit_id" ref="account.view_account_analytic_account_form"/>
+ <field name="arch" type="xml">
+ <xpath expr="/form/notebook/page" position="after">
+ <page string="Users/Products Rel.">
+ <field name="user_product_ids" colspan="4" nolabel="1"/>
+ </page>
+ </xpath>
+ </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</field>
+ <field name="model">hr_timesheet_sheet.sheet</field>
+ <field name="type">form</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="/form/notebook/page/field[@name='timesheet_ids']/tree/field[@name='account_id']" position="replace">
+ <field name="account_id" domain="[('type','=','normal'),('state', '&lt;&gt;', 'close')]" on_change="on_change_account_id(user_id, account_id, unit_amount)"/>
+ </xpath>
+ </field>
+ </record>
+
+ <!-- hr.analytic.timesheet inherited views -->
+ <record model="ir.ui.view" id="hr_timesheet_line_form_inherit">
+ <field name="name">hr.analytic.timesheet.form</field>
+ <field name="model">hr.analytic.timesheet</field>
+ <field name="type">form</field>
+ <field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_form"/>
+ <field name="arch" type="xml">
+ <xpath expr="/form/field[@name='account_id']" position="replace">
+ <field name="account_id" domain="[('type','=','normal'),('state', '&lt;&gt;', 'close')]" on_change="on_change_account_id(user_id, account_id, unit_amount)" select="1"/>
+ </xpath>
+ </field>
+ </record>
+
+ <record model="ir.ui.view" id="hr_timesheet_line_form_inherit_2">
+ <field name="name">hr.analytic.timesheet.form</field>
+ <field name="model">hr.analytic.timesheet</field>
+ <field name="type">form</field>
+ <field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_form"/>
+ <field name="arch" type="xml">
+ <xpath expr="/form/field[@name='user_id']" position="replace">
+ <field name="user_id" select="1" required="1" on_change="on_change_user_id(user_id, account_id, unit_amount)"/>
+ </xpath>
+ </field>
+ </record>
+
+ <record model="ir.ui.view" id="hr_timesheet_line_tree_inherit">
+ <field name="name">hr.analytic.timesheet.tree</field>
+ <field name="model">hr.analytic.timesheet</field>
+ <field name="type">tree</field>
+ <field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
+ <field name="arch" type="xml">
+ <xpath expr="/tree/field[@name='account_id']" position="replace">
+ <field name="account_id" domain="[('type','=','normal'),('state', '&lt;&gt;', 'close')]" on_change="on_change_account_id(user_id, account_id, unit_amount)" select="1"/>
+ </xpath>
+ </field>
+ </record>
+
+ <record model="ir.ui.view" id="hr_timesheet_line_tree_inherit_2">
+ <field name="name">hr.analytic.timesheet.tree</field>
+ <field name="model">hr.analytic.timesheet</field>
+ <field name="type">tree</field>
+ <field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
+ <field name="arch" type="xml">
+ <xpath expr="/tree/field[@name='user_id']" position="replace">
+ <field name="user_id" select="1" required="1" on_change="on_change_user_id(user_id, account_id, unit_amount)"/>
+ </xpath>
+ </field>
+ </record>
+
+ </data>
+</openerp>