Toward a working multi-company

223 views
Skip to first unread message

Cédric Krier

unread,
Jul 3, 2014, 3:59:30 AM7/3/14
to tryton
Hi,

I was requested to provide a plan for multi-company as I say in
issue3974 [1].

TL;DR: drop record rule, add domain on fields

First, what is wrong with the current implementation? The multi-company
is a legacy from TinyERP/OpenERP/Odoo (partially from me). It uses the
record rule to split the records by companies and many part of the code
rely on this to find the right subset of records etc.
It is a wrong design because it is mixing 2 things, the access right and
the business logic. There are no reason to rely on access right to
ensure that an sale generate invoices from the same company.

So the plan is to remove all the company record rule/access right (it is
part of the customization/configuration) and use domains to enforce
company where it is needed (invoices on sale, account on moves, etc.)
So by default everyone will see every companies, restriction will be
part of the configuration.
And the company context will be used only for default value of company
field.
It will probably require to add some more 'company' fields, for example
on move. They will be needed on «main documents» and thanks to the
domain inversion and the validation, children lines will be filled
correctly and the integrity will be respected.

The only tricky part that I see for this change, is the stock quantity
computation. But probably we could just add a filter for companies.

Also this change will not affect any mono-company installation which I
guess is the majority.


[1] https://bugs.tryton.org/issue3974
--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Sergi Almacellas Abellana

unread,
Jul 3, 2014, 5:16:46 AM7/3/14
to tryto...@googlegroups.com
El 03/07/14 09:59, Cédric Krier ha escrit:
> Hi,
>
> I was requested to provide a plan for multi-company as I say in
> issue3974 [1].
>
> TL;DR: drop record rule, add domain on fields
>
> First, what is wrong with the current implementation? The multi-company
> is a legacy from TinyERP/OpenERP/Odoo (partially from me). It uses the
> record rule to split the records by companies and many part of the code
> rely on this to find the right subset of records etc.
> It is a wrong design because it is mixing 2 things, the access right and
> the business logic. There are no reason to rely on access right to
> ensure that an sale generate invoices from the same company.
>
> So the plan is to remove all the company record rule/access right (it is
> part of the customization/configuration) and use domains to enforce
> company where it is needed (invoices on sale, account on moves, etc.)
> So by default everyone will see every companies, restriction will be
> part of the configuration.
When you say restriction will be part of the configuration, you say it's
up to every company that needs to multi-company support to add the
needed access rules or another mechanims they want in order to restrict
the access to companies to some users?
> And the company context will be used only for default value of company
> field.
But the company fields on res.user will still be there? Or you plan to
remove it also?
> It will probably require to add some more 'company' fields, for example
> on move. They will be needed on «main documents» and thanks to the
> domain inversion and the validation, children lines will be filled
> correctly and the integrity will be respected.
>
> The only tricky part that I see for this change, is the stock quantity
> computation. But probably we could just add a filter for companies.
So in a multi-company environment the user will be able to compute the
stock for one company, and for all the companies in the system?


--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Cédric Krier

unread,
Jul 3, 2014, 5:36:39 AM7/3/14
to tryto...@googlegroups.com
On 03 Jul 11:16, Sergi Almacellas Abellana wrote:
> El 03/07/14 09:59, Cédric Krier ha escrit:
> >Hi,
> >
> >I was requested to provide a plan for multi-company as I say in
> >issue3974 [1].
> >
> >TL;DR: drop record rule, add domain on fields
> >
> >First, what is wrong with the current implementation? The multi-company
> >is a legacy from TinyERP/OpenERP/Odoo (partially from me). It uses the
> >record rule to split the records by companies and many part of the code
> >rely on this to find the right subset of records etc.
> >It is a wrong design because it is mixing 2 things, the access right and
> >the business logic. There are no reason to rely on access right to
> >ensure that an sale generate invoices from the same company.
> >
> >So the plan is to remove all the company record rule/access right (it is
> >part of the customization/configuration) and use domains to enforce
> >company where it is needed (invoices on sale, account on moves, etc.)
> >So by default everyone will see every companies, restriction will be
> >part of the configuration.
> When you say restriction will be part of the configuration, you say it's up
> to every company that needs to multi-company support to add the needed
> access rules or another mechanims they want in order to restrict the access
> to companies to some users?

Yes, they should be just like any other access rights.

> >And the company context will be used only for default value of company
> >field.
> But the company fields on res.user will still be there? Or you plan to
> remove it also?

Yes - No, it is the storage of the context.

> >It will probably require to add some more 'company' fields, for example
> >on move. They will be needed on «main documents» and thanks to the
> >domain inversion and the validation, children lines will be filled
> >correctly and the integrity will be respected.
> >
> >The only tricky part that I see for this change, is the stock quantity
> >computation. But probably we could just add a filter for companies.
> So in a multi-company environment the user will be able to compute the stock
> for one company, and for all the companies in the system?

