Skip to content

Commit

Permalink
[IMP] product_sequence: Suggested PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tardo committed Sep 27, 2019
1 parent 668d507 commit 231a83b
Show file tree
Hide file tree
Showing 6 changed files with 498 additions and 42 deletions.
71 changes: 45 additions & 26 deletions 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
=====
Expand All @@ -41,39 +54,45 @@ To specify a different sequence for a product category proceed as follows:
Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/product-attribute/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 <https://github.com/OCA/product-attribute/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-attribute/issues/new?body=module:%20product_sequence%0Aversion:%2012.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
=======

Images
------
Authors
~~~~~~~

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
* Zikzakmedia SL
* Sodexis

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

* Angel Moya <angel.moya@domatix.com>
* Graeme Gellatly <g@o4sb.com>
* Sodexis <dev@sodexis.com>
* Lois Rilo <lois.rilo@eficent.com>
* Sudhir Arya <sudhir@erpharbor.com>
* Alexandre Díaz <alexandre.diaz@tecnativa.com>

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 <https://github.com/OCA/product-attribute/tree/12.0/product_sequence>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion 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.
Expand All @@ -14,6 +13,7 @@
'category': 'Product',
'depends': [
'product',
'product_code_unique',
],
'data': [
'data/product_sequence.xml',
Expand Down
24 changes: 10 additions & 14 deletions product_sequence/models/product_product.py
Expand Up @@ -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'] == '/':
Expand All @@ -42,28 +36,30 @@ 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):
"""To assign a new internal reference, just write '/' on the field.
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')
ref = sequence.next_by_id()
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):
Expand All @@ -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)
1 change: 1 addition & 0 deletions product_sequence/readme/CONTRIBUTORS.rst
Expand Up @@ -3,3 +3,4 @@
* Sodexis <dev@sodexis.com>
* Lois Rilo <lois.rilo@eficent.com>
* Sudhir Arya <sudhir@erpharbor.com>
* Alexandre Díaz <alexandre.diaz@tecnativa.com>

0 comments on commit 231a83b

Please sign in to comment.