Company ID in properties

Bug #691541 reported by Open Net Sàrl
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Undecided
OpenERP's Framework R&D

Bug Description

We did the following test on OE server 6-trunk:
In multi-company mode:
1. the user is working for company A
1. setup the accounts receivable/Payable for a partner
2. change the company the user is working for (user preferences): the company B for example
3. setup other accounts receivable/Payable for the partner (select for the new company)
4. change your user's company: re-select company A
5. reload your partner: the account properties will keep the ones with the highest Database ID, ignoring the company

We've looked at the source: osv/fields.py, class: property
1. the function: _fnct_write( .... ) seems to use the user's default company
2. in the function: _fnct_read( ... ), this does not look really obvious that the user's company is taken into account

We suspect that the write process is correct, and the read process seems to fail

Best regards

Related branches

Revision history for this message
Open Net Sàrl (openerp-open-net) wrote :

Related to 673433

Revision history for this message
Azazahmed Saiyed (OpenERP) (saz-openerp) wrote :

Hello,

I have tested your scenario at my end with the latest code. Fortunately it is working normally with respect to the company's account. I have installed the "multi_company" module and configured the chart of accounts for different company. Have you checked the issue with the installation of "multi_company" module. If it was then let we know about it.

Thanks.

Changed in openobject-server:
status: New → Incomplete
Revision history for this message
Open Net Sàrl (openerp-open-net) wrote :

Hi,

For our scenario to work correctly, we had to add some lines of code to the class "property", function: _fnct_read( ... )
The difference is only between the comments. Here is the code we use:

        properties = obj.pool.get('ir.property')
        domain = [('fields_id.model', '=', obj._name), ('fields_id.name','in',prop_name)]
        domain += [('res_id','in', [obj._name + ',' + str(oid) for oid in ids])]
        #------------------------------------------------------------------------
        # patch by <email address hidden> => company_id handled while reading properties
        #
        prop = prop_name
        if isinstance(prop_name,list):
            prop = prop_name[0]
        def_id = self._field_get(cr, uid, obj._name, prop)
        company = obj.pool.get('res.company')
        cid = company._company_default_get(cr, uid, obj._name, def_id,
                                               context=context)
        if cid:
            domain += [('company_id','=',cid)]
        #
        #------------------------------------------------------------------------
        nids = properties.search(cr, uid, domain, context=context)
        default_val,replaces = self._get_defaults(obj, cr, uid, prop_name, context)

        res = {}
        for id in ids:
            res[id] = default_val.copy()

        brs = properties.browse(cr, uid, nids, context=context)
        for prop in brs:
            value = properties.get_by_record(cr, uid, prop, context=context)
            res[prop.res_id.id][prop.fields_id.name] = value or False
            if value and (prop.type == 'many2one'):
                replaces.setdefault(value._name, {})
                replaces[value._name][value.id] = True

        for rep in replaces:
            replaces[rep] = dict(obj.pool.get(rep).name_get(cr, uid, replaces[rep].keys(), context=context))

        for prop in prop_name:
            for id in ids:
                if res[id][prop] and hasattr(res[id][prop], '_name'):
                    res[id][prop] = (res[id][prop].id , replaces[res[id][prop]._name].get(res[id][prop].id, False))

        return res

The idea was to add one more item to the domain, using the same code as the function _fnct_write( ... ) uses.

In this scenario, you'll end up with at least two rows in the table 'ir_property':
1. consider we have the res_partner ID: 918 (just an example)
2: using pgadmin, filter your table with: "res_id='res.partner,918' and name='property_account_receivable'"
3.for each row, the "company_id" column should have a different value (following the fact that the user changes the company he is working for), while the field: value_reference is showing your choices (the property "Payable account" is a many2one)
4. the original code *seems* not to be using this column in the search in the function: _fnct_read( ... )
5. with the patch I am proposing, it handles company_id correctly to read the property

Best regards

Revision history for this message
Azazahmed Saiyed (OpenERP) (saz-openerp) wrote :

Let the team will decide.

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
status: Incomplete → Triaged
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hello,

There is no patch needed in the ir.property class, but there was one case not properly handled: when companies A and B in your example were not siblings, but company B was a descendant of company A (or the other way around).

The per-company filtering is in fact implemented by the ir.rule records that are applied on the ir.property object, and the default rule was using "child_of" instead of "=" operator. The child_of operator is appropriate in most cases, but not for ir.property.

This has been fixed in revision 3152 <email address hidden>, so if you update to the latest version (and upgrade the base module), or start with a new database, you should not have the issue anymore.

Thanks for reporting!

Changed in openobject-server:
milestone: none → 6.0-rc2
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.