From 121d3c2222f3f2ef872d13557331fd140dd14b10 Mon Sep 17 00:00:00 2001 From: Christophe Chauvet Date: Thu, 17 Dec 2009 22:37:00 +0100 Subject: [PATCH 1/5] [FIX] change size for multi company default from 32 to 256 [IMP] Prepare _company_default_get to support rules on object's field lp bug: https://launchpad.net/bugs/497685 fixed bzr revid: christophe.chauvet@syleam.fr-20091217213700-k1i6fdgojhn0uccs --- bin/addons/base/res/res_company.py | 11 ++++++++--- bin/addons/base/res/res_company_view.xml | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bin/addons/base/res/res_company.py b/bin/addons/base/res/res_company.py index acd1e85a184..70af44da6a4 100644 --- a/bin/addons/base/res/res_company.py +++ b/bin/addons/base/res/res_company.py @@ -36,7 +36,7 @@ class multi_company_default(osv.osv): _columns = { 'sequence': fields.integer('Sequence'), - 'name': fields.char('Name', size=32, required=True, help='Name it to easily find a record'), + 'name': fields.char('Name', size=256, required=True, help='Name it to easily find a record'), 'company_id': fields.many2one('res.company', 'Main Company', required=True, help='Company where the user is connected'), 'company_dest_id': fields.many2one('res.company', 'Default Company', required=True, @@ -45,6 +45,7 @@ class multi_company_default(osv.osv): help='Object affect by this rules'), 'expression': fields.char('Expression', size=32, required=True, help='Expression, must be True to match'), + 'field_id': fields.many2one('ir.model.fields', 'Field', help='Select field property'), } _defaults = { @@ -88,14 +89,18 @@ class res_company(osv.osv): } - def _company_default_get(self, cr, uid, object=False, context=None): + def _company_default_get(self, cr, uid, object=False, field=False, context=None): """ Check if the object for this company have a default value """ if not context: context = {} proxy = self.pool.get('multi_company.default') - ids = proxy.search(cr, uid, [('object_id.model', '=', object)]) + args = [ + ('object_id.model', '=', object), + ('field_id.name','=',field), + ] + ids = proxy.search(cr, uid, args) for rule in proxy.browse(cr, uid, ids, context): user = self.pool.get('res.users').browse(cr, uid, uid) if eval(rule.expression, {'context': context, 'user': user}): diff --git a/bin/addons/base/res/res_company_view.xml b/bin/addons/base/res/res_company_view.xml index cfaab5abd38..34e58b75b6c 100644 --- a/bin/addons/base/res/res_company_view.xml +++ b/bin/addons/base/res/res_company_view.xml @@ -11,6 +11,7 @@ + @@ -30,10 +31,12 @@ - + + + From 981e7408bd583ded90afbdc236e5cd895c1bd89a Mon Sep 17 00:00:00 2001 From: Christophe Chauvet Date: Thu, 17 Dec 2009 22:38:28 +0100 Subject: [PATCH 2/5] [IMP] Extended the field.property to new type field (char, integer, float, date, ...) By default, when there are no multi company default, we keep the compatibility with 5.0 else we match to find the company_id for this fields. bzr revid: christophe.chauvet@syleam.fr-20091217213828-f8edggbqnhzw41h2 --- bin/addons/base/res/ir_property.py | 13 +------- bin/osv/fields.py | 53 +++++++++++++++++------------- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/bin/addons/base/res/ir_property.py b/bin/addons/base/res/ir_property.py index e14e365dce3..b02ba593a02 100644 --- a/bin/addons/base/res/ir_property.py +++ b/bin/addons/base/res/ir_property.py @@ -25,17 +25,6 @@ from osv import osv,fields # Properties # ------------------------------------------------------------------------- -def _models_get2(self, cr, uid, context={}): - obj = self.pool.get('ir.model.fields') - ids = obj.search(cr, uid, [('view_load','=',1)]) - res = [] - done = {} - for o in obj.browse(cr, uid, ids, context=context): - if o.relation not in done: - res.append( [o.relation, o.relation]) - done[o.relation] = True - return res - def _models_get(self, cr, uid, context={}): obj = self.pool.get('ir.model.fields') ids = obj.search(cr, uid, [('view_load','=',1)]) @@ -51,7 +40,7 @@ class ir_property(osv.osv): _name = 'ir.property' _columns = { 'name': fields.char('Name', size=128), - 'value': fields.reference('Value', selection=_models_get2, size=128), + 'value': fields.char('Value', size=128), 'res_id': fields.reference('Resource', selection=_models_get, size=128), 'company_id': fields.many2one('res.company', 'Company'), 'fields_id': fields.many2one('ir.model.fields', 'Fields', ondelete='cascade', required=True) diff --git a/bin/osv/fields.py b/bin/osv/fields.py index 09d51e6bd82..50b7a233b3b 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -856,9 +856,12 @@ class property(function): if nid: default_val = property.browse(cr, uid, nid[0], context).value - company_id = obj.pool.get('res.users').company_get(cr, uid, uid) + company_id = obj.pool.get('res.company')._company_default_get(cr, uid, obj._name, prop, context=context) res = False - newval = (id_val and obj_dest+','+str(id_val)) or False + if val[0]: + newval = (id_val and obj_dest+','+str(id_val)) or False + else: + newval = id_val or False if (newval != default_val) and newval: propdef = obj.pool.get('ir.model.fields').browse(cr, uid, definition_id, context=context) @@ -892,27 +895,33 @@ class property(function): for id in ids: res[id] = default_val for prop in property.browse(cr, uid, nids): - res[int(prop.res_id.split(',')[1])] = (prop.value and \ - int(prop.value.split(',')[1])) or False - - obj = obj.pool.get(self._obj) - - to_check = res.values() - if default_val and default_val not in to_check: - to_check += [default_val] - existing_ids = obj.search(cr, uid, [('id', 'in', to_check)]) - - for id, res_id in res.items(): - if res_id not in existing_ids: - cr.execute('DELETE FROM ir_property WHERE value=%s', ((obj._name+','+str(res_id)),)) - res[id] = default_val - - names = dict(obj.name_get(cr, uid, existing_ids, context)) - for r in res.keys(): - if res[r] and res[r] in names: - res[r] = (res[r], names[res[r]]) + if prop.value.find(',') >= 0: + res[int(prop.res_id.split(',')[1])] = (prop.value and \ + int(prop.value.split(',')[1])) or False else: - res[r] = False + res[int(prop.res_id.split(',')[1])] = prop.value or '' + + try: + obj = obj.pool.get(self._obj) + + to_check = res.values() + if default_val and default_val not in to_check: + to_check += [default_val] + existing_ids = obj.search(cr, uid, [('id', 'in', to_check)]) + + for id, res_id in res.items(): + if res_id not in existing_ids: + cr.execute('DELETE FROM ir_property WHERE value=%s', ((obj._name+','+str(res_id)),)) + res[id] = default_val + + names = dict(obj.name_get(cr, uid, existing_ids, context)) + for r in res.keys(): + if res[r] and res[r] in names: + res[r] = (res[r], names[res[r]]) + else: + res[r] = False + except: + pass return res def _field_get(self, cr, uid, model_name, prop): From 0700f9286fa400e36f16a3503d0efe1048b13de0 Mon Sep 17 00:00:00 2001 From: Christophe Chauvet Date: Fri, 18 Dec 2009 09:41:26 +0100 Subject: [PATCH 3/5] [IMP] Update the template for translation bzr revid: christophe.chauvet@syleam.fr-20091218084126-fwa0yt6cg0x160qj --- bin/addons/base/i18n/base.pot | 168 +++++++++++++++++----------------- 1 file changed, 86 insertions(+), 82 deletions(-) diff --git a/bin/addons/base/i18n/base.pot b/bin/addons/base/i18n/base.pot index ad77b86e94f..79662043441 100644 --- a/bin/addons/base/i18n/base.pot +++ b/bin/addons/base/i18n/base.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: OpenERP Server 5.0.6\n" "Report-Msgid-Bugs-To: support@openerp.com\n" -"POT-Creation-Date: 2009-12-09 10:13:57+0000\n" -"PO-Revision-Date: 2009-12-10 07:54+0000\n" +"POT-Creation-Date: 2009-12-18 08:39:22+0000\n" +"PO-Revision-Date: 2009-12-18 08:39:22+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -189,11 +189,6 @@ msgstr "" msgid "Number of Modules" msgstr "" -#. module: base -#: help:multi_company.default,company_dest_id:0 -msgid "Company to store the current record" -msgstr "" - #. module: base #: field:res.partner.bank.type.field,size:0 msgid "Max. Size" @@ -718,6 +713,12 @@ msgstr "" msgid "Iran" msgstr "" +#. module: base +#: model:ir.actions.act_window,name:base.res_request-act +#: model:ir.ui.menu,name:base.menu_res_request_act +msgid "My Requests" +msgstr "" + #. module: base #: field:ir.sequence,name:0 #: field:ir.sequence.type,name:0 @@ -1077,6 +1078,11 @@ msgstr "" msgid "Fixed Width" msgstr "" +#. module: base +#: model:res.company,overdue_msg:base.main_company +msgid "Would your payment have been carried out after this mail was sent, please consider the present one as void. Do not hesitate to contact our accounting department at (+32).81.81.37.00." +msgstr "" + #. module: base #: selection:ir.ui.menu,icon:0 msgid "terp-calendar" @@ -1112,13 +1118,8 @@ msgid "7. %H:%M:%S ==> 18:25:20" msgstr "" #. module: base -#: model:ir.actions.act_window,name:base.action_partner_form -#: model:ir.ui.menu,name:base.menu_base_partner -#: model:ir.ui.menu,name:base.menu_partner_form -#: view:res.partner:0 -#: view:res.partner.category:0 -#: field:res.partner.category,partner_ids:0 -msgid "Partners" +#: help:res.users,company_id:0 +msgid "The company this user is currently working on." msgstr "" #. module: base @@ -1317,6 +1318,11 @@ msgstr "" msgid "Groups" msgstr "" +#. module: base +#: constraint:res.users:0 +msgid "This user can not connect using this company !" +msgstr "" + #. module: base #: model:res.country,name:base.bz msgid "Belize" @@ -1529,6 +1535,12 @@ msgstr "" msgid "Field Mappings" msgstr "" +#. module: base +#: model:ir.actions.act_window,name:base.res_request-closed +#: model:ir.ui.menu,name:base.next_id_12_close +msgid "My Closed Requests" +msgstr "" + #. module: base #: model:ir.ui.menu,name:base.menu_custom msgid "Customization" @@ -1585,11 +1597,6 @@ msgstr "" msgid "Iteration Actions" msgstr "" -#. module: base -#: help:multi_company.default,company_id:0 -msgid "Company where the user is connected" -msgstr "" - #. module: base #: field:maintenance.contract,date_stop:0 msgid "Ending Date" @@ -1792,11 +1799,6 @@ msgstr "" msgid "Dependencies" msgstr "" -#. module: base -#: field:multi_company.default,company_id:0 -msgid "Main Company" -msgstr "" - #. module: base #: field:ir.report.custom.fields,bgcolor:0 msgid "Background Color" @@ -1912,6 +1914,12 @@ msgstr "" msgid "Module" msgstr "" +#. module: base +#: model:ir.actions.act_window,name:base.action_res_bank_form +#: model:ir.ui.menu,name:base.menu_action_res_bank_form +msgid "Bank List" +msgstr "" + #. module: base #: field:ir.attachment,description:0 #: field:ir.module.module,description:0 @@ -2275,11 +2283,6 @@ msgstr "" msgid "6. %d, %m ==> 05, 12" msgstr "" -#. module: base -#: help:multi_company.default,expression:0 -msgid "Expression, must be True to match" -msgstr "" - #. module: base #: help:res.partner,customer:0 msgid "Check this box if the partner is a customer." @@ -2384,11 +2387,6 @@ msgstr "" msgid "Summary" msgstr "" -#. module: base -#: field:multi_company.default,expression:0 -msgid "Expression" -msgstr "" - #. module: base #: help:ir.actions.server,subject:0 msgid "Specify the subject. You can use fields from the object, e.g. `Hello [[ object.partner_id.name ]]`" @@ -2974,6 +2972,7 @@ msgstr "" #. module: base #: field:ir.rule,field_id:0 #: selection:ir.translation,type:0 +#: field:multi_company.default,field_id:0 msgid "Field" msgstr "" @@ -3039,7 +3038,6 @@ msgstr "" #: field:ir.rule.group,name:0 #: field:ir.values,name:0 #: field:maintenance.contract.module,name:0 -#: field:multi_company.default,name:0 #: field:res.bank,name:0 #: field:res.config.view,name:0 #: field:res.lang,name:0 @@ -3560,8 +3558,6 @@ msgid "Signal (button Name)" msgstr "" #. module: base -#: model:ir.actions.act_window,name:base.action_res_bank_form -#: model:ir.ui.menu,name:base.menu_action_res_bank_form #: view:res.bank:0 #: field:res.partner,bank_ids:0 msgid "Banks" @@ -3820,6 +3816,7 @@ msgid "On Multiple Doc." msgstr "" #. module: base +#: model:ir.ui.menu,name:base.menu_base_config_contact #: field:res.partner,address:0 #: view:res.partner.address:0 msgid "Contacts" @@ -3830,11 +3827,6 @@ msgstr "" msgid "Faroe Islands" msgstr "" -#. module: base -#: help:multi_company.default,object_id:0 -msgid "Object affect by this rules" -msgstr "" - #. module: base #: model:ir.actions.wizard,name:base.wizard_upgrade #: model:ir.ui.menu,name:base.menu_wizard_upgrade @@ -4218,11 +4210,6 @@ msgstr "" msgid "French (CH) / Français (CH)" msgstr "" -#. module: base -#: model:ir.model,name:base.model_res_company -msgid "List of Company" -msgstr "" - #. module: base #: selection:ir.ui.menu,icon:0 msgid "STOCK_NEW" @@ -4333,6 +4320,11 @@ msgstr "" msgid "res.partner.event" msgstr "" +#. module: base +#: field:res.company,user_ids:0 +msgid "Accepted Users" +msgstr "" + #. module: base #: selection:ir.ui.menu,icon:0 msgid "STOCK_UNDERLINE" @@ -4450,13 +4442,6 @@ msgstr "" msgid "iCal id" msgstr "" -#. module: base -#: model:ir.actions.act_window,name:base.action_partner_function_form -#: model:ir.ui.menu,name:base.menu_partner_function_form -#: view:res.partner.function:0 -msgid "Partner Functions" -msgstr "" - #. module: base #: wizard_view:res.partner.sms_send,init:0 msgid "Bulk SMS send" @@ -4589,11 +4574,6 @@ msgstr "" msgid "Full" msgstr "" -#. module: base -#: field:multi_company.default,company_dest_id:0 -msgid "Default Company" -msgstr "" - #. module: base #: model:res.country,name:base.as msgid "American Samoa" @@ -4831,6 +4811,7 @@ msgstr "" #. module: base #: model:ir.actions.act_window,name:base.action_res_company_form #: model:ir.ui.menu,name:base.menu_action_res_company_form +#: model:ir.ui.menu,name:base.menu_res_company_global #: view:res.company:0 msgid "Companies" msgstr "" @@ -5256,9 +5237,10 @@ msgid "Active Partner Events" msgstr "" #. module: base -#: model:ir.actions.act_window,name:base.action_rule -#: model:ir.ui.menu,name:base.menu_action_rule -msgid "Record Rules" +#: model:ir.actions.act_window,name:base.action_partner_function_form +#: model:ir.ui.menu,name:base.menu_partner_function_form +#: view:res.partner.function:0 +msgid "Contact Functions" msgstr "" #. module: base @@ -5551,8 +5533,6 @@ msgid "Martinique (French)" msgstr "" #. module: base -#: model:ir.actions.act_window,name:base.res_request-act -#: model:ir.ui.menu,name:base.menu_res_request_act #: model:ir.ui.menu,name:base.next_id_12 #: view:res.request:0 msgid "Requests" @@ -5809,6 +5789,11 @@ msgstr "" msgid "Rounding factor" msgstr "" +#. module: base +#: model:ir.model,name:base.model_res_company +msgid "res.company" +msgstr "" + #. module: base #: wizard_view:module.upgrade,end:0 #: wizard_view:module.upgrade,start:0 @@ -5889,6 +5874,11 @@ msgstr "" msgid "Hour 00->24: %(h24)s" msgstr "" +#. module: base +#: help:multi_company.default,field_id:0 +msgid "Select field property" +msgstr "" + #. module: base #: field:res.request.history,date_sent:0 msgid "Date sent" @@ -5908,7 +5898,6 @@ msgstr "" #: view:ir.sequence:0 #: field:ir.ui.menu,sequence:0 #: field:ir.ui.view_sc,sequence:0 -#: field:multi_company.default,sequence:0 #: field:res.partner.bank,sequence:0 #: field:wizard.ir.model.menu.create.line,sequence:0 msgid "Sequence" @@ -5973,6 +5962,11 @@ msgstr "" msgid "Parent" msgstr "" +#. module: base +#: view:multi_company.default:0 +msgid "Returning" +msgstr "" + #. module: base #: field:ir.actions.act_window,res_model:0 #: field:ir.actions.report.custom,model:0 @@ -5991,7 +5985,6 @@ msgstr "" #: selection:ir.translation,type:0 #: field:ir.ui.view,model:0 #: field:ir.values,model_id:0 -#: field:multi_company.default,object_id:0 #: field:res.request.link,object:0 #: field:wizard.ir.model.menu.create,model_id:0 #: field:workflow.triggers,model:0 @@ -6688,6 +6681,17 @@ msgstr "" msgid "Landscape" msgstr "" +#. module: base +#: model:ir.actions.act_window,name:base.action_partner_form +#: model:ir.ui.menu,name:base.menu_base_config_partner +#: model:ir.ui.menu,name:base.menu_base_partner +#: model:ir.ui.menu,name:base.menu_partner_form +#: view:res.partner:0 +#: view:res.partner.category:0 +#: field:res.partner.category,partner_ids:0 +msgid "Partners" +msgstr "" + #. module: base #: model:ir.ui.menu,name:base.menu_administration msgid "Administration" @@ -6902,11 +6906,6 @@ msgstr "" msgid "Second field should be figures" msgstr "" -#. module: base -#: help:multi_company.default,name:0 -msgid "Name it to easily find a record" -msgstr "" - #. module: base #: model:ir.actions.act_window,name:base.action_model_grid_security #: model:ir.ui.menu,name:base.menu_ir_access_grid @@ -7029,11 +7028,6 @@ msgstr "" msgid "Bank Accounts" msgstr "" -#. module: base -#: model:ir.model,name:base.model_multi_company_default -msgid "Default multi company" -msgstr "" - #. module: base #: view:res.request:0 msgid "Send" @@ -7122,12 +7116,6 @@ msgstr "" msgid "https://translations.launchpad.net/openobject" msgstr "" -#. module: base -#: model:ir.actions.act_window,name:base.action_partner_title -#: model:ir.ui.menu,name:base.menu_partner_title -msgid "Titles" -msgstr "" - #. module: base #: field:ir.actions.todo,start_date:0 msgid "Start Date" @@ -7199,6 +7187,11 @@ msgstr "" msgid "Delete Permission" msgstr "" +#. module: base +#: model:ir.model,name:base.model_multi_company_default +msgid "multi_company.default" +msgstr "" + #. module: base #: selection:workflow.activity,join_mode:0 #: selection:workflow.activity,split_mode:0 @@ -7455,6 +7448,11 @@ msgstr "" msgid "Rwanda" msgstr "" +#. module: base +#: constraint:res.partner:0 +msgid "The VAT doesn't seem to be correct." +msgstr "" + #. module: base #: selection:ir.report.custom.fields,operation:0 msgid "Calculate Sum" @@ -7592,6 +7590,12 @@ msgstr "" msgid "ir.actions.server" msgstr "" +#. module: base +#: model:ir.actions.act_window,name:base.action_rule +#: model:ir.ui.menu,name:base.menu_action_rule +msgid "Record Rules" +msgstr "" + #. module: base #: view:ir.actions.report.custom:0 msgid "Report custom" From 1e4d933cbc36503a6caec7119a512201024d10c3 Mon Sep 17 00:00:00 2001 From: Christophe Chauvet Date: Fri, 18 Dec 2009 18:09:27 +0100 Subject: [PATCH 4/5] [FIX] Regression on global object bzr revid: christophe.chauvet@syleam.fr-20091218170927-5m05rgb8rp09o21s --- bin/addons/base/res/res_company.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/addons/base/res/res_company.py b/bin/addons/base/res/res_company.py index 70af44da6a4..b514e40b9fe 100644 --- a/bin/addons/base/res/res_company.py +++ b/bin/addons/base/res/res_company.py @@ -98,8 +98,11 @@ class res_company(osv.osv): proxy = self.pool.get('multi_company.default') args = [ ('object_id.model', '=', object), - ('field_id.name','=',field), ] + if field: + args.append(('field_id.name','=',field)) + else: + args.append(('field_id','=',False)) ids = proxy.search(cr, uid, args) for rule in proxy.browse(cr, uid, ids, context): user = self.pool.get('res.users').browse(cr, uid, uid) From 18f41e53a78d420de8a7af1890633b9b96ddf23b Mon Sep 17 00:00:00 2001 From: Christophe Chauvet Date: Tue, 22 Dec 2009 12:43:50 +0100 Subject: [PATCH 5/5] [IMP] Change try/except by if to test when field is not a relation bzr revid: christophe.chauvet@syleam.fr-20091222114350-x94m7ts7uwcadsnc --- bin/osv/fields.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bin/osv/fields.py b/bin/osv/fields.py index 50b7a233b3b..2cbba931a47 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -901,27 +901,25 @@ class property(function): else: res[int(prop.res_id.split(',')[1])] = prop.value or '' - try: + if self._obj: obj = obj.pool.get(self._obj) - + to_check = res.values() if default_val and default_val not in to_check: to_check += [default_val] existing_ids = obj.search(cr, uid, [('id', 'in', to_check)]) - + for id, res_id in res.items(): if res_id not in existing_ids: cr.execute('DELETE FROM ir_property WHERE value=%s', ((obj._name+','+str(res_id)),)) res[id] = default_val - + names = dict(obj.name_get(cr, uid, existing_ids, context)) for r in res.keys(): if res[r] and res[r] in names: res[r] = (res[r], names[res[r]]) else: res[r] = False - except: - pass return res def _field_get(self, cr, uid, model_name, prop):