Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] default_warehouse_from_sale_team: Migration to 18.0 T#87470 #1689

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
20ed74c
[IMP] Better test naming, and cleanup of test (#883)
nhomar Apr 26, 2016
2634d8b
8.0 warehouse default (#889): Test was incorrectly invoqued
nhomar Apr 27, 2016
8e9a127
default_warehouse_from_sale_team: new version (#1032) (#1281)
JulioSerna Jul 3, 2018
7121301
[FIX] default_warehouse_from_sale_team: Update get_id method in seque…
deivislaya Aug 14, 2018
636bdd8
[IMP] default_warehouse_from_sales_team: adapt method in order to avo…
JulioSerna Sep 18, 2018
ba36fcb
[MIG] default_warehouse_from_sale_team: Migration to 12.0
hugho-ad Apr 15, 2019
56c5451
[REF] default_warehouse_from_sale_team: Default journal at invoice is…
hugho-ad May 1, 2019
ca59b1f
[FIX] Lints
hugho-ad May 1, 2019
efd1100
[REF] i18n: Update translations
hugho-ad May 2, 2019
7b224d1
[FIX] default_warehouse_from_sale_team: Wrong UoM Reference
Apr 30, 2020
f469b62
[I18N] default_warehouse_from_sale_team: Update translations terms
CarmenMiranda Jul 15, 2020
9c73d87
[I18N] default_warehouse_from_sale_team: Typo in translation
CarmenMiranda Jul 16, 2020
4a356f4
[FIX] default_warehouse_from_sale_team: Default Sales Team Constraint
CarmenMiranda Jul 17, 2020
241248f
[FIX] default_warehouse_from_sale_team: Adapt tests to v12
luisg123v Aug 2, 2020
9b70fe5
[IMP] default_warehouse_from_sale_team: Remove nested for on ir_rule
Aug 19, 2020
7d0193c
[FIX] default_warehouse_from_sale_team: Remove unnecessary headers
luisg123v Sep 3, 2020
d3a48d4
[MIG] default_warehouse_from_sale_team: Migrate to v13
luisg123v Oct 4, 2020
d64f0a8
[FIX] default_warehouse_from_sale_team: avoid sequence re-call
Oct 30, 2020
9b5157e
[FIX] default_warehouse_from_sale_team: CRM Team Read Permission
CarmenMiranda May 31, 2021
081f4f3
[MIG] default_warehouse_from_sale_team: Migrate to 14.0
luisg123v Jul 24, 2021
8b0a09a
[IMP] default_warehouse_from_sale_team: Improving Rules
CarmenMiranda Oct 12, 2021
02bb468
[REF] default_warehouse_from_sale_team: Sequence assignation in v14.0
luisg123v Oct 20, 2021
f1b5af7
[IMP] default_warehouse_from_sale_team: Rename field Default Warehouse
luisg123v Oct 23, 2021
bd477c0
[FIX] default_warehouse_from_Sale_team: Don't overwrite team nor ware…
luisg123v Nov 23, 2021
2862076
[FIX] default_warehouse_on_sale_team: typo in model names of mixins
luisg123v Feb 12, 2022
bc99b83
[FIX] default_warehouse_from_sale_team: access error when chained rule
luisg123v Feb 22, 2022
65cab85
[IMP] default_warehouse_from_sale_team: Default journal for vendor bills
luisg123v Feb 28, 2022
a7cacf0
[FIX] default_warehouse_from_sale_team: typo in README
luisg123v Mar 3, 2022
6b4a14d
[FIX] default_warehouse_from_sale_team: Sale Team Constraint Message
CarmenMiranda Mar 9, 2022
b87db5c
[IMP] default_warehouse_from_sale_team: journal when created by code
luisg123v Mar 10, 2022
9786a20
[FIX] default_warehouse_from_sale_team: access error on journal name
luisg123v Mar 11, 2022
f2ecaa1
[MIG] default_warehouse_from_sale_team: Migrate to 15.0
rolandojduartem Mar 10, 2022
2d6c035
[ADD] default_warehouse_from_sale_team: Allow to run procurement in w…
rolandojduartem Mar 9, 2022
2d5f481
[IMP] default_warehouse_from_sale_team: black, isort, prettier
ajqn9094 Aug 30, 2022
8513947
[FIX] default_warehouse_from_sale_team: pre-commit-vauxoo error
Jan 23, 2023
34a32c6
[IMP] default_warehouse_from_sale_team: run test after installation
luisg123v Mar 3, 2023
8f25e8e
[REF] default_warehouse_from_sale_team: Rename and split files by the…
rolandojduartem Mar 3, 2023
20fe592
[REF] default_warehouse_from_sale_team: fix indentation in files
rolandojduartem Mar 3, 2023
e2d4d56
[REF] default_warehouse_from_sale_team: Change to Command syntax
rolandojduartem Mar 7, 2023
cb64d9b
[REF] default_warehouse_from_sale_team: Remove superfluous false noup…
rolandojduartem Mar 7, 2023
640687c
[MIG] default_warehouse_from_sale_team: Migration to 16.0
rolandojduartem Mar 9, 2023
88aa2b4
[IMP] default_warehouse_from_sale_team: Add sale_team_ids to the inva…
rolandojduartem Apr 18, 2023
a458a38
[FIX] default_warehouse_from_sale_team: Avoid return the same record …
R4Alex Jun 1, 2023
f7a9d55
[I18n] default_warehouse_from_sale_team: autoformat translations
luisg123v Jul 1, 2023
738d421
[FIX] default_warehouse_from_sale_team: update default journal retrieval
CLaurelB Oct 18, 2023
bc0cd5c
[MIG] default_warehouse_from_sale_team: Migration to 17.0
xmglord Apr 3, 2024
32c42f9
[FIX] default_warehouse_from_sale_team: Fix case of searching a stock…
keylor2906 Apr 15, 2024
d9cb654
[IMP] default_warehouse_from_sale_team: hook to fill allowed sales teams
luisg123v Jul 6, 2024
86dae09
[IMP] default_warehouse_from_sale_team: make ineritable bypassed rules
luisg123v Mar 17, 2022
7371861
[FIX] default_warehouse_from_sale_team: remove incorrect record rule
luisg123v Jul 27, 2024
e72e683
[FIX] default_warehouse_from_sale_team: usability for readonly users
luisg123v Sep 5, 2024
a51aa2c
[FIX] default_warehouse_from_sale_team: prevent Sales Team compute on…
CLaurelB Dec 30, 2024
94eac14
[FIX] default_warehouse_from_sale_team: validate cache access when no…
CLaurelB Jan 9, 2025
1ba7e44
[MIG] default_warehouse_from_sale_team: Migration to 18.0
IrvingReyes Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions default_warehouse_from_sale_team/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

=================================
Default Warehouse from Sales Team
=================================

Usage
=====

Add a field `Default Warehouse` in sales team.

Create sort kind of api where any object with field called warehouse_id will
take the default value from the sales team field
this taking into account the team defined in `Default Sale Teams` field defined
in the res.user model.

To improve, consistency and usability we add the following features:

- If you try to add a default sales team where the user doesn't belongs wil throw
you an error message: Can not set default team is do not belongs to sale team
- Add an automated action/server action to update the user default sales team
every time that a sales teams by:

- add user's default sale team if empty.
- remove default sale team from user if not longer in sale team.
- dummy write to update m2m in users to make new feature for filtering
records.

Currently this default warehouse feature applies for:
- Sale orders
- Transfers (``stock.picking``)
- Operation type (``stock.picking.type``)

Also add a new feature for Permissions and Security: Taking advantage of the
default_warehouse field in the sales team model now we can filter the
records (picking type and picking model) to only show those records that match
with the user sale teams default_warehouse. To accomplish this I:

- add new groups to manage the records access by user:

* Default Warehouse / Limited access to transfers (filtered by sales team)
* Default Warehouse / Limited access to operation types (filtered by sales team)
* Default Warehouse / Access to all operation types
* Default Warehouse / Access to all transfers

- add new m2m field in the res.user model used in the new ir.rules.
this onw is showed as a readonly field (only informative) to know
the teams were the sale user belongs.
- add new ir.rule records, one for each default warehouse group. This
one will let us to only show the records for the current user sale
teams default_warehouse or to do not take into account the sale teams
and show all the records to the user.

To add more models use it simple do this:

1. Inherit the class that you want to set the field warehouse_id::

class SomeClass(models.Model):
_name = 'some.class'
_inherit = ['some.class', 'default.warehouse']
warehouse_id = fields.Many2one('stock.warehouse', help='Warehouse were'
'this object will belong to')

2. Create two ir.rule to filter stock.picking and stock.picking.type taking
into account the current user warehouses. When a user is part of warehouse
teams will be able to access only the records related to that warehouses::

<record id="rule_group_model" model="ir.rule">
<field name="name">Limited access to model (filtered by sales teams)</field>
<field name="model_id" search="[('model','=','model')]" model="ir.model"/>
<field name="groups" eval"[Command.set([ref('xml_id_group')])]/>
<field name="domain_force">[('warehouse_id', 'in', [team.default_warehouse.id for team in user.sale_team_ids if team.default_warehouse])]</field>
</record>
<record id="rule_group_model_2" model="ir.rule">
<field name="name">Access to all model</field>
<field name="model_id" search="[('model','=','model')]" model="ir.model"/>
<field name="groups" eval"[Command.set([ref('xml_id_group')])]/>
<field name="domain_force">[(1, '=', 1)]</field>
</record>

3. Don't forget depends of this module adding it to the list into `__openerp__.py`::

The default value from this field will be the warehouse setted in the section.
If the user is not related to a sales team or not warehouse setted on the
section the default warehouse will be set using the default behavior of the
system which is assign the main warehouse.

Bug Tracker
===========

Bugs are tracked on
`GitHub Issues <https://github.com/Vauxoo/addons-vauxoo/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and
welcomed feedback
`here <https://github.com/Vauxoo/addons-vauxoo/issues/new?body=module:%20
default_warehouse_from_sale_team
%0Aversion:%20
18.0
%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_

Credits
=======

**Contributors**

* Nhomar Hernández <[email protected]> (Planner/Developer)
* Katherine Zaoral <[email protected]> (Planner/Developer)
* Luis González <[email protected]> (Developer)
* Rolando Duarte <[email protected]> (Developer)

Maintainer
==========

.. image:: https://s3.amazonaws.com/s3.vauxoo.com/description_logo.png
:alt: Vauxoo
:target: https://www.vauxoo.com
:width: 200

This module is maintained by Vauxoo.

To contribute to this module, please visit https://www.vauxoo.com.
2 changes: 2 additions & 0 deletions default_warehouse_from_sale_team/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_init_hook
34 changes: 34 additions & 0 deletions default_warehouse_from_sale_team/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "Default Warehouse from Sales Team",
"summary": """Adding a field for the default user warehouse and modifying
the global default method for assign in any related field the correct
default warehouse.
""",
"author": "Vauxoo",
"website": "http://www.vauxoo.com",
"license": "LGPL-3",
"category": "Inventory/Inventory",
"version": "18.0.1.0.0",
"depends": [
"sale_stock",
"purchase_requisition",
],
"data": [
"views/crm_team_views.xml",
"views/ir_sequence_views.xml",
"views/res_users_views.xml",
"views/stock_picking_type_views.xml",
"views/stock_picking_views.xml",
"security/res_groups_security.xml",
"security/ir_rule_security.xml",
],
"demo": [
"demo/account_journal_demo.xml",
"demo/stock_warehouse_demo.xml",
"demo/crm_team_demo.xml",
],
"post_init_hook": "post_init_hook",
"installable": True,
"application": False,
"auto_install": False,
}
10 changes: 10 additions & 0 deletions default_warehouse_from_sale_team/demo/account_journal_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version='1.0' encoding='UTF-8' ?>
<odoo>

<record id="journal_default_team" model="account.journal">
<field name="name">Journal Default Warehouse</field>
<field name="code">JDW</field>
<field name="type">general</field>
</record>

</odoo>
10 changes: 10 additions & 0 deletions default_warehouse_from_sale_team/demo/crm_team_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version='1.0' encoding='UTF-8' ?>
<odoo>

<record id="section_sales_default_team" model="crm.team">
<field name="name">Default Team</field>
<field name="default_warehouse_id" ref="stock_warehouse_default_team" />
<field name="journal_stock_id" ref="journal_default_team" />
</record>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='UTF-8' ?>
<odoo>

<record id="stock_warehouse_default_team" model="stock.warehouse">
<field name="name">Team Default Warehouse</field>
<field name="code">TDW</field>
</record>

</odoo>
25 changes: 25 additions & 0 deletions default_warehouse_from_sale_team/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import logging

_logger = logging.getLogger(__name__)


def post_init_hook(env):
fill_user_allowed_salesteams(env)


def fill_user_allowed_salesteams(env):
"""Fill allowed sales teams in users that are already members of any team.

Since this module implements a feature to restrict which sales teams a user may be a member of, users that already
belong to any team are configured to be allowed for those teams, to avoid inconsistencies between allowed and
already-configured memberships. In other words, if a user already belongs to a team, it most likely means they
should be allowed to belong to it, so allowance is granted.
"""
teams_per_user = env["crm.team.member"]._read_group(
domain=[],
groupby=["user_id"],
aggregates=["crm_team_id:recordset"],
)
for user, teams in teams_per_user:
user.sale_team_ids |= teams
_logger.info("Field 'Allowed sales Teams' has been set to %d users.", len(teams_per_user))
Loading