Skip to content

Commit

Permalink
[IMP] product_variant_default_code: pre-commit auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arantxa-s73 committed Oct 16, 2024
1 parent d70bc2a commit 3f613b0
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 250 deletions.
140 changes: 75 additions & 65 deletions product_variant_default_code/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Product Variant Default Code
============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0e25d0e9019dd6cfa4182b1688957555fc576f90f64d7a26c2cb9294253b5455
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
Expand All @@ -14,35 +17,36 @@ Product Variant Default Code
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github
:target: https://github.com/OCA/product-variant/tree/16.0/product_variant_default_code
:target: https://github.com/OCA/product-variant/tree/17.0/product_variant_default_code
:alt: OCA/product-variant
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-variant-16-0/product-variant-16-0-product_variant_default_code
:target: https://translation.odoo-community.org/projects/product-variant-17-0/product-variant-17-0-product_variant_default_code
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/137/16.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-variant&target_branch=17.0
:alt: Try me on Runboat

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

This module automatically generate Product Reference (default_code)
according to attributes data with a configurable behavior.

It defines a reference mask on the product templates so the
variants references are automatically set. For example:
It defines a reference mask on the product templates so the variants
references are automatically set. For example:

- Product template: Jacket
- Attributes:
- Color: White, Black
- Size: M, L
- Reference mask: `JKT01-[Color]-[Size]`
- Product template: Jacket
- Attributes:

- Reference on variants:
- Color: White, Black
- Size: M, L

- `JKT01-Wh-M` Jacket White M
- `JKT01-Bl-M` Jacket Black M
- `JKT01-Wh-L` Jacket White L
- `JKT01-Bl-L` Jacket Black L
- Reference mask: JKT01-[Color]-[Size]
- Reference on variants:

- JKT01-Wh-M Jacket White M
- JKT01-Bl-M Jacket Black M
- JKT01-Wh-L Jacket White L
- JKT01-Bl-L Jacket Black L

**Table of contents**

Expand All @@ -52,96 +56,102 @@ variants references are automatically set. For example:
Usage
=====

To set the reference mask up on any product template 'Variant reference mask'
new field.
To set the reference mask up on any product template 'Variant reference
mask' new field.

When creating a new product template without specifying the *Variant reference
mask*, a default value for *Variant reference mask* will be automatically
generated according to the attribute line settings on the product template (if
any). The mask will then be used as an instruction to generate default code of
each product variant of the product template with the corresponding *Attribute
Code* (of the attribute value) inserted. Besides the default value, *Variant
reference mask* can be configured to your liking, make sure putting the
*Attribute Name* inside `[]` marks (it is case sensitive).
When creating a new product template without specifying the *Variant
reference mask*, a default value for *Variant reference mask* will be
automatically generated according to the attribute line settings on the
product template (if any). The mask will then be used as an instruction
to generate default code of each product variant of the product template
with the corresponding *Attribute Code* (of the attribute value)
inserted. Besides the default value, *Variant reference mask* can be
configured to your liking, make sure putting the *Attribute Name* inside
[] marks (it is case sensitive).

Example:

Creating a product named *Jacket* with two attributes, *Size* and *Color*::
Creating a product named *Jacket* with two attributes, *Size* and
*Color*:

::

Product: Jacket
Color: Black(Bl), White(Wh) # Black and White are the attribute values;
'Bl' and 'Wh' are the corresponding codes
Size: L (L), XL(XL)

The automatically generated default value for the Variant reference mask will
be `[Color]-[Size]` and so the 'default code' on the variants will be `Bl-L`,
`Wh-L`, `Bl-XL` and `Wh-XL`.
The automatically generated default value for the Variant reference mask
will be [Color]-[Size] and so the 'default code' on the variants will be
Bl-L, Wh-L, Bl-XL and Wh-XL.

