Skip to content

Commit

Permalink
[ADD] test file and resolved travis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
atchuthan committed Sep 29, 2016
1 parent 55933fd commit 9d20322
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 19 deletions.
2 changes: 0 additions & 2 deletions product_sequence/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Otherwise the setting of the unique constraint will fail and the module will fai
Usage
=====

#. Go to ...

.. 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
Expand Down
2 changes: 1 addition & 1 deletion product_sequence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# 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
2 changes: 1 addition & 1 deletion product_sequence/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'demo': [
'demo/product_product.xml'
],
'pre_init_hook': 'update_null_and_slash_codes',
'pre_init_hook': 'pre_init_hook',
'auto_install': False,
'installable': True,
}
3 changes: 2 additions & 1 deletion product_sequence/demo/product_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Copyright (C) 2016 Sodexis
The licence is in the file __openerp__.py
-->

<odoo>
<record id="product.product_product_0" model="product.product">
<field name="default_code">SERVICE</field>
Expand All @@ -15,4 +16,4 @@
<record id="product.product_product_2" model="product.product">
<field name="default_code">OSA</field>
</record>
</odoo>
</odoo>
17 changes: 17 additions & 0 deletions product_sequence/hooks.py
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 = '/';")
15 changes: 1 addition & 14 deletions product_sequence/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@
from openerp import models, fields, api, _


def update_null_and_slash_codes(cr): # pragma: no cover
"""
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 = '/';")


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

Expand Down Expand Up @@ -51,7 +38,7 @@ def write(self, vals):
super(ProductProduct, product).write(vals)
return True

@api.one
@api.multi
def copy(self, default=None):
if default is None:
default = {}
Expand Down
5 changes: 5 additions & 0 deletions product_sequence/tests/__init__.py
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
24 changes: 24 additions & 0 deletions product_sequence/tests/test_product_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# © 2016 Sodexis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp.tests.common import TransactionCase


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_id = self.product_product.create(dict(
name="Apple",
default_code='PROD01'
))
self.assertEqual(product_id.default_code, 'PROD01')

def test_product_create_without_default_code(self):
product_id_1 = self.product_product.create(dict(name="Orange"))
self.assertRegexpMatches(str(product_id_1.default_code), r'PR/*')

0 comments on commit 9d20322

Please sign in to comment.