summaryrefslogtreecommitdiff
path: root/addons/analytic_user_function
diff options
context:
space:
mode:
authorAjay Chauhan (OpenERP) <cha@tinyerp.com>2012-10-29 11:04:40 +0530
committerAjay Chauhan (OpenERP) <cha@tinyerp.com>2012-10-29 11:04:40 +0530
commit08843b9f2b1e8e5f4823787e813ff877a4f9bd41 (patch)
treeaed5369aff32161bd045e9362b8f8d34918398bd /addons/analytic_user_function
parent435a1bd673e724dd18acfb5af8d32cc5aac6fcd0 (diff)
parentbcf7db1651bef48b0495d6234c18dcc4dee506ce (diff)
[MERGE] merge with lp:openobject-addons
bzr revid: cha@tinyerp.com-20121029053440-e0xabu6cczx0o5dt
Diffstat (limited to 'addons/analytic_user_function')
-rw-r--r--addons/analytic_user_function/analytic_user_function.py55
-rw-r--r--addons/analytic_user_function/analytic_user_function_view.xml41
2 files changed, 62 insertions, 34 deletions
diff --git a/addons/analytic_user_function/analytic_user_function.py b/addons/analytic_user_function/analytic_user_function.py
index 9233845f7eb..c2a7ae8f05a 100644
--- a/addons/analytic_user_function/analytic_user_function.py
+++ b/addons/analytic_user_function/analytic_user_function.py
@@ -21,39 +21,51 @@
from osv import fields,osv
from tools.translate import _
+import decimal_precision as dp
class analytic_user_funct_grid(osv.osv):
-
_name="analytic.user.funct.grid"
- _description= "Relation table between users and products on a analytic account"
+ _description= "Price per User"
_columns={
'user_id': fields.many2one("res.users", "User", required=True,),
- 'product_id': fields.many2one("product.product", "Product", required=True,),
+ 'product_id': fields.many2one("product.product", "Service", required=True,),
'account_id': fields.many2one("account.analytic.account", "Analytic Account", required=True,),
- }
-
-analytic_user_funct_grid()
+ 'uom_id': fields.related("product_id", "uom_id", relation="product.uom", string="Unit of Measure", type="many2one", readonly=True),
+ 'price': fields.float('Price', digits_compute=dp.get_precision('Product Price'), help="Price per hour for this user.", required=True),
+ }
+ def onchange_user_product_id(self, cr, uid, ids, user_id, product_id, context=None):
+ if not user_id:
+ return {}
+ emp_obj = self.pool.get('hr.employee')
+ emp_id = emp_obj.search(cr, uid, [('user_id', '=', user_id)], context=context)
+ if not emp_id:
+ return {}
+
+ value = {}
+ emp = emp_obj.browse(cr, uid, emp_id[0], context=context)
+ if emp.product_id and not product_id:
+ value['product_id'] = emp.product_id.id
+ prod = emp.product_id
+ if product_id:
+ prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
+ if prod:
+ value['price'] = prod.list_price
+ value['uom_id'] = prod.uom_id.id
+ return {'value': value}
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:
@@ -64,7 +76,6 @@ class hr_analytic_timesheet(osv.osv):
else:
return False
-
def on_change_account_id(self, cr, uid, ids, account_id, user_id=False, unit_amount=0):
res = {}
if not (account_id):
@@ -106,12 +117,6 @@ class hr_analytic_timesheet(osv.osv):
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:
@@ -141,7 +146,11 @@ class hr_analytic_timesheet(osv.osv):
res ['value']['general_account_id']= a
return res
-hr_analytic_timesheet()
-
+class account_analytic_line(osv.osv):
+ _inherit = "account.analytic.line"
+ def _get_invoice_price(self, cr, uid, account, product_id, user_id, qty, context = {}):
+ for grid in account.user_product_ids:
+ if grid.user_id.id==user_id:
+ return grid.price
+ return super(account_analytic_line, self)._get_invoice_price(cr, uid, account, product_id, user_id, qty, context)
-# 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
index 6fa141f480d..490b3026d7f 100644
--- a/addons/analytic_user_function/analytic_user_function_view.xml
+++ b/addons/analytic_user_function/analytic_user_function_view.xml
@@ -7,9 +7,11 @@
<field name="name">analytic_user_funct_grid.tree</field>
<field name="model">analytic.user.funct.grid</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 string="Invoicing Data" editable="bottom">
+ <field name="user_id" on_change="onchange_user_product_id(user_id, product_id)"/>
+ <field name="product_id" on_change="onchange_user_product_id(user_id, product_id)" domain="[('type','=','service')]"/>
+ <field name="price"/>
+ <field name="uom_id"/>
</tree>
</field>
</record>
@@ -18,9 +20,13 @@
<field name="name">analytic_user_funct_grid.form</field>
<field name="model">analytic.user.funct.grid</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 string="Invoicing Data">
+ <group>
+ <field name="user_id" on_change="onchange_user_product_id(user_id, product_id)"/>
+ <field name="product_id" domain="[('type','=','service')]" on_change="onchange_user_product_id(user_id, product_id)"/>
+ <field name="price"/>
+ <field name="uom_id"/>
+ </group>
</form>
</field>
</record>
@@ -29,13 +35,26 @@
<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 eval="60" name="priority"/>
<field name="inherit_id" ref="analytic.view_account_analytic_account_form"/>
<field name="arch" type="xml">
- <xpath expr="//notebook/page" position="after">
- <page string="Users/Products Rel.">
- <field name="user_product_ids" colspan="4" nolabel="1"/>
- </page>
- </xpath>
+ <separator name="description" position="before">
+ <div name="user_function_price" attrs="{'invisible': [('invoice_on_timesheets','=',False)]}">
+ <separator string="Invoice Price Rate per User"/>
+ <p class="oe_grey oe_edit_only">
+ Define a specific service (e.g. Senior Consultant)
+ and price for some users to use these data instead
+ of the default values when invoicing the customer.
+ </p>
+ <p class="oe_grey oe_edit_only">
+ OpenERP will recursively search on parent accounts
+ to check if specific conditions are defined for a
+ specific user. This allows to set invoicing
+ conditions for a group of contracts.
+ </p>
+ <field name="user_product_ids"/>
+ </div>
+ </separator>
</field>
</record>