Why not. But probably the wizard will ask for a company (prefilled).

Cédric Krier

unread,
Jul 23, 2014, 4:54:07 PM7/23/14
to tryton
On 03 Jul 09:59, Cédric Krier wrote:
> Hi,
>
> I was requested to provide a plan for multi-company as I say in
> issue3974 [1].
>
> TL;DR: drop record rule, add domain on fields

Here is

- the issue: https://bugs.tryton.org/issue4080
- the review: http://codereview.tryton.org/10461002/

Mathias Behrle

unread,
Jul 23, 2014, 6:55:36 PM7/23/14
to tryto...@googlegroups.com
* Cédric Krier: " Re: [tryton-dev] Toward a working multi-company" (Wed, 23 Jul
2014 22:54:04 +0200):

> On 03 Jul 09:59, Cédric Krier wrote:
> > Hi,
> >
> > I was requested to provide a plan for multi-company as I say in
> > issue3974 [1].
> >
> > TL;DR: drop record rule, add domain on fields
>
> Here is
>
> - the issue: https://bugs.tryton.org/issue4080
> - the review: http://codereview.tryton.org/10461002/

Much appreciated! As we are at the point to make the decision for a customer to
use a multi-company in favor of a multi-database setup I want to ask, if we can
supposedly rely on this feature in the future. If there are uncertainties about
the persistance of this feature, please let us know.

BTW the current multi-company support wrt. to shared models would work quite
well for this use case.


--

Mathias Behrle
MBSolutions
Gilgenmatten 10 A
D-79114 Freiburg

Tel: +49(761)471023
Fax: +49(761)4770816
http://m9s.biz
UStIdNr: DE 142009020
PGP/GnuPG key availabable from any keyserver, ID: 0x8405BBF6
signature.asc

Cédric Krier

unread,
Jul 23, 2014, 7:13:50 PM7/23/14
to tryto...@googlegroups.com
On 24 Jul 00:53, Mathias Behrle wrote:
> * Cédric Krier: " Re: [tryton-dev] Toward a working multi-company" (Wed, 23 Jul
> 2014 22:54:04 +0200):
>
> > On 03 Jul 09:59, Cédric Krier wrote:
> > > Hi,
> > >
> > > I was requested to provide a plan for multi-company as I say in
> > > issue3974 [1].
> > >
> > > TL;DR: drop record rule, add domain on fields
> >
> > Here is
> >
> > - the issue: https://bugs.tryton.org/issue4080
> > - the review: http://codereview.tryton.org/10461002/
>
> Much appreciated! As we are at the point to make the decision for a customer to
> use a multi-company in favor of a multi-database setup I want to ask, if we can
> supposedly rely on this feature in the future. If there are uncertainties about
> the persistance of this feature, please let us know.

For me, it is the way to go but still waiting feedback from others.
But about "feature" as you can see it is more about removing rules than
adding new stuff. The new code is mainly adding missing domain (should
be there in any cases) or missing company field and in few places it
just hard code the previous rule because anything else don't make sense
(ex: stock quantity)

> BTW the current multi-company support wrt. to shared models would work quite
> well for this use case.

--

Cédric Krier

unread,
Jul 24, 2014, 5:08:30 AM7/24/14
to tryto...@googlegroups.com
On 24 Jul 01:13, Cédric Krier wrote:
> On 24 Jul 00:53, Mathias Behrle wrote:
> > * Cédric Krier: " Re: [tryton-dev] Toward a working multi-company" (Wed, 23 Jul
> > 2014 22:54:04 +0200):
> >
> > > On 03 Jul 09:59, Cédric Krier wrote:
> > > > Hi,
> > > >
> > > > I was requested to provide a plan for multi-company as I say in
> > > > issue3974 [1].
> > > >
> > > > TL;DR: drop record rule, add domain on fields
> > >
> > > Here is
> > >
> > > - the issue: https://bugs.tryton.org/issue4080
> > > - the review: http://codereview.tryton.org/10461002/
> >
> > Much appreciated! As we are at the point to make the decision for a customer to
> > use a multi-company in favor of a multi-database setup I want to ask, if we can
> > supposedly rely on this feature in the future. If there are uncertainties about
> > the persistance of this feature, please let us know.
>
> For me, it is the way to go but still waiting feedback from others.
> But about "feature" as you can see it is more about removing rules than
> adding new stuff. The new code is mainly adding missing domain (should
> be there in any cases) or missing company field and in few places it
> just hard code the previous rule because anything else don't make sense
> (ex: stock quantity)

