# Ready to use multi-company

**URL:** <https://discuss.tryton.org/t/ready-to-use-multi-company/4793>\
**Category:** Feature\
**Created:** [November 24, 2021, 9:56pm UTC](https://discuss.tryton.org/t/ready-to-use-multi-company/4793 "2021-11-24T21:56:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [November 24, 2021, 9:56pm UTC](https://discuss.tryton.org/t/ready-to-use-multi-company/4793/1 "2021-11-24T21:56:17Z")

</div>

## Rational

In [Remove company record rules (#4080) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue4080) we made it possible to work on many companies in the same session. The problem is that most of the list views do not display the company field. This is mainly to not overload the view with a column with always the same value for the most common use case of mono-company.  
So with standard views it is difficult to work on multi-company setup without customize many views.

## Proposal

I propose to add the company column on all the list view. But to override all the `ModelView` with a `Mixin` that will set `optional="1"` to company field (any `Many2One` pointing to `company.company`) of all tree views if the number of company in the database is equal to `1`.  
But also to move out the company field from “Other Info” tab to the header of the forms as it needs to be visually checked by multi-company users.

## Implementation

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [November 25, 2021, 8:17am UTC](https://discuss.tryton.org/t/ready-to-use-multi-company/4793/2 "2021-11-25T08:17:07Z")

</div>

Your proposal makes completly sense for me but I’m wondering if we should have a similar behaviour for Warehouse adding it to tree view and having the same Mixin.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [November 25, 2021, 8:37am UTC](https://discuss.tryton.org/t/ready-to-use-multi-company/4793/3 "2021-11-25T08:37:49Z")

</div>

Indeed that’s also a nice to have. The only problem is that we do not have a cached method to count the number of warehouses.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [November 25, 2021, 8:53am UTC](https://discuss.tryton.org/t/ready-to-use-multi-company/4793/4 "2021-11-25T08:53:13Z")

</div>

> [@ced](#):
>
> The only problem is that we do not have a cached method to count the number of warehouses.

Do we have a chached method to count the number of companies? 😱

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [November 25, 2021, 11:20am UTC](https://discuss.tryton.org/t/ready-to-use-multi-company/4793/5 "2021-11-25T11:20:01Z")

</div>

Yes we have a cached method on all `ModelStorage` that count the number of record.

So to support warehouses we will have to implement a similar cached counting.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [November 25, 2021, 3:55pm UTC](https://discuss.tryton.org/t/ready-to-use-multi-company/4793/6 "2021-11-25T15:55:12Z")

</div>

> [@ced](#):
>
> So to support warehouses we will have to implement a similar cached counting.

Maybe we can just add a `domain` argument to the current count function, so we can count the warehouses (but also any other domain clause).

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [November 28, 2021, 12:33am UTC](https://discuss.tryton.org/t/ready-to-use-multi-company/4793/7 "2021-11-28T00:33:44Z")

</div>

Instead of using `tree_invisible` I think we should use the `optional` from [Per user list view definition](https://discuss.tryton.org/t/per-user-list-view-definition/3729).

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [April 6, 2022, 8:42am UTC](https://discuss.tryton.org/t/ready-to-use-multi-company/4793/8 "2022-04-06T08:42:28Z")

</div>

Closed on April 6, 2022, 8:42am UTC


