diff --git a/product_sequence/README.rst b/product_sequence/README.rst index 648df785d83d..a087c84030aa 100644 --- a/product_sequence/README.rst +++ b/product_sequence/README.rst @@ -1,27 +1,40 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 - ================ Product Sequence ================ +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |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%2Fproduct--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/12.0/product_sequence + :alt: OCA/product-attribute +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-attribute-12-0/product-attribute-12-0-product_sequence + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/135/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + This module allows to associate a sequence to the product reference. The reference (default code) is unique (SQL constraint) and required. You can optionally specify different sequences for different product categories. -Installation -============ - -Prior to installing this module, if you have any existing products you should -ensure they already have a unique reference (or no reference) set. Products -with a default_code of '/' or empty will automatically be assigned a code of -"!!mig!!" followed by the system id for that product. +**Table of contents** -Otherwise the setting of the unique constraint will fail and the module will -fail to install. +.. contents:: + :local: Usage ===== @@ -41,39 +54,45 @@ To specify a different sequence for a product category proceed as follows: Bug Tracker =========== -Bugs are tracked on `GitHub 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. +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* Zikzakmedia SL +* Sodexis Contributors ------------- +~~~~~~~~~~~~ * Angel Moya * Graeme Gellatly * Sodexis * Lois Rilo * Sudhir Arya +* Alexandre Díaz -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - 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. -To contribute to this module, please visit https://odoo-community.org. +This module is part of the `OCA/product-attribute `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_sequence/__openerp__.py b/product_sequence/__openerp__.py index 72028ab6a638..637f68bbdb85 100644 --- a/product_sequence/__openerp__.py +++ b/product_sequence/__openerp__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2004 Tiny SPRL # Copyright 2016 Sodexis # Copyright 2018 Eficent Business and IT Consulting Services S.L. @@ -14,6 +13,7 @@ 'category': 'Product', 'depends': [ 'product', + 'product_code_unique', ], 'data': [ 'data/product_sequence.xml', diff --git a/product_sequence/models/product_product.py b/product_sequence/models/product_product.py index 9a5b4894c3b2..bdc6c6d314cc 100644 --- a/product_sequence/models/product_product.py +++ b/product_sequence/models/product_product.py @@ -18,12 +18,6 @@ class ProductProduct(models.Model): "to be proposed." ) - _sql_constraints = [ - ('uniq_default_code', - 'unique(default_code)', - 'The reference must be unique'), - ] - @api.model def create(self, vals): if 'default_code' not in vals or vals['default_code'] == '/': @@ -42,7 +36,7 @@ def create(self, vals): if not sequence: sequence = self.env.ref('product_sequence.seq_product_auto') vals['default_code'] = sequence.next_by_id() - return super(ProductProduct, self).create(vals) + return super().create(vals) @api.multi def write(self, vals): @@ -50,11 +44,12 @@ def write(self, vals): Note this is up to the user, if the product category is changed, she/he will need to write '/' on the internal reference to force the re-assignment.""" - for product in self: - if vals.get('default_code', '') == '/': + if vals.get('default_code', '') == '/': + product_category_obj = self.env['product.category'] + for product in self: category_id = vals.get('categ_id', product.categ_id.id) - category = self.env['product.category'].browse(category_id) - sequence = category.sequence_id + category = product_category_obj.browse(category_id) + sequence = category.exists() and category.sequence_id if not sequence: sequence = self.env.ref( 'product_sequence.seq_product_auto') @@ -62,8 +57,9 @@ def write(self, vals): vals['default_code'] = ref if len(product.product_tmpl_id.product_variant_ids) == 1: product.product_tmpl_id.write({'default_code': ref}) - super(ProductProduct, product).write(vals) - return True + super(ProductProduct, product).write(vals) + return True + return super().write(vals) @api.multi def copy(self, default=None): @@ -73,4 +69,4 @@ def copy(self, default=None): default.update({ 'default_code': self.default_code + _('-copy'), }) - return super(ProductProduct, self).copy(default) + return super().copy(default) diff --git a/product_sequence/readme/CONTRIBUTORS.rst b/product_sequence/readme/CONTRIBUTORS.rst index 0d3a12bdc341..aee3584f99f2 100644 --- a/product_sequence/readme/CONTRIBUTORS.rst +++ b/product_sequence/readme/CONTRIBUTORS.rst @@ -3,3 +3,4 @@ * Sodexis * Lois Rilo * Sudhir Arya +* Alexandre Díaz diff --git a/product_sequence/static/description/index.html b/product_sequence/static/description/index.html new file mode 100644 index 000000000000..90782f6c5bb4 --- /dev/null +++ b/product_sequence/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Product Sequence + + + +
+

Product Sequence

+ + +

Beta License: AGPL-3 OCA/product-attribute Translate me on Weblate Try me on Runbot

+

This module allows to associate a sequence to the product reference. +The reference (default code) is unique (SQL constraint) and required.

+

You can optionally specify different sequences for different product +categories.

+

Table of contents

+ +
+

Usage

+

To specify a different sequence for a product category proceed as follows:

+
    +
  1. Go to the a Product Category form view. +(note: you will need to install Inventory app to be able to access to +the form view, Inventory > Configuration > Products > Products Categories; +or create a menuitem manually).
  2. +
  3. Fill the Prefix for Product Internal Reference as desired.
  4. +
+Try me on Runbot +
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Zikzakmedia SL
  • +
  • Sodexis
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/product-attribute project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/product_sequence/tests/test_product_sequence.py b/product_sequence/tests/test_product_sequence.py index bae42528d87b..c79736d044ea 100644 --- a/product_sequence/tests/test_product_sequence.py +++ b/product_sequence/tests/test_product_sequence.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016 Sodexis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).