Skip to content

Commit

Permalink
[IMP] product_attribute_types (#1275)
Browse files Browse the repository at this point in the history
added onchange to fill numeric_value using values name
  • Loading branch information
mikelarre authored and pedrobaeza committed Mar 17, 2017
1 parent 042d143 commit 5dc7dfc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
9 changes: 6 additions & 3 deletions product_attribute_types/__openerp__.py
@@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -18,13 +18,16 @@

{
"name": "Product attribute types",
"version": "1.0",
"version": "8.0.1.1.0",
"license": "AGPL-3",
"depends": [
"product",
],
"author": "OdooMRP team,"
"AvanzOSC,"
"Serv. Tecnol. Avanzados - Pedro M. Baeza",
"Tecnativa,"
"Serv. Tecnol. Avanzados - Pedro M. Baeza,"
"Odoo Community Association (OCA)",
"contributors": [
"Mikel Arregi <mikelarregi@avanzosc.es>",
"Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>",
Expand Down
12 changes: 10 additions & 2 deletions product_attribute_types/models/product.py
@@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@
#
##############################################################################

from openerp import models, fields
from openerp import api, fields, models


class ProductAttribute(models.Model):
Expand Down Expand Up @@ -45,3 +45,11 @@ class ProductAttributeValue(models.Model):
numeric_value = fields.Float('Numeric Value', digits=(12, 6))
min_range = fields.Float('Min', digits=(12, 6))
max_range = fields.Float('Max', digits=(12, 6))

@api.onchange('name')
def onchange_name(self):
if self.attr_type == 'numeric' and not self.numeric_value:
try:
self.numeric_value = float(self.name)
except:
pass
4 changes: 4 additions & 0 deletions product_attribute_types/tests/__init__.py
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2016 Mikel Arregi Etxaniz - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import test_product_attribute_types
31 changes: 31 additions & 0 deletions product_attribute_types/tests/test_product_attribute_types.py
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# © 2016 Mikel Arregi Etxaniz - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
import openerp.tests.common as common


class TestProductAttributeTypes(common.TransactionCase):

def setUp(self):
super(TestProductAttributeTypes, self).setUp()
self.attribute_model = self.env['product.attribute']
self.attribute_value_model = self.env['product.attribute.value']
self.attribute = self.attribute_model.create(
{
'name': 'attr1',
'attr_type': 'numeric'
}
)
self.attribute_value = self.attribute_value_model.create(
{
'name': 'value1',
'attribute_id': self.attribute.id
}
)

def test_onchange_numeric_value_name(self):
self.attribute_value.name = '3'
self.attribute_value.onchange_name()
self.assertEquals(self.attribute_value.numeric_value,
float(self.attribute_value.name),
'Numeric value properly assigned')

0 comments on commit 5dc7dfc

Please sign in to comment.