Also this review needs more testing especially for new cases, like
creating a sale for an other company then the current user one.

Albert Cervera i Areny

unread,
Jul 25, 2014, 6:55:04 PM7/25/14
to tryto...@googlegroups.com
2014-07-03 9:59 GMT+02:00 Cédric Krier <cedric...@b2ck.com>:
> Hi,
>
> I was requested to provide a plan for multi-company as I say in
> issue3974 [1].
>
> TL;DR: drop record rule, add domain on fields
>
> First, what is wrong with the current implementation? The multi-company
> is a legacy from TinyERP/OpenERP/Odoo (partially from me). It uses the
> record rule to split the records by companies and many part of the code
> rely on this to find the right subset of records etc.
> It is a wrong design because it is mixing 2 things, the access right and
> the business logic. There are no reason to rely on access right to
> ensure that an sale generate invoices from the same company.

I agree current design is wrong.

> So the plan is to remove all the company record rule/access right (it is
> part of the customization/configuration) and use domains to enforce
> company where it is needed (invoices on sale, account on moves, etc.)
> So by default everyone will see every companies, restriction will be
> part of the configuration.
> And the company context will be used only for default value of company
> field.

I'm not sure this is the desired behaviour nor consistent with how
Tryton currently works. For example, to me it looks quite similar to
the warehouse field in sales. There, the warehouse is only filled in
automatically if the user has access to one warehouse only.

Well, maybe some users will desire this behaviour but I think it is an
error-prone default.

> It will probably require to add some more 'company' fields, for example
> on move. They will be needed on «main documents» and thanks to the
> domain inversion and the validation, children lines will be filled
> correctly and the integrity will be respected.
>
> The only tricky part that I see for this change, is the stock quantity
> computation. But probably we could just add a filter for companies.

I agree the filter is the way to go.

I took a look at the patch and I see that by now you used user's
default company. I really prefer the filter.

>
> Also this change will not affect any mono-company installation which I
> guess is the majority.
>
>
> [1] https://bugs.tryton.org/issue3974
> --
> Cédric Krier - B2CK SPRL
> Email/Jabber: cedric...@b2ck.com
> Tel: +32 472 54 46 59
> Website: http://www.b2ck.com/



--
Albert Cervera i Areny
Tel. 93 553 18 03
@albertnan
www.NaN-tic.com

Cédric Krier

unread,
Jul 26, 2014, 8:26:40 AM7/26/14
to tryto...@googlegroups.com
On 26 Jul 00:55, Albert Cervera i Areny wrote:
> > So the plan is to remove all the company record rule/access right (it is
> > part of the customization/configuration) and use domains to enforce
> > company where it is needed (invoices on sale, account on moves, etc.)
> > So by default everyone will see every companies, restriction will be
> > part of the configuration.
> > And the company context will be used only for default value of company
> > field.
>
> I'm not sure this is the desired behaviour nor consistent with how
> Tryton currently works. For example, to me it looks quite similar to
> the warehouse field in sales. There, the warehouse is only filled in
> automatically if the user has access to one warehouse only.
>
> Well, maybe some users will desire this behaviour but I think it is an
> error-prone default.

I don't understand.

> > It will probably require to add some more 'company' fields, for example
> > on move. They will be needed on «main documents» and thanks to the
> > domain inversion and the validation, children lines will be filled
> > correctly and the integrity will be respected.
> >
> > The only tricky part that I see for this change, is the stock quantity
> > computation. But probably we could just add a filter for companies.
>
> I agree the filter is the way to go.
>
> I took a look at the patch and I see that by now you used user's
> default company. I really prefer the filter.

I keep the current behavior for cases that needs something.
If you have a better design please propose a patch.

Cédric Krier

unread,
Sep 8, 2014, 4:05:31 AM9/8/14
to tryto...@googlegroups.com
For me, the state of the patch is good for inclusion so I plan to push
it by the end of the week of I get no bad feedbacks.

Mathias Behrle

unread,
Sep 8, 2014, 7:14:55 AM9/8/14
to tryto...@googlegroups.com
* Cédric Krier: " Re: [tryton-dev] Toward a working multi-company" (Mon, 8 Sep
2014 10:05:28 +0200):
The test of this patch is on my TODO, but I didn't manage so far to find the
time. I will try to do it this week.
signature.asc

Cédric Krier

unread,
Sep 10, 2014, 3:50:13 PM9/10/14
to tryto...@googlegroups.com
So I give up for this patch.
So to be clear, multi-company will still not work for the next release.

The issues are:

- property field: it will not be possible to have correct
multi-company when we still have those shitty fields.

- context: in base we should never depend on context.

- user.company: in base we should never depend on this.
Reply all
Reply to author
Forward
0 new messages