forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df02066
commit 254c4e8
Showing
10 changed files
with
138 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
A module that adds sequence to the product. | ||
=========================================== | ||
.. 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 module allows to associate a sequence to the product reference. | ||
The reference (default code) is unique (SQL constraint) and required. | ||
|
@@ -13,6 +18,13 @@ they already have a unique reference (or no reference) set. Products with a def | |
|
||
Otherwise the setting of the unique constraint will fail and the module will fail to install. | ||
|
||
Usage | ||
===== | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/135/9.0 | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
|
@@ -29,6 +41,7 @@ Contributors | |
|
||
* Angel Moya <[email protected]> | ||
* Graeme Gellatly <[email protected]> | ||
* Sodexis <[email protected]> | ||
|
||
Maintainer | ||
---------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,7 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# Copyright (c) 2015 Domatix (http://domatix.com) | ||
# Angel Moua <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
# -*- coding: utf-8 -*- | ||
# © 2004 Tiny SPRL | ||
# © 2016 Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import models | ||
from .models.product_product import update_null_and_slash_codes | ||
from .hooks import pre_init_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<openerp> | ||
<data noupdate="1"> | ||
|
||
<record id="seq_product_auto_type" model="ir.sequence.type"> | ||
<field name="name">Product</field> | ||
<field name="code">product.product</field> | ||
</record> | ||
<!-- | ||
product_sequence for Odoo | ||
Copyright (C) 2004 Tiny SPRL | ||
Copyright (C) 2016 Sodexis | ||
The licence is in the file __openerp__.py | ||
--> | ||
|
||
<odoo> | ||
<data noupdate="1"> | ||
<record id="seq_product_auto" model="ir.sequence"> | ||
<field name="name">Product</field> | ||
<field name="code">product.product</field> | ||
<field eval="5" name="padding"/> | ||
<field name="prefix">PR/</field> | ||
</record> | ||
</data> | ||
</openerp> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data noupdate="0"> | ||
<record id="product.product_product_consultant" model="product.product"> | ||
<field name="default_code">SERVICE</field> | ||
</record> | ||
<!-- | ||
product_sequence for Odoo | ||
Copyright (C) 2004 Tiny SPRL | ||
Copyright (C) 2016 Sodexis | ||
The licence is in the file __openerp__.py | ||
--> | ||
|
||
<record id="product.product_product_1" model="product.product"> | ||
<field name="default_code">OSM</field> | ||
</record> | ||
|
||
<record id="product.product_product_2" model="product.product"> | ||
<field name="default_code">OSA</field> | ||
</record> | ||
</data> | ||
</openerp> | ||
<odoo> | ||
<record id="product.product_product_0" model="product.product"> | ||
<field name="default_code">SERVICE</field> | ||
</record> | ||
<record id="product.product_product_1" model="product.product"> | ||
<field name="default_code">OSM</field> | ||
</record> | ||
<record id="product.product_product_2" model="product.product"> | ||
<field name="default_code">OSA</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2004 Tiny SPRL | ||
# © 2016 Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
def pre_init_hook(cr): | ||
""" | ||
Updates existing codes matching the default '/' or | ||
empty. Primarily this ensures installation does not | ||
fail for demo data. | ||
:param cr: database cursor | ||
:return: void | ||
""" | ||
cr.execute("UPDATE product_product " | ||
"SET default_code = '!!mig!!' || id " | ||
"WHERE default_code IS NULL OR default_code = '/';") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,6 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# Copyright (c) 2015 Domatix (http://domatix.com) | ||
# Angel Moya <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
# -*- coding: utf-8 -*- | ||
# © 2004 Tiny SPRL | ||
# © 2016 Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import product_product |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_product_sequence |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp.tests.common import TransactionCase | ||
from ..hooks import pre_init_hook | ||
|
||
|
||
class TestProductSequence(TransactionCase): | ||
"""Tests for creating product with and without Product Sequence""" | ||
|
||
def setUp(self): | ||
super(TestProductSequence, self).setUp() | ||
self.product_product = self.env['product.product'] | ||
|
||
def test_product_create_with_default_code(self): | ||
product = self.product_product.create(dict( | ||
name="Apple", | ||
default_code='PROD01' | ||
)) | ||
self.assertEqual(product.default_code, 'PROD01') | ||
|
||
def test_product_create_without_default_code(self): | ||
product_1 = self.product_product.create(dict( | ||
name="Orange", | ||
default_code='/')) | ||
self.assertRegexpMatches(str(product_1.default_code), r'PR/*') | ||
|
||
def test_product_copy(self): | ||
product_2 = self.product_product.create(dict( | ||
name="Apple", | ||
default_code='PROD02' | ||
)) | ||
copy_product_2 = product_2.copy() | ||
self.assertEqual(copy_product_2.default_code, 'PROD02-copy') | ||
|
||
def test_pre_init_hook(self): | ||
product_3 = self.product_product.create(dict( | ||
name="Apple", | ||
default_code='PROD03' | ||
)) | ||
self.cr.execute( | ||
"update product_product set default_code='/' where id=%s" | ||
% (product_3.id,)) | ||
product_3.invalidate_cache() | ||
self.assertEqual(product_3.default_code, '/') | ||
pre_init_hook(self.cr) | ||
product_3.invalidate_cache() | ||
self.assertEqual(product_3.default_code, '!!mig!!%s' % (product_3.id,)) |