sequence might use a child company's sequence by error under certain circumstances

Bug #863221 reported by Pollet Alexandre
30
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Status tracked in Trunk
6.0
Confirmed
Low
OpenERP Publisher's Warranty Team
Trunk
Fix Released
Low
OpenERP's Framework R&D

Bug Description

On ~openerp/openobject-server/6.0 since rev 3460:

"rev 3460 : [MERGE] Merged ILA's branch for the fix of correction in get_id() of ir_sequence to allow multi-company feature"

It's does'nt work if you use multi-company feature...

Now the sql query select every sequences for all companies (for the object) order by company_id, but there is a cr.dictfetchone() after sql response...

For example, when you create a sale_order (or any other objects), the sequence returned is the for the first company_id found.
However we need to have the specific sequence of the active user's company .

So the code of ir_sequence.py before rev 3460 works fine with multi-company

ir_sequence.py, line 78 rev 3460:
 - company_id = self.pool.get('res.users').read(cr, uid, uid, ['company_id'], context=context)['company_id'][0] or None
+ company_ids = self.pool.get('res.company').search(cr, uid, [], context=context)

Related branches

Revision history for this message
Amit Parik (amit-parik) wrote :

Hello,

I have checked your issue with latest 6.0 and all are working fine.

And the sequence are generated properly for multi-company.

For more reference I have attached a video so would you please check it and notify us where you faced the problem.

Thanks and waiting for your reply!

Revision history for this message
Amit Parik (amit-parik) wrote :
Changed in openobject-server:
status: New → Incomplete
Revision history for this message
Pollet Alexandre (a-pollet) wrote :

hello,

thanks for your video.

But now can you create an new company "" with "Shop 1" as parent.
After create a new user with this new company.
Create a new sequence for this new company.

And try the new sequence.

For me it's clear in the code...the company used it's not the compagy of the user.

""""
        company_ids = self.pool.get('res.company').search(cr, uid, [], context=context)

        cr.execute('''SELECT id, number_next, prefix, suffix, padding
                      FROM ir_sequence
                      WHERE %s=%%s
                       AND active=true
                       AND (company_id in %%s or company_id is NULL)
                      ORDER BY company_id, id
                      FOR UPDATE NOWAIT''' % test,
                      (sequence_id, tuple(company_ids)))
        res = cr.dictfetchone()
"""
company_ids it's all the companies.
res it's the first return of the select.
So it's the sequence for the company which has the minimal id ?

Thanks

Revision history for this message
Graeme Gellatly (gdgellatly) wrote : Re: [Bug 863221] Re: [6.0] ir_sequence does'nt work with multi_company

+1 for this, noticed it today. Was trying to iron out another bug and
testing with admin user who belongs to 2 companies and was getting the other
company sequence.

On Thu, Oct 6, 2011 at 1:18 AM, Pollet Alexandre
<email address hidden>wrote:

> hello,
>
> thanks for your video.
>
> But now can you create an new company "" with "Shop 1" as parent.
> After create a new user with this new company.
> Create a new sequence for this new company.
>
> And try the new sequence.
>
> For me it's clear in the code...the company used it's not the compagy of
> the user.
>
> """"
> company_ids = self.pool.get('res.company').search(cr, uid, [],
> context=context)
>
> cr.execute('''SELECT id, number_next, prefix, suffix, padding
> FROM ir_sequence
> WHERE %s=%%s
> AND active=true
> AND (company_id in %%s or company_id is NULL)
> ORDER BY company_id, id
> FOR UPDATE NOWAIT''' % test,
> (sequence_id, tuple(company_ids)))
> res = cr.dictfetchone()
> """
> company_ids it's all the companies.
> res it's the first return of the select.
> So it's the sequence for the company which has the minimal id ?
>
> Thanks
>
> --
> You received this bug notification because you are subscribed to OpenERP
> Server.
> https://bugs.launchpad.net/bugs/863221
>
> Title:
> [6.0] ir_sequence does'nt work with multi_company
>
> Status in OpenERP Server:
> Incomplete
>
> Bug description:
> On ~openerp/openobject-server/6.0 since rev 3460:
>
> "rev 3460 : [MERGE] Merged ILA's branch for the fix of correction in
> get_id() of ir_sequence to allow multi-company feature"
>
> It's does'nt work if you use multi-company feature...
>
> Now the sql query select every sequences for all companies (for the
> object) order by company_id, but there is a cr.dictfetchone() after
> sql response...
>
> For example, when you create a sale_order (or any other objects), the
> sequence returned is the for the first company_id found.
> However we need to have the specific sequence of the active user's company
> .
>
> So the code of ir_sequence.py before rev 3460 works fine with multi-
> company
>
> ir_sequence.py, line 78 rev 3460:
> - company_id = self.pool.get('res.users').read(cr, uid, uid,
> ['company_id'], context=context)['company_id'][0] or None
> + company_ids = self.pool.get('res.company').search(cr, uid, [],
> context=context)
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/openobject-server/+bug/863221/+subscriptions
>

Amit Parik (amit-parik)
summary: - [6.0] ir_sequence does'nt work with multi_company
+ sequence might use a child company's sequence by error under certain
+ circumstances
Revision history for this message
Amit Parik (amit-parik) wrote :

Hello,

I have faced the same problem when
 - in 6.0, if child company has lower ID than parent company
 - in trunk, if child company sequence has name lower than parent company sequence

In 6.0 it will depend on the ID of the company, because the result is order by company_id so if a child company has an ID lower than the parent company, users of parent company will always use sequence of child company .

For trunk we recently re wrote ir.sequence, and now it will use a normal search, so the order will be the default one and ir_sequence._order is 'name', so it will now be based on the sequence name so when the child company has name lower then the parent we will seen the same sequence in parent also.

Thanks for reporting!

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Low
status: Incomplete → Confirmed
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello,

Thanks for reporting the bug !

for the trunk version had allowed to pass force_company in the context if you want specific companies seq to be used else it will use users current company sequence.

It has been fixed at lp:~openerp-dev/openobject-server/trunk-bug-863221-nch with revision-info:3799 <email address hidden> and will be merged soon to the trunk server.

Regards,

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

As Naresh says, we have fixed this by considering a "preferred company" when selecting the sequence. By default the preferred company will be the company of the user, but this can be overridden for special cases. (Technically this works similarly to reading properties: by specifying a 'force_company' key in the context).
If no sequence is found for the preferred company, we fallback to selecting the first matching sequence that is currently visible to the user. Probably in that last case we should give priority to sequences that belong to a company rather than global sequences, because the former are presumed to be more specific than the latter.

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

The fix for this problem has landed in trunk(6.1) at revision 3881 revid: <email address hidden>
Thanks for reporting!

Revision history for this message
Jose Antonio Morales Ponce(vauxoo) - - http://www.vauxoo.com (josemoralesp) wrote :

The simplest solution is simple and add to the judgment company_id filter by user, not by all companies.
That way I can have multiple sequences with the same code but for distintias companies. I apply a patch with this condition and it works perfectly, but the multi-company module should inherit and carry out this modification, because there are important documents such as the deductions should have a different sequence for comañia and never mixed because which is a document that reviews state agencies and are very careful in the sequence of documents

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Bug attachments

Remote bug watches

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