The mask value can be fully customized whatever you like. You can even have
the attribute name appear more than once in the mask such as,
`Jacket/[Size]~[Color]~[Size]`, and the generated code on variants will be
something like `Jacket/L~Bl~L` (for variant with Color "Black" and Size "L").
The mask value can be fully customized whatever you like. You can even
have the attribute name appear more than once in the mask such as,
Jacket/[Size]~[Color]~[Size], and the generated code on variants will be
something like Jacket/L~Bl~L (for variant with Color "Black" and Size
"L").

When the code attribute is changed, it automatically regenerates the 'default
code' on all variants affected.
When the code attribute is changed, it automatically regenerates the
'default code' on all variants affected.

Aditionally, a product attribute can be set and so it will be appended to the
product `default_code`. In the first example, setting a `Color` code to `CO`
would give `default_code` like this: `COBl-L`, `COWh-L`, `COBl-XL` and
`COWh-XL`.
Aditionally, a product attribute can be set and so it will be appended
to the product default_code. In the first example, setting a Color code
to CO would give default_code like this: COBl-L, COWh-L, COBl-XL and
COWh-XL.

Avoiding mask in variants
~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------

You can avoid this behavior or force a manual default_code on variant. To do
so, go to *Product Variants > [any variant you want to set up]* and set
manually its reference code. The field `manual code` will be set to on and the
variant internal reference will no longer be changed by this module.
You can avoid this behavior or force a manual default_code on variant.
To do so, go to *Product Variants > [any variant you want to set up]*
and set manually its reference code. The field manual code will be set
to on and the variant internal reference will no longer be changed by
this module.

Unset `manual code` and the reference code will be unlocked again.
Unset manual code and the reference code will be unlocked again.

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

* In case of attribute name update, related mask are not updated.
- In case of attribute name update, related mask are not updated.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-variant/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 <https://github.com/OCA/product-variant/issues/new?body=module:%20product_variant_default_code%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/product-variant/issues/new?body=module:%20product_variant_default_code%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
~~~~~~~
-------

* AvancOSC
* Shine IT
* Tecnativa
* Akretion

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

* Alfredo de la Fuente <[email protected]>
* Tony Gu <[email protected]>
* David Beal <[email protected]>
* Daniel Campos <[email protected]>
* Kévin Roche <[email protected]>
- Alfredo de la Fuente <[email protected]>
- Tony Gu <[email protected]>
- David Beal <[email protected]>
- Daniel Campos <[email protected]>
- Kévin Roche <[email protected]>
- Tecnativa <tecnativa.com>:

* Tecnativa <tecnativa.com>:
* David Vidal
* Pedro M. Baeza
* João Marques
- David Vidal
- Pedro M. Baeza
- João Marques

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

This module is maintained by the OCA.

Expand All @@ -161,6 +171,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-Kev-Roche|

