From b7a4dffa63a44a160ca05d1fc7f412dbb47cab90 Mon Sep 17 00:00:00 2001 From: Fabian Semal Date: Tue, 28 Oct 2008 17:23:02 +0100 Subject: [PATCH] Added auto category assigned at create from category tree view bzr revid: fabian@tinyerp.com-20081028162302-i5z6cc06zhf08x3z --- addons/product/product.py | 6 ++++++ addons/project/project.py | 6 ++++++ addons/project/project_view.xml | 1 + 3 files changed, 13 insertions(+) diff --git a/addons/product/product.py b/addons/product/product.py index 4c205bb29d5..1827fa72a01 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -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): diff --git a/addons/project/project.py b/addons/project/project.py index 2fad4bc5379..43319ace95a 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -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" diff --git a/addons/project/project_view.xml b/addons/project/project_view.xml index aae0ba550be..aae9a5bb847 100644 --- a/addons/project/project_view.xml +++ b/addons/project/project_view.xml @@ -439,6 +439,7 @@ form tree,form,calendar,graph [('project_id', 'child_of', [active_id])] + {'project_id':active_id}