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

Open
wants to merge 55 commits into
base: 17.0
Choose a base branch
from

Conversation

IrvingReyes
Copy link

This PR is related to task#87,470

luisg123v and others added 30 commits January 27, 2025 20:23
sale_team_warehouse => default_warehouse_from_sale_team
* Better test naming.
* [IMP] Better module naming.
)

This module formerly just add a default_warehouse field to the sales
    team model that is used to set the `warehouse_id` field in the sale order
    when the current user has defined a `Default Sale Team`

    We extend this functionality by:

    - Improve consistency: Add a constraint that do not let us to add a
      default sale team if the user do not belongs to the sales team.
    - Improve usability: 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 filtering rules work.

    - Extend scope: Now both stock picking and stock.picking type models
      also have default warehouse_id functionality taking into account the
      user default sale team.
    - Compatibility fix: in order to be compatible with one of our customers
      instances we remove the _auto = False for WarehouseDefault api.

    - 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 pickings (filtered by sale teams)
          * Default Warehouse / Limited access to stock pickings (filtered by sale teams)
          * Default Warehouse / Access to all picking types (filtered by sale teams)
          * Default Warehouse / Access to all pickings (filtered by sale teams)

        - 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 warehouse of the user.
        - 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.

    Module version, description and Spanish translations were updated: missing
    translation template was added. Also the module was modified to follow
    OCA guideline:

    - models in one model file per model/module.

    default_warehouse_from_sale_team: defined 'picking_type_id' default as well from the sale team werahouse

    default_warehouse_from_sale_team: add test to validate pick type from sale team

    default_warehouse_from_sale_team: return limit 1 picking type by defualt to avoid 'Expected singleton' when create record

    default_warehouse_sale_team: add docstring to method

    default_warehouse_from_sale_team: Allow to management that users can see only the journals that match with the sale team

    default_warehouse_from_sale_team: deleted file not used

    apply pylint

    apply pylint

    default_warehouse_from_sale_team: propagate SUPERUSER_ID in read (Vauxoo#1042)

    * [IMP] default_warehouse_from_sale_team: propagate SUPERUSER_ID in read
    when user create from sale pickings chained in another warehouse without
    access to read.
    * [IMP] default_warehouse_from_sale_team: adapt to old and new api read
    * [IMP] default_warehouse_from_sale_team: adapt read to use has_group to
    validate in what user required SUPERUSER_ID.

    default_warehouse_from_sale_team: added rule to allow to see own warehouse by sale team

    default_warehouse_from_sale_team: Adding test unit for validation in policy from sale (Vauxoo#1064)

    * [IMP] default_warehouse_from_sale_team: add journal stock from sale team
    in journal entries of stock valuation
    * [ADD] validation police from sale order defined in sale team warehouse

    default_warehouse_from_sale_team: Move fields default_warehouse… (Vauxoo#1066)

    * [REF] default_warehouse_from_sale_team: Move fields default_warehouse and journal_team_ids to new page Settings warehouse from sale team.

    * [REF] default_warehouse_from_sale_team: Move field journal_stock_id to new page Settings warehouse from sale team.

    * [ADD] default_warehouse_from_sale_team: Adapt traslation.

    * [FIX] default_warehouse_from_sale_team: Fix pylint.

    default_warehouse_from_sale_team: Change field journal_team_ids to one2many. [ADD] default_warehouse_from_sale_team: Add field section_id in account_invoice model to reference sale teams.

    default_warehouse_from_sale_team: in order to allow search and see all record from fields remove selection widget to use origianl widget

    default_warehose_from_sale_team: Modify search of warehouse from the move

    Adding stock_picking_type.warehouse_id field to generate the policy while
    taking into consideration, the warehouse

    default_warehouse_from_sale_team: Modified view_picking_type_form view

    Adding attribute required in warehouse field

    default_warehouse_from_sale_team: adapt class to allow get sequence in base to sale tema in models like: * sale.order * purchase.order * purchase.requisition

    default_warehouse_from_sale_team: change data demo from data to demo

    addons-vauxoo: add disable message by duplicate methods

    default_warehouse_from_sale_team: Modified updated dictionary from super

    Modified updated dictionary from super method because warehouse_id default

    default_warehouse_from_sale_team: Modified updated dictionary from super

    Revert modified updated dictionary from super method because warehouse_id
    default

    default_warehouse_from_sale_team: add priority to get warehouse from warehouse of picking type of stock move because warehouse_id of stock move can be another different by stock move propagated like re-supply move from another warehouse

    default_warehouse_from_sale_team: get picking type from picking of move

    [IMP] default_warehouse_from_sale_team: migration to version11.0

[IMP] default_warehouse_from_sales_team: remove file unnecessary

[IMP] default_warehouse_from_sales_team: remove method read unnecessary
…nce (Vauxoo#1290)

* [ADD] default_warehouse_from_sale_team: Update get_id method in sequence

* [ADD] default_warehouse_from_sale_team: Access Rule
By merging the two Spanish language translation files we are
solving the issue of duplicated terms on the translations of this
module.
Also changing some of the messages and translations of this module.
And increasing the module version for this major change.
And deleting a term that is not need it.
When a user is created without a default sales team or if a user is
being deleted the field `sale_team_id` will be set to False, the
constraint will fail since the value False is not on the `sale_team_ids`
list.
This change simplifies the code and avoids bad practices
This removes:
- Hencoding headers, fixing lint `utf8-coding-comment`
- Headers like `# Part of Odoo`
- And other ones
The following is performed:
- Replace account invoice model by account move
- import openerp -> import odoo
- Fix class names
- Fix indentation in data files
- Adapt tests

Co-Authored-By: José Suniaga [Vauxoo] <[email protected]>
The sequence is calling two times, one from original model and
another from 'default.warehouse' inherit, this fix avoid the
re-call to next_sequence number if it was called previously,
this is just by checking if the name has been already set.

Before:
- Current Purchase Order P00039, next P000041.

Now:
- Current Purchase Order P00041, next P00042.
Using `sudo()` to avoid creating `ir.model.access` but allowing all the
users with access to create a purchase order using the default
warehouse.
Odoo now provides a native way to specify a default warehouse on the
user. So this module uses the same behavior, but giving priority if a
warehouse is set on the sales team.

Other tasks are also performed:
- Code and views are reorganized by model
- Models that were actually mixings are renamed to use the `mixing` suffix
- Test are improved to use the `Form` class
- Some Typos are fixed
- General code clean up
Adding to the rule `rule_default_warehouse_journal` an `or` if the
journal doesn't have its field `section_id` set.

Also, improving the domains of the rules to avoid list comprehensions
using the mapped for related fields.
Automatic sequence numbering was not working in 14.0. For instance, now
purchase requisitions have different sequence codes, depending on
their types.
Field name for default warehouse on sales teams was missing the proper
suffix on previous versions of this module.

This implements a migration script so the database column is renamed
when we're coming from previous versions.
…house

When the partner is changed in a sale order, the current user's sales
team and warehouse should have priority over other ones.
When a stock movement triggers an inventory rule that involves another
warehouse on which the current user has no access, an access error is
triggered. That's because, thanks to this module, users can only see
warehouses allowed in their sales teams.

To solve the above, access is granted to all warehouses when computing
inventory rules to apply.
Currently, when creating a customer invoice, a default journal is set
if it's configured in the sales team. However, that feature only works
for customer invoices but not for vendor bills.

This change implements the default journal feature also for vendor
bills.

In addition, now company and currency are also considered when
computing default journal, for more accurate results.
Which was causing list of contributors to not be correctly rendered.
Improving the message of the `sale_team_id` constraint, also, changing
the `string` and `help` of the `sale_team_ids` field because is not
readonly and the allowed teams should be set that field.
rolandojduartem and others added 21 commits January 28, 2025 17:40
…arehouses not allowed on current user's sales teams

As part of migration to 15.0 of default_warehouse_from_sale_team and
default_warehouse_from_sale_team_jit, the dependency procurement_jit was removed
(odoo/odoo@a838f2a). This change caused
that default_warehouse_from_sale_team_jit
(https://github.com/Vauxoo/addons-vauxoo/tree/14.0/default_warehouse_from_sale_team_jit)
be deprecated on Odoo v15.0 and the main function of that model can be added in
default_warehouse_from_sale_team.
So the CoA is available, which is required for valuation to work.
The method '_search_default_journal' was modified natively on [1], so it
was modified in this module too, also, the method 'create' must be
applied on batches.

References:
[1] odoo/odoo@d8d47f9
…at create

The self in the method create inheritance could be not empty, for example, using
a recordset.copy(), in that case the self is not empty.

Using the self.browse(), we will ensure that the self is empty, and the
split create calls are made as expected.
This runs the translations autoformatter [1], which performs the
following changes over .po files:
- Sort terms alphabetically
- Split lines to 78 characters
- clear message when translated term is the same as original one

This is done to produce a file as if it were re-exported from Odoo. For
more info, see [2].

[1] OCA/odoo-pre-commit-hooks#76
[2] Vauxoo/pre-commit-vauxoo#104
Change the method previously used as a default value for the journal_id
to retrieve the default journal to the new method defined to search the
default journal.
- Adapt the use of name_get as part of [1].
- Change qty_done to quantity and picked = True as part of [2].

[1] odoo/odoo#122085
[2] odoo/odoo#137864
… rule when there is no warehouse parameter, like when is done by stock rules when the move destination location is for a different company https://github.com/Vauxoo/odoo/blob/8af8846c88bd04bcf3fa0bcbe4a720b415f994a4/addons/stock/models/stock_move.py#L830
Implement a hook to fill allowed sales teams in users that are already
a member 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.
We allow to bypass record rules related to sales teams when confirming
a  sale order, so deliveries may be created even if the involved routes
belong to other warehouses the current user has no access to.

This commit allows to extend those rules.
There was a rule to grant read-only access to pickings. However, the
correct way to grant read-only access to a model is to uncheck the
"Read" field on the desired rule, which would cause that rule to not be
considered when verifying accesses.
Limited users are able to see some pickings in readonly mode, but there
were some usability issues that are fixed in this commit:
- It was possible to mark as TODo and check availability, because those
  actions don't require write access to the pickings. This is fixed by
  hiding involved buttons.
- Even though validating a picking does require access, it's also hidden
  because there's no point on showing a button that can't be used anyway.
- Similarly, the Print button is also hidden when the picking is not
  done yet, because it requires access to mark the picking as printed.
- The Return button is also hidden. Even though it doesn't require
  write access to the current picking, it will require creation access
  on the new picking.
- The Cancel button is not hidden because it requires being inventory
  administrator, which is not compatible with being a limited user.
… default journal set

Use the cached value of the Sales Team field to access its value as a
record. This avoids computing its value when it has not been computed
yet, which could result in setting the wrong Sales Team on an invoice
form creation. This issue occurs because the company is not yet set, and
its value is required to determine the correct Sales Team [1].

[1]: https://github.com/odoo/odoo/blob/3884a60e/addons/sale/models/account_move.py#L41
… record exists

Add a validation to avoid errors when accessing the cache without a
record. The change ensures that the `team_id` value is only retrieved
from the cache when a valid `account.move` record exists.
@IrvingReyes IrvingReyes changed the title [MIG] default_warehouse_from_sale_team 18.0 mig default warehouse from sale team irvingreyes T#87470 [MIG] default_warehouse_from_sale_team: default warehouse from sale team irvingreyes T#87470 Jan 29, 2025
@IrvingReyes IrvingReyes changed the title [MIG] default_warehouse_from_sale_team: default warehouse from sale team irvingreyes T#87470 [MIG] default_warehouse_from_sale_team: Migration to 18.0 T#87470 Jan 29, 2025
@IrvingReyes IrvingReyes force-pushed the 18.0-mig-default-warehouse-from-sale-team-irvingreyes branch from 80a3404 to 3d888b8 Compare January 29, 2025 20:15
@IrvingReyes
Copy link
Author

@rolandojduartem Please review.

@rolandojduartem
Copy link
Contributor

Man, this is PR is going to 17.0, could you change it, please

@luisg123v luisg123v self-requested a review January 30, 2025 22:37
Copy link
Contributor

@luisg123v luisg123v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fill the commit description, please?

To mention performed changes and provide references.

#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0+e\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please regenerate translation file.

`here <https://github.com/Vauxoo/addons-vauxoo/issues/new?body=module:%20
default_warehouse_from_sale_team
%0Aversion:%20
15.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

18.0

Check other references.

"sale_stock",
"purchase_requisition",
],
"test": [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This key is deprecated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.