This module is part of the `OCA/product-variant <https://github.com/OCA/product-variant/tree/16.0/product_variant_default_code>`_ project on GitHub.
This module is part of the `OCA/product-variant <https://github.com/OCA/product-variant/tree/17.0/product_variant_default_code>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 3 additions & 2 deletions product_variant_default_code/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Product Variant Default Code",
"version": "16.0.1.0.2",
"author": "AvancOSC, Shine IT, Tecnativa, Akretion, Odoo Community Association (OCA)",
"version": "17.0.1.0.0",
"author": "AvancOSC, Shine IT, Tecnativa, Akretion, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-variant",
"license": "AGPL-3",
"category": "Product",
Expand Down
4 changes: 2 additions & 2 deletions product_variant_default_code/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _get_default_mask(self):
main_lang = self._guess_main_lang()
for line in self.attribute_line_ids:
attribute_names.append(
"[{}]".format(line.attribute_id.with_context(lang=main_lang).name)
f"[{line.attribute_id.with_context(lang=main_lang).name}]"
)
default_mask = (self.code_prefix or "") + default_reference_separator.join(
attribute_names
Expand All @@ -162,7 +162,7 @@ def create(self, vals):
vals["reference_mask"] = product._get_default_mask()
elif vals.get("reference_mask"):
sanitize_reference_mask(product, vals["reference_mask"])
return super(ProductTemplate, self).create(vals)
return super().create(vals)

@api.model
def _guess_main_lang(self):
Expand Down
3 changes: 3 additions & 0 deletions product_variant_default_code/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
9 changes: 9 additions & 0 deletions product_variant_default_code/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- Alfredo de la Fuente \<<[email protected]>\>
- Tony Gu \<<[email protected]>\>
- David Beal \<<[email protected]>\>
- Daniel Campos \<<[email protected]>\>
- Kévin Roche \<<[email protected]>\>
- Tecnativa \<tecnativa.com\>:
- David Vidal
- Pedro M. Baeza
- João Marques
10 changes: 0 additions & 10 deletions product_variant_default_code/readme/CONTRIBUTORS.rst

This file was deleted.

16 changes: 16 additions & 0 deletions product_variant_default_code/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This module automatically generate Product Reference (default_code)
according to attributes data with a configurable behavior.

It defines a reference mask on the product templates so the variants
references are automatically set. For example:

- Product template: Jacket
- Attributes:
- Color: White, Black
- Size: M, L
- Reference mask: JKT01-\[Color\]-\[Size\]
- Reference on variants:
- JKT01-Wh-M Jacket White M
- JKT01-Bl-M Jacket Black M
- JKT01-Wh-L Jacket White L
- JKT01-Bl-L Jacket Black L
18 changes: 0 additions & 18 deletions product_variant_default_code/readme/DESCRIPTION.rst

This file was deleted.

1 change: 1 addition & 0 deletions product_variant_default_code/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- In case of attribute name update, related mask are not updated.
1 change: 0 additions & 1 deletion product_variant_default_code/readme/ROADMAP.rst

This file was deleted.

50 changes: 50 additions & 0 deletions product_variant_default_code/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
To set the reference mask up on any product template 'Variant reference
mask' new field.

When creating a new product template without specifying the *Variant
reference mask*, a default value for *Variant reference mask* will be
automatically generated according to the attribute line settings on the
product template (if any). The mask will then be used as an instruction
to generate default code of each product variant of the product template
with the corresponding *Attribute Code* (of the attribute value)
inserted. Besides the default value, *Variant reference mask* can be
configured to your liking, make sure putting the *Attribute Name* inside
\[\] marks (it is case sensitive).

Example:

Creating a product named *Jacket* with two attributes, *Size* and
*Color*:

Product: Jacket
Color: Black(Bl), White(Wh) # Black and White are the attribute values;
'Bl' and 'Wh' are the corresponding codes
Size: L (L), XL(XL)

The automatically generated default value for the Variant reference mask
will be \[Color\]-\[Size\] and so the 'default code' on the variants
will be Bl-L, Wh-L, Bl-XL and Wh-XL.

The mask value can be fully customized whatever you like. You can even
have the attribute name appear more than once in the mask such as,
Jacket/\[Size\]~\[Color\]~\[Size\], and the generated code on variants
will be something like Jacket/L~Bl~L (for variant with Color "Black" and
Size "L").

When the code attribute is changed, it automatically regenerates the
'default code' on all variants affected.

Aditionally, a product attribute can be set and so it will be appended
to the product default_code. In the first example, setting a Color code
to CO would give default_code like this: COBl-L, COWh-L, COBl-XL and
COWh-XL.

## Avoiding mask in variants

You can avoid this behavior or force a manual default_code on variant.
To do so, go to *Product Variants \> \[any variant you want to set up\]*
and set manually its reference code. The field manual code will be set
to on and the variant internal reference will no longer be changed by
this module.

Unset manual code and the reference code will be unlocked again.
Loading

0 comments on commit 3f613b0

Please sign in to comment.