Can not get a sequence_id from a child company

Bug #789832 reported by Eric Caudal - www.elico-corp.com
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Medium
OpenERP's Framework R&D

Bug Description

In V6, how to reproduce the bug:
2 companies, A is child of B.
2 invoice sequences, one for A and one for B.
User X with company B as main company should be able to watch all objects from company B and A.
When user X is entering a new invoice for company A, no sequence_id is generated. This is due to the fact that in ir_sequence/get_id the following code seems incorrect:

        company_id = self.pool.get('res.users').read(cr, uid, uid, ['company_id'], context=context)['company_id'][0] or None
        cr.execute('''SELECT id, number_next, prefix, suffix, padding
                      FROM ir_sequence
                      WHERE %s=%%s
                       AND active=true
                       AND (company_id = %%s or company_id is NULL)
                      ORDER BY company_id, id
                      FOR UPDATE NOWAIT''' % test,
                      (sequence_id, company_id))

The function is filtering according to user's company (B) and cannot find the correct invoice sequence (which is assigned to A company).
As far as I understand multi-company, the filter should find a list of all children companies and give all sequences for A, B and NULL.

affects: openobject-addons → openobject-server
Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
xrg (xrg) wrote : Re: [Bug 789832] [NEW] Can not get a sequence_id from a child company

On Sunday 29 May 2011, you wrote:
> Public bug reported:
>
> In V6, how to reproduce the bug:
> 2 companies, A is child of B.
> 2 invoice sequences, one for A and one for B.
> User X with company B as main company should be able to watch all objects
> from company B and A. When user X is entering a new invoice for company A,
> no sequence_id is generated. This is due to the fact that in
> ir_sequence/get_id the following code seems incorrect:
>
> company_id = self.pool.get('res.users').read(cr, uid, uid,
> ['company_id'], context=context)['company_id'][0] or None

Hmm. Smells dead fish here..

The company_id of the ir.sequence must match the one of the journal. Or
shouldn't be considered at all..

Why would the sequence ever be affected by the /user/ doing the operation,
rather than the /object/ receiving the sequence number?

Using the current code, *please* have distinct sequences per journal, and have
company_id=NULL at all of them.

--
Say NO to spam and viruses. Stop using Microsoft Windows!

Revision history for this message
Eric Caudal - www.elico-corp.com (elicoidal) wrote :

I agree with the solution which applied.
Nevertheless, the get_id function should return by default all
sequence_id applying for the user.
Question could be: should we add filter in function call a for specific
scope (Journal's company only for example) or should we control after
the function call that result is compatible with journal's comapny?
I'd rather the second but...

--
Eric

Revision history for this message
xrg (xrg) wrote :

On Friday 10 June 2011, you wrote:
> I agree with the solution which applied.
> Nevertheless, the get_id function should return by default all
> sequence_id applying for the user

Can you give me any example where the user (+ his company or so) would affect
the numbering? Are we /ever/ allowed to use more than 1 sequence per
journal/stock etc? [1]

> Question could be: should we add filter in function call a for specific
> scope (Journal's company only for example) or
I had -long- [2] implemented a "condition" field in ir.sequence . There, I say,
if we need to select sequence by any criteria, we could put a small expression
and have it restrict the selection. So far, I discovered that using distinct
journals has been the best practice, rather than trying to select among
multiple sequences.

> should we control after
> the function call that result is compatible with journal's comapny?
you mean validate?
A sequence is a counter that you only want to use irreversibly. So, if you get
a number and you then realize it's not the right sequence, you can't go back.

Said that, if you just want to do an 'assertion' that you used the right
sequence, that's fine. Not, however, try to repeat and use another sequence.

> I'd rather the second but...

[1] yes, journal is the worst example, because it's strictly defined. Other
models may have more relax rules. Do they?
[2] found in trunk-xrg, pg84 and pg84-next branches, since the early days I've
worked with the 5.0 series

Revision history for this message
Eric Caudal - www.elico-corp.com (elicoidal) wrote :

Maybe I didnot express myself correctly.

> Can you give me any example where the user (+ his company or so) would affect
> the numbering? Are we /ever/ allowed to use more than 1 sequence per
> journal/stock etc? [1]

I have a user which is in the holding company and can invoice in both
child company witht different numbering system. No need for several
sequence per journal but still when user X invoices for company A, it
should get the seq A from the journal A (and subsequently for B). Yes
company A should have journal A and sequence A and you cannot cross
reference here but still if in invoicing I should company A for which I
allowed to make invoice it should set all objects to A (and B if I
choose B).

> I had -long- [2] implemented a "condition" field in ir.sequence . There, I say,
> if we need to select sequence by any criteria, we could put a small expression
> and have it restrict the selection. So far, I discovered that using distinct
> journals has been the best practice, rather than trying to select among
> multiple sequences.

My question was more on the way the information is handle by python and
the function.
the get_id function should return all valid sequence number for a user
but then you need to be able to check if those sequence numbers are
valid (eg seq A for company B is invalid).
Concerning this validation, I was wondering if it is bettter to
implement it as a condition after get_id is called or send a filter as a
parameter.

>

Eric

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

Hi,

This was fixed recently in 6.0 due to a Maintenance case, and the fix was just ported to forward-ported to trunk at revision: 3514
revid: <email address hidden>

See also bug 808672 about further improvements to this topic.

Thanks for reporting!

Changed in openobject-server:
milestone: none → 6.1
status: Confirmed → 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.