Skip to content

Commit

Permalink
[IMP] attribute_set: pre-commit auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
damcar committed Dec 4, 2023
1 parent 2808fb1 commit 42f1c20
Show file tree
Hide file tree
Showing 16 changed files with 207 additions and 107 deletions.
96 changes: 65 additions & 31 deletions attribute_set/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,40 @@ Attribute Set
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fodoo--pim-lightgray.png?logo=github
:target: https://github.com/OCA/odoo-pim/tree/16.0/attribute_set
:target: https://github.com/OCA/odoo-pim/tree/17.0/attribute_set
:alt: OCA/odoo-pim
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/odoo-pim-16-0/odoo-pim-16-0-attribute_set
:target: https://translation.odoo-community.org/projects/odoo-pim-17-0/odoo-pim-17-0-attribute_set
: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/odoo-pim&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/odoo-pim&target_branch=17.0
:alt: Try me on Runboat

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

This module allows the user to create Attributes to any model.
This is a basic module in the way that **it does not provide views to display these new Attributes.**
This module allows the user to create Attributes to any model. This is a
basic module in the way that **it does not provide views to display
these new Attributes.**

Each Attribute created will be related to an **existing field** (in case of a *"native"* Attribute) or to a newly **created field** (in case of a *"custom"* Attribute).
Each Attribute created will be related to an **existing field** (in case
of a *"native"* Attribute) or to a newly **created field** (in case of a
*"custom"* Attribute).

A *"custom"* Attribute can be of any type : Char, Text, Boolean, Date, Binary... but also Many2one or Many2many.
A *"custom"* Attribute can be of any type : Char, Text, Boolean, Date,
Binary... but also Many2one or Many2many.

In case of m2o or m2m, these attributes can be related to **custom options** created for the Attribute, or to **existing Odoo objects** from other models.
In case of m2o or m2m, these attributes can be related to **custom
options** created for the Attribute, or to **existing Odoo objects**
from other models.

Last but not least an Attribute can be **serialized** using the Odoo SA module `base_sparse_field <https://github.com/odoo/odoo/tree/16.0/addons/base_sparse_field>`_ .
It means that all the serialized attributes will be stored in a single "JSON serialization field" and will not create new columns in the database (and better, it will not create new SQL tables in case of Many2many Attributes), **increasing significantly the requests speed** when dealing with thousands of Attributes.
Last but not least an Attribute can be **serialized** using the Odoo SA
module
`base_sparse_field <https://github.com/odoo/odoo/tree/16.0/addons/base_sparse_field>`__
. It means that all the serialized attributes will be stored in a single
"JSON serialization field" and will not create new columns in the
database (and better, it will not create new SQL tables in case of
Many2many Attributes), **increasing significantly the requests speed**
when dealing with thousands of Attributes.

**Table of contents**

Expand All @@ -48,54 +60,76 @@ It means that all the serialized attributes will be stored in a single "JSON ser
Usage
=====

Even if this module does not provide views to display some model's Attributes, it provides however a Technical menu in *Settings > Technical > Database Structure > Attributes* to **create new Attributes**.
Even if this module does not provide views to display some model's
Attributes, it provides however a Technical menu in *Settings >
Technical > Database Structure > Attributes* to **create new
Attributes**.

An Attribute is related to both an Attribute Group and an Attribute Set :
An Attribute is related to both an Attribute Group and an Attribute Set
:

- The **Attribute Set** is related to the *"model's category"*, i.e. all the model's instances which will display the same Attributes.
- The **Attribute Group** is related to the *"attribute's category"*. All the attributes from the same Attribute Set and Attribute Group will be displayed under the same field's Group in the model's view.
- The **Attribute Set** is related to the *"model's category"*, i.e.
all the model's instances which will display the same Attributes.

- The **Attribute Group** is related to the *"attribute's category"*.
All the attributes from the same Attribute Set and Attribute Group
will be displayed under the same field's Group in the model's view.

🔎 In order to create a custom Attribute many2one or many2many related to **other Odoo model**, you need to activate the Technical Setting **"Advanced Attribute Set settings"** (:code:`group_advanced_attribute_set`).
🔎 In order to create a custom Attribute many2one or many2many
related to **other Odoo model**, you need to activate the
Technical Setting **"Advanced Attribute Set settings"**
(``group_advanced_attribute_set``).

-----
--------------

If you want to create a module displaying some specific model's
Attributes :

1. Your model must **\_inherit the mixin**
``"attribute.set.owner.mixin"``
2. You need to **add a placeholder**
``<separator name="attributes_placeholder" />`` at the desired
location in the model's form view.
3. Finally, **add a context** ``{"include_native_attribute": True}`` on
the action leading to this form view if the model's view needs to
display attributes related to native fields together with the other
"custom" attributes.

Known issues / Roadmap
======================

If you want to create a module displaying some specific model's Attributes :

1. Your model must **\_inherit the mixin** :code:`"attribute.set.owner.mixin"`
2. You need to **add a placeholder** :code:`<separator name="attributes_placeholder" />` at the desired location in the model's form view.
3. Finally, **add a context** :code:`{"include_native_attribute": True}` on the action leading to this form view if the model's view needs to display attributes related to native fields together with the other "custom" attributes.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/odoo-pim/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/odoo-pim/issues/new?body=module:%20attribute_set%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/odoo-pim/issues/new?body=module:%20attribute_set%0Aversion:%2017.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
~~~~~~~
-------

