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

[IMP] Uniqueness on product template also #1

Open
wants to merge 3 commits into
base: product_internal_reference_unique
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 61 additions & 0 deletions product_code_unique/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.. 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

==================================
Unique Product Internal Reference
==================================

This module adds a constraint on the internal reference of the product
to make it unique across the database.

Usage
=====

* For this module to be succesfully installed, there should be no 2 existing
records that has the same Internal Reference including empty fields. A
correction of the records needs to be done prior to the installation of this
module.

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 smash it by providing detailed and welcomed feedback.

Credits
=======

Images
------

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

Contributors
------------

* Antonio Yamuta <ayamuta@opensourceintegrators.com>

Funders
-------

The development of this module has been financially supported by:

* Open Source Integrators <http://www.opensourceintegrators.com>

Maintainer
----------

.. 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.
4 changes: 4 additions & 0 deletions product_code_unique/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
19 changes: 19 additions & 0 deletions product_code_unique/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Unique Product Internal Reference",
"summary": "Set Product Internal Reference as Unique",
"version": "11.0.1.0.0",
"license": "AGPL-3",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"category": "Product",
"website": "http://www.opensourceintegrators.com",
"depends": ["product"],
"data": [
],
'demo': [
'data/product_demo.xml',
],
"installable": True,
}
40 changes: 40 additions & 0 deletions product_code_unique/data/product_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0"?>
<odoo>
<record id="product.product_product_1" model="product.product">
<field name="name">GAP Analysis Service</field>
<field name="default_code">GAPANA</field>
</record>
<record id="product.product_product_2" model="product.product">
<field name="name">Support Services</field>
<field name="default_code">SUSER</field>
</record>
<record id="product.product_product_5c" model="product.product">
<field name="name">Parts Replacement</field>
<field name="default_code">PAREP</field>
</record>
<record id="product.product_product_6c" model="product.product">
<field name="name">Repair</field>
<field name="default_code">REP</field>
</record>
<record id="product.product_product_11c" model="product.product">
<field name="name">Cleaning</field>
<field name="default_code">CLEN</field>
</record>
<record id="stock.test_quant_product" model="product.product">
<field name="name">Whiteboard</field>
<field name="default_code">WTBO</field>
</record>
<!-- Archived Demo Products without Internal Reference Value -->
<record id="product.membership_0" model="product.product">
<field name="name">Gold Membership</field>
<field name="default_code">GMEM</field>
</record>
<record id="product.membership_1" model="product.product">
<field name="name">Silver Membership</field>
<field name="default_code">SMEM</field>
</record>
<record id="product.membership_2" model="product.product">
<field name="name">Basic Membership</field>
<field name="default_code">BMEM</field>
</record>
</odoo>
4 changes: 4 additions & 0 deletions product_code_unique/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import product
24 changes: 24 additions & 0 deletions product_code_unique/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = 'product.template'

default_code = fields.Char('Internal Reference', index=True)

_sql_constraints = [
('product_template_default_code_uniq', 'unique(default_code)',
'Internal Reference must be unique across the database!')]


class ProductProduct(models.Model):
_inherit = 'product.product'

default_code = fields.Char('Internal Reference', index=True)

_sql_constraints = [
('product_product_default_code_uniq', 'unique(default_code)',
'Internal Reference must be unique across the database!')]
Binary file added product_code_unique/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.