changeset ee2d3dfdee6a in modules/product:default
details: https://hg.tryton.org/modules/product?cmd=changeset;node=ee2d3dfdee6a
description:
        Remove parent field from TemplateFunction fields

        Otherwise the parent will be set using a product instance instead of a
        template when assigning values to the product instance like in
        on_change_template.

        issue8868
        review288591007
diffstat:

 product.py                         |   5 +++-
 tests/scenario_product_variant.rst |  39 ++++++++++++++++++++++++++++++++++++++
 tests/test_product.py              |   5 ++++
 3 files changed, 48 insertions(+), 1 deletions(-)

diffs (73 lines):

diff -r 61e048c247e3 -r ee2d3dfdee6a product.py
--- a/product.py        Mon Nov 25 21:55:20 2019 +0100
+++ b/product.py        Tue Nov 26 17:50:18 2019 +0100
@@ -246,7 +246,10 @@
                 continue
             field = getattr(cls, attr, None)
             if not field or isinstance(field, TemplateFunction):
-                setattr(cls, attr, TemplateFunction(copy.deepcopy(tfield)))
+                tfield = copy.deepcopy(tfield)
+                if hasattr(tfield, 'field'):
+                    tfield.field = None
+                setattr(cls, attr, TemplateFunction(tfield))
                 order_method = getattr(cls, 'order_%s' % attr, None)
                 if (not order_method
                         and not isinstance(tfield, (
diff -r 61e048c247e3 -r ee2d3dfdee6a tests/scenario_product_variant.rst
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/scenario_product_variant.rst        Tue Nov 26 17:50:18 2019 +0100
@@ -0,0 +1,39 @@
+========================
+Product Variant Scenario
+========================
+
+Imports::
+
+    >>> from decimal import Decimal
+    >>> from proteus import Model
+    >>> from trytond.tests.tools import activate_modules
+
+Install party::
+
+    >>> config = activate_modules('product')
+
+Create a template::
+
+    >>> ProductUom = Model.get('product.uom')
+    >>> unit, = ProductUom.find([('name', '=', 'Unit')])
+    >>> ProductTemplate = Model.get('product.template')
+    >>> template = ProductTemplate()
+    >>> template.name = "Product"
+    >>> template.default_uom = unit
+    >>> template.list_price = Decimal('42.0000')
+    >>> template.save()
+    >>> len(template.products)
+    1
+
+Create a variant::
+
+    >>> Product = Model.get('product.product')
+    >>> product = Product()
+    >>> product.template = template
+    >>> product.name
+    'Product'
+    >>> product.list_price
+    Decimal('42.0000')
+    >>> product.save()
+    >>> product.list_price
+    Decimal('42.0000')
diff -r 61e048c247e3 -r ee2d3dfdee6a tests/test_product.py
--- a/tests/test_product.py     Mon Nov 25 21:55:20 2019 +0100
+++ b/tests/test_product.py     Tue Nov 26 17:50:18 2019 +0100
@@ -450,6 +450,11 @@
     suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
         ProductTestCase))
     suite.addTests(doctest.DocFileSuite(
+            'scenario_product_variant.rst',
+            tearDown=doctest_teardown, encoding='utf-8',
+            checker=doctest_checker,
+            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
+    suite.addTests(doctest.DocFileSuite(
             'scenario_product_identifier.rst',
             tearDown=doctest_teardown, encoding='utf-8',
             checker=doctest_checker,

Reply via email to