Ignore:
Timestamp:
25 Dec 2014, 18:23:17 (10 years ago)
Author:
Henrik Bettermann
Message:

#Remove unchanged product options from data when saving the form.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/products
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/products/browser.py

    r12317 r12318  
    177177    @action(_('Save'), style='primary')
    178178    def save(self, **data):
    179         ##: ToDo Remove unchanged product options from data
     179        # Remove unchanged product options from data
     180        new_options = data.get('options')
     181        if new_options and (len(new_options) == len (self.context.options)):
     182            new = False
     183            for i in range(len(new_options)):
     184                new_option_str = new_options[i].to_string()
     185                stored_options_str = self.context.options[i].to_string()
     186                if new_option_str != stored_options_str:
     187                    new = True
     188                    break
     189            if not new:
     190               del data['options']
    180191        return msave(self, **data)
    181192
  • main/waeup.ikoba/trunk/src/waeup/ikoba/products/tests/test_browser.py

    r12288 r12318  
    2323import pytz
    2424import base64
     25from decimal import Decimal
    2526from datetime import datetime, timedelta, date
    2627from StringIO import StringIO
     
    4344from waeup.ikoba.tests.test_async import FunctionalAsyncTestCase
    4445from waeup.ikoba.browser.tests.test_pdf import samples_dir
     46from waeup.ikoba.products.productoptions import ProductOptionEntry
    4547
    4648def lookup_submit_value(name, value, browser):
     
    8385        # to access grok.getSite() and should get our new app then
    8486        setSite(app)
     87
     88        self.logfile = os.path.join(
     89            self.app['datacenter'].storage, 'logs', 'main.log')
    8590
    8691        # Add user
     
    211216            None)
    212217        return
     218
     219    def test_product_options(self):
     220        prodoptions = ProductOptionEntry()
     221        prodoptions.title = u'My option'
     222        prodoptions.fee = Decimal('99.9')
     223        prodoptions.currency = 'usd'
     224        self.product.options = [prodoptions,]
     225        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     226        self.browser.open(self.product_path)
     227        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     228        self.assertEqual(self.product.options[0], prodoptions)
     229        self.browser.open(self.manage_product_path)
     230        self.browser.getControl("Save").click()
     231        # applyData must not exchange the object
     232        self.assertEqual(self.product.options[0], prodoptions)
     233        # and thus not add a logging message (the log file
     234        # do not even exist so far)
     235        self.assertRaises(IOError, open, self.logfile, 'read')
     236        # Now we change the content after opening the manage page
     237        self.browser.open(self.manage_product_path)
     238        prodoptions.title = u'My new option'
     239        self.assertEqual(self.product.options[0].title, 'My new option')
     240        # but save the opened form with the old data.
     241        self.browser.getControl("Save").click()
     242        # The object has been replaced,
     243        self.assertTrue(self.product.options[0] != prodoptions)
     244        # the old title has been restored
     245        self.assertEqual(self.product.options[0].title, 'My option')
     246        # and a logging message has been added.
     247        logcontent = open(self.logfile).read()
     248        self.assertTrue('saved: options' in logcontent)
Note: See TracChangeset for help on using the changeset viewer.