* Akretion

Contributors
~~~~~~~~~~~~
------------

* Sébastien BEAU <[email protected]>
* Clément Mombereau <[email protected]>
* Benoît Guillot <[email protected]>
* Akretion Raphaël VALYI <[email protected]>
* David Dufresne <[email protected]>
* Denis Roussel <[email protected]>
- Sébastien BEAU <[email protected]>
- Clément Mombereau <[email protected]>
- Benoît Guillot <[email protected]>
- Akretion Raphaël VALYI <[email protected]>
- David Dufresne <[email protected]>
- Denis Roussel <[email protected]>

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -107,6 +141,6 @@ 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/odoo-pim <https://github.com/OCA/odoo-pim/tree/16.0/attribute_set>`_ project on GitHub.
This module is part of the `OCA/odoo-pim <https://github.com/OCA/odoo-pim/tree/17.0/attribute_set>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 2 additions & 2 deletions attribute_set/models/attribute_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def _build_attribute_eview(self):
att_group = attribute.attribute_group_id
att_group_name = att_group.name.capitalize()
if att_group in groups:
xpath = ".//group[@string='{}']".format(att_group_name)
xpath = f".//group[@string='{att_group_name}']"
attribute_egroup = attribute_eview.find(xpath)
else:
att_set_ids = []
Expand All @@ -212,7 +212,7 @@ def _build_attribute_eview(self):
"group",
string=att_group_name,
colspan="2",
attrs="{{'invisible' : {} }}".format(hide_domain),
attrs=f"{{'invisible' : {hide_domain} }}",
)
groups.append(att_group)

Expand Down
2 changes: 1 addition & 1 deletion attribute_set/models/attribute_set_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def remove_native_fields(self, eview):
]
)
for attr in native_attrs:
efield = eview.xpath("//field[@name='{}']".format(attr.name))
efield = eview.xpath(f"//field[@name='{attr.name}']")
if len(efield):
efield[0].getparent().remove(efield[0])

Expand Down
3 changes: 3 additions & 0 deletions attribute_set/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
6 changes: 6 additions & 0 deletions attribute_set/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- Sébastien BEAU \<<[email protected]>\>
- Clément Mombereau \<<[email protected]>\>
- Benoît Guillot \<<[email protected]>\>
- Akretion Raphaël VALYI \<<[email protected]>\>
- David Dufresne \<<[email protected]>\>
- Denis Roussel \<<[email protected]>\>
6 changes: 0 additions & 6 deletions attribute_set/readme/CONTRIBUTORS.rst

This file was deleted.

23 changes: 23 additions & 0 deletions attribute_set/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
This module allows the user to create Attributes to any model. This is a
basic module in the way that **it does not provide views to display
these new Attributes.**

Each Attribute created will be related to an **existing field** (in case
of a *"native"* Attribute) or to a newly **created field** (in case of a
*"custom"* Attribute).

A *"custom"* Attribute can be of any type : Char, Text, Boolean, Date,
Binary... but also Many2one or Many2many.

In case of m2o or m2m, these attributes can be related to **custom
options** created for the Attribute, or to **existing Odoo objects**
from other models.

Last but not least an Attribute can be **serialized** using the Odoo SA
module
[base_sparse_field](https://github.com/odoo/odoo/tree/16.0/addons/base_sparse_field)
. It means that all the serialized attributes will be stored in a single
"JSON serialization field" and will not create new columns in the
database (and better, it will not create new SQL tables in case of
Many2many Attributes), **increasing significantly the requests speed**
when dealing with thousands of Attributes.
11 changes: 0 additions & 11 deletions attribute_set/readme/DESCRIPTION.rst

This file was deleted.

1 change: 1 addition & 0 deletions attribute_set/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file removed attribute_set/readme/ROADMAP.rst
Empty file.
34 changes: 34 additions & 0 deletions attribute_set/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Even if this module does not provide views to display some model's
Attributes, it provides however a Technical menu in *Settings \>
Technical \> Database Structure \> Attributes* to **create new
Attributes**.

An Attribute is related to both an Attribute Group and an Attribute Set
:

- The **Attribute Set** is related to the *"model's category"*, i.e. all
the model's instances which will display the same Attributes.

- The **Attribute Group** is related to the *"attribute's category"*.
All the attributes from the same Attribute Set and Attribute Group
will be displayed under the same field's Group in the model's view.

> 🔎 In order to create a custom Attribute many2one or many2many
> related to **other Odoo model**, you need to activate the Technical
> Setting **"Advanced Attribute Set settings"**
> (`group_advanced_attribute_set`).
------------------------------------------------------------------------

If you want to create a module displaying some specific model's
Attributes :

1. Your model must **\_inherit the mixin**
`"attribute.set.owner.mixin"`
2. You need to **add a placeholder**
`<separator name="attributes_placeholder" />` at the desired
location in the model's form view.
3. Finally, **add a context** `{"include_native_attribute": True}` on
the action leading to this form view if the model's view needs to
display attributes related to native fields together with the other
"custom" attributes.
17 changes: 0 additions & 17 deletions attribute_set/readme/USAGE.rst

This file was deleted.

Loading

0 comments on commit 42f1c20

Please sign in to comment.