Ajay Chauhan(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-editable_expense_lines-cha into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-editable_expense_lines-cha/+merge/118897

Hello,

 I have made hr expense line editable & did other changes for that.

Thanks,
Ajay Chauhan
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-editable_expense_lines-cha/+merge/118897
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-editable_expense_lines-cha.
=== modified file 'hr_expense/hr_expense.py'
--- hr_expense/hr_expense.py	2012-08-07 11:31:37 +0000
+++ hr_expense/hr_expense.py	2012-08-09 08:54:21 +0000
@@ -253,15 +253,23 @@
         res = dict(cr.fetchall())
         return res
 
+    def _get_uom_id(self, cr, uid, context=None):
+        try:
+            proxy = self.pool.get('ir.model.data')
+            result = proxy.get_object_reference(cr, uid, 'product', 'product_uom_unit')
+            return result[1]
+        except Exception, ex:
+            return False
+
     _columns = {
         'name': fields.char('Expense Note', size=128, required=True),
         'date_value': fields.date('Date', required=True),
         'expense_id': fields.many2one('hr.expense.expense', 'Expense', ondelete='cascade', select=True),
         'total_amount': fields.function(_amount, string='Total', digits_compute=dp.get_precision('Account')),
         'unit_amount': fields.float('Unit Price', digits_compute=dp.get_precision('Account')),
-        'unit_quantity': fields.float('Quantities' ),
+        'unit_quantity': fields.float('Quantities'),
         'product_id': fields.many2one('product.product', 'Product', domain=[('hr_expense_ok','=',True)]),
-        'uom_id': fields.many2one('product.uom', 'Unit of Measure'),
+        'uom_id': fields.many2one('product.uom', 'Unit of Measure', required=True),
         'description': fields.text('Description'),
         'analytic_account': fields.many2one('account.analytic.account','Analytic account'),
         'ref': fields.char('Reference', size=32),
@@ -270,20 +278,31 @@
     _defaults = {
         'unit_quantity': 1,
         'date_value': lambda *a: time.strftime('%Y-%m-%d'),
+        'uom_id': _get_uom_id,
     }
     _order = "sequence, date_value desc"
 
-    def onchange_product_id(self, cr, uid, ids, product_id, uom_id, employee_id, context=None):
+    def onchange_product_id(self, cr, uid, ids, product_id, context=None):
         res = {}
         if product_id:
             product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
             res['name'] = product.name
             amount_unit = product.price_get('standard_price')[product.id]
             res['unit_amount'] = amount_unit
-            if not uom_id:
-                res['uom_id'] = product.uom_id.id
+            res['uom_id'] = product.uom_id.id
         return {'value': res}
 
+    def onchange_uom(self, cr, uid, ids, product_id, uom_id, context=None):
+        res = {'value':{}}
+        if product_id:
+            product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
+            uom = self.pool.get('product.uom').browse(cr, uid, uom_id, context=context)
+            if uom.category_id.id != product.uom_id.category_id.id:
+                res['warning'] = {'title': _('Warning'), 'message': _('Selected Unit of Measure does not belong to the same category as the product Unit of Measure')}
+                uom_id = product.uom_id.id
+        res['value'].update({'uom_id': uom_id})
+        return res
+
 hr_expense_line()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'hr_expense/hr_expense_view.xml'
--- hr_expense/hr_expense_view.xml	2012-08-04 14:35:56 +0000
+++ hr_expense/hr_expense_view.xml	2012-08-09 08:54:21 +0000
@@ -92,7 +92,7 @@
                                 <form string="Expense Lines" version="7.0">
                                     <group>
                                         <group>
-                                            <field name="product_id" on_change="onchange_product_id(product_id, uom_id, parent.employee_id, context)" context="{'default_hr_expense_ok':1}"/>
+                                            <field name="product_id" on_change="onchange_product_id(product_id, context)" context="{'default_hr_expense_ok':1}"/>
                                             <field name="name"/>
                                             <field name="ref"/>
                                             <field domain="[('type','=','normal')]" name="analytic_account" groups="analytic.group_analytic_accounting"/>
@@ -102,12 +102,24 @@
                                             <label for="unit_quantity"/>
                                             <div>
                                                 <field name="unit_quantity" class="oe_inline"/> 
-                                                <field name="uom_id" on_change="onchange_product_id(product_id, uom_id, parent.employee_id, context)" class="oe_inline"/>
+                                                <field name="uom_id" on_change="onchange_uom(product_id, uom_id, context)" class="oe_inline"/>
                                             </div>
                                             <field name="date_value" />
                                         </group>
                                     </group>
                                 </form>
+                                <tree string="Expense Lines" editable="bottom">
+                                    <field name="sequence" invisible="1"/>
+                                    <field name="product_id" on_change="onchange_product_id(product_id, context)" context="{'default_hr_expense_ok':1}"/>
+                                    <field name="date_value" string="Expense Date"/>
+                                    <field name="name" invisible="1"/>
+                                    <field name="ref"/>
+                                    <field domain="[('type','in',['normal','contract']), ('parent_id','!=',False)]" name="analytic_account" groups="analytic.group_analytic_accounting"/>
+                                    <field name="uom_id" on_change="onchange_uom(product_id, uom_id, context)"/>
+                                    <field name="unit_amount"/>
+                                    <field name="unit_quantity"/>
+                                    <field name="total_amount" sum="Total"/>
+                                </tree>
                             </field>
                             <separator string="Notes"/>
                             <field name="note" placeholder="Free Notes"/>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to