Added auto category assigned at create from category tree view
authorFabian Semal <fabian@tinyerp.com>
Tue, 28 Oct 2008 16:23:02 +0000 (17:23 +0100)
committerFabian Semal <fabian@tinyerp.com>
Tue, 28 Oct 2008 16:23:02 +0000 (17:23 +0100)
bzr revid: fabian@tinyerp.com-20081028162302-i5z6cc06zhf08x3z

addons/product/product.py
addons/project/project.py
addons/project/project_view.xml

index 4c205bb..1827fa7 100644 (file)
@@ -283,6 +283,11 @@ class product_template(osv.osv):
         res = cr.fetchone()
         return res and res[0] or False
 
+    def _default_category(self, cr, uid, context={}):
+        if 'categ_id' in context and context['categ_id']:
+            return context['categ_id']
+        return False
+
     _defaults = {
         'type': lambda *a: 'product',
         'list_price': lambda *a: 1,
@@ -298,6 +303,7 @@ class product_template(osv.osv):
         'uom_po_id': _get_uom_id,
         'uos_coeff' : lambda *a: 1.0,
         'mes_type' : lambda *a: 'fixed',
+        'categ_id' : _default_category,
     }
 
     def _check_uom(self, cursor, user, ids):
index 2fad4bc..43319ac 100644 (file)
@@ -273,6 +273,11 @@ class task(osv.osv):
     def onchange_planned(self, cr, uid, ids, planned, effective):
         return {'value':{'remaining_hours': planned-effective}}
 
+    def _default_project(self, cr, uid, context={}):
+        if 'project_id' in context and context['project_id']:
+            return context['project_id']
+        return False
+
     #_sql_constraints = [
     #    ('remaining_hours', 'CHECK (remaining_hours>=0)', 'Please increase and review remaining hours ! It can not be smaller than 0.'),
     #]
@@ -313,6 +318,7 @@ class task(osv.osv):
         'sequence': lambda *a: 10,
         'active': lambda *a: True,
         'date_start': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
+        'project_id': _default_project,
     }
     _order = "sequence, priority, date_deadline, id"
 
index aae0ba5..aae9a5b 100644 (file)
             <field name="view_type">form</field>
             <field name="view_mode">tree,form,calendar,graph</field>
             <field name="domain">[('project_id', 'child_of', [active_id])]</field>
+            <field name="context">{'project_id':active_id}</field>
         </record>
         <record id="ir_project_task_open" model="ir.values">
             <field eval=" 'tree_but_open'" name="key2"/>