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

[16.0][MIG] chained_swapper: Migration to 16.0 #691

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
97cacbd
[ADD] chained_swapper: new module
Aug 12, 2020
fcb3d8f
[FIX+IMP] chained_swapper: Make constraints to work + refinements
pedrobaeza Aug 14, 2020
a612c42
[IMP] chained_swapper: `env`, `date` and `datetime` in constraint exp…
Aug 15, 2020
32a86b4
[FIX] chained_swapper: Avoid singleton error to update records
sergio-teruel Aug 31, 2020
6503ab7
[IMP] chained_swapper: black, isort, prettier
Jan 18, 2021
fe5ffe4
[MIG] chained_swapper: Migration to 13.0
Jan 18, 2021
2dcf55a
[UPD] Update chained_swapper.pot
oca-travis Jan 23, 2021
5761525
[IMP] chained_swapper: black, isort, prettier
schhatbar-initos Feb 25, 2021
5827a53
[14.0][MIG] chained_swapper
schhatbar-initos Feb 25, 2021
da05810
[UPD] Update chained_swapper.pot
oca-travis Jul 21, 2021
0ff7686
MIG] chained_swapper: Migration to 15.0
cesar-tecnativa Jun 6, 2022
4df86d5
[UPD] Update chained_swapper.pot
Jul 1, 2022
bd26015
[UPD] README.rst
OCA-git-bot Jul 1, 2022
8f865a6
[FIX] chained_swapper - search chain field with correct model
enriquemartin Mar 11, 2022
2f0ed5b
[FIX] chained_swapper: Change SavepointCase to TransactionCase
victoralmau Nov 23, 2022
d6ccbd5
[FIX] chained_swapper: Change load_lang method to _activate_lang to p…
victoralmau Nov 23, 2022
dcc97a2
chained_swapper 15.0.1.0.2
OCA-git-bot Nov 24, 2022
f319f28
Translated using Weblate (Italian)
mymage Jun 7, 2023
b1390ba
[UPD] README.rst
OCA-git-bot Sep 3, 2023
054c589
Update translation files
weblate Oct 10, 2023
3948442
[IMP] chained_swapper: test performance improvement
josep-tecnativa Oct 25, 2023
b1e9567
[BOT] post-merge updates
OCA-git-bot Oct 25, 2023
df1bcd0
[FIX] chained_swapper: Pylint
etobella Oct 28, 2023
9342914
[BOT] post-merge updates
OCA-git-bot Oct 28, 2023
0597084
[IMP] chained_swapper: pre-commit stuff
kaynnan Nov 12, 2023
cbad58f
[MIG] chained_swapper: Migration to 16.0
kaynnan Nov 12, 2023
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
143 changes: 143 additions & 0 deletions chained_swapper/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
===============
Chained Swapper
===============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:efe2db6be950b62445f15132e77f74fc17b5c02a80a5f268899de70636553feb
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png
:target: https://odoo-community.org/page/development-status
:alt: Mature
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github
:target: https://github.com/OCA/server-ux/tree/16.0/chained_swapper
:alt: OCA/server-ux
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-ux-16-0/server-ux-16-0-chained_swapper
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-ux&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to swap the value of a field and propagate it in a chained
way to linked records. Example: changing the delivery address in a confirmed
sales order, it should be changed in its delivery orders as well.

It also allows to apply constraints for not allowing to do that change
according rules, so the business logic is not broken. Example: Don't allow
to change the delivery address if the delivery order is validated.

This module requires some technical knowledge for setting the chained swap and
the constraint, as it's defined through technical names and Python code.

**WARNING**: Use this module with care, as it can screw up database consistency
if swaps are not properly designed .

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module, you need to:

#. Go to *Setting > Field Swaps > Field Swaps*.
#. Create a new object and set the following data as an example:

* Name for identifying it and use it for the action name.
* Select the source model where the swap will be started.
* Select the starting field for which the swap will be done.
* Add several chained fields. They are expressed as a string using
dot notation, taking the source model as beginning for looking there
the first field, and continuing from there drilling through. Example:
`picking_ids.partner_id` for `sale.order` model will go to the linked
deliveries orders, and change the customer there.
* Add possible constraints for restricting the chained swap. They are
Python expressions that must be one line that is evaluated as boolean.
If the evaluation is true, then a message will be thrown and no swap
will be allowed. You can use the variable `records` in your code, that
will be referring the selected records for doing the swap. Example: for
restricting sales orders that have a delivery order validated:

`any(p.state == 'done' for p in records.mapped('picking_ids.state'))`

Other variables you can use are `env`, `date` and `datetime`.
Each constraint has a name for identifying it, but also for showing that
name when displaying the error trying to do the swap.

#. Click on 'Add action' smart button to add a new action in the source model.

On demo databases, you can check the example "Language", that changes the
language of a contact, and propagate it to children contacts.

Usage
=====

To use this module, you need to:

#. Go to the source document in list mode.
#. Select one or several records.
#. Click on Action and locate the option "Chained swap: <name of the swap>".
#. If one of the selected records doesn't comply with one of the constraints,
a message will be shown, and the swap won't continue.
#. If everything is OK, a popup will arise, and you will see a field for
filling the new value.
#. Click on "Change", and the swap will be done.
#. On the chatter of the source document, an entry will be logged for
reflecting the done swap.

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

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

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Tecnativa

Contributors
~~~~~~~~~~~~

* `Tecnativa <https://www.tecnativa.com>`_:

* Ernesto Tejeda
* Pedro M. Baeza
* César A. Sánchez
* Sunanda Chhatbar <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/16.0/chained_swapper>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions chained_swapper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
from . import wizard
from .hooks import uninstall_hook
20 changes: 20 additions & 0 deletions chained_swapper/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2020 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Chained Swapper",
"summary": "Chained Swapper",
"version": "16.0.1.0.0",
"development_status": "Mature",
"author": "Tecnativa, Odoo Community Association (OCA)",
"category": "Tools",
"website": "https://github.com/OCA/server-ux",
"license": "AGPL-3",
"depends": ["base"],
"data": [
"security/ir.model.access.csv",
"views/chained_swapper_views.xml",
"wizard/chained_swapper_wizard_views.xml",
],
"demo": ["demo/chained_swapper_demo.xml"],
"uninstall_hook": "uninstall_hook",
}
44 changes: 44 additions & 0 deletions chained_swapper/demo/chained_swapper_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2020 Tecnativa - Ernesto Tejeda
Copyright 2020 Tecnativa - Pedro M. Baeza
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">
<!--Add a chained swapper-->
<record id="chained_swapper_demo" model="chained.swapper">
<field name="name">Language</field>
<field name="model_id" ref="base.model_res_partner" />
<field name="field_id" ref="base.field_res_partner__lang" />
</record>
<record id="chained_swapper_sub_field_demo" model="chained.swapper.sub.field">
<field name="chained_swapper_id" ref="chained_swapper_demo" />
<field name="sub_field_chain">child_ids.lang</field>
</record>
<record id="chained_swapper_constraint_demo" model="chained.swapper.constraint">
<field name="chained_swapper_id" ref="chained_swapper_demo" />
<field name="name">Only parent company</field>
<field name="expression">bool(records.mapped('parent_id'))</field>
</record>
<!--Add an action-->
<record id="partner_chained_swap_lang_action_demo" model="ir.actions.act_window">
<field name="name">Chained swap: Language</field>
<field name="res_model">chained.swapper.wizard</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="binding_model_id" ref="base.model_res_partner" />
<field name="binding_view_types">form</field>
<field
name="context"
eval="{
'chained_swapper_id': ref('chained_swapper_demo'),
}"
/>
</record>
<!-- oca-hooks:disable=xml-duplicate-record-id -->
<!-- pylint:disable=duplicate-xml-record-id -->
<record id="chained_swapper_demo" model="chained.swapper">
<field
name="ref_ir_act_window_id"
ref="partner_chained_swap_lang_action_demo"
/>
</record>
</odoo>
14 changes: 14 additions & 0 deletions chained_swapper/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2020 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.api import SUPERUSER_ID, Environment


def uninstall_hook(cr, registry):
"""Delete the actions that were created with chained_swapper when
the module is uninstalled"""
env = Environment(cr, SUPERUSER_ID, {})
env["ir.actions.act_window"].search(
[("res_model", "=", "chained.swapper.wizard")]
).unlink()
return True
Loading
Loading