Reviewers: ,


Please review this at http://codereview.tryton.org/443001/

Affected files:
  M allocation.py
  M tests/test_project_plan.py


Index: allocation.py
===================================================================
--- a/allocation.py
+++ b/allocation.py
@@ -16,6 +16,21 @@
             select=True)
     percentage = fields.Float('Percentage', digits=(16, 2), required=True)

+    def __init__(self):
+        super(Allocation, self).__init__()
+        self._constraints += [
+            ('check_percentage', 'invalid_percentage'),
+            ]
+        self._error_messages.update({
+            'invalid_percentage': 'Percentage must be greater than zero '
+            })
+
+    def check_percentage(self, ids):
+        for allocation in self.browse(ids):
+            if not allocation.percentage > 0.00:
+                return False
+        return True
+
     def default_percentage(self):
         return 100

Index: tests/test_project_plan.py
===================================================================
--- a/tests/test_project_plan.py
+++ b/tests/test_project_plan.py
@@ -11,7 +11,10 @@

 import unittest
 import trytond.tests.test_tryton
-from trytond.tests.test_tryton import test_view, test_depends
+from trytond.exceptions import UserError
+from trytond.transaction import Transaction
+from trytond.tests.test_tryton import test_view, test_depends, POOL, \
+    DB_NAME, USER, CONTEXT


 class ProjectPlanTestCase(unittest.TestCase):
@@ -34,6 +37,41 @@
         '''
         test_depends()

+    def test0010allocation(self):
+        '''
+        Test Allocation
+        '''
+        with Transaction().start(DB_NAME, USER,
+                    context=CONTEXT) as transaction:
+            project_obj = POOL.get('project.work')
+            employee_obj = POOL.get('company.employee')
+            company_obj = POOL.get('company.company')
+            currency_obj = POOL.get('currency.currency')
+
+            currency = currency_obj.create({
+                'name': 'USD',
+                'code': 'USD',
+                'symbol': '$',
+            })
+            company = company_obj.create({
+                'name': 'Company',
+                'currency': currency,
+            })
+            employee = employee_obj.create({
+                'name': 'Employee',
+                'company': company,
+            })
+            data = {
+                'name': 'A Test Project',
+                'type': 'task',
+                'company': company,
+                'allocations': [
+                    ('create', {'employee': employee, 'percentage': 0})
+                ]
+            }
+            self.assertRaises(
+                UserError, project_obj.create, data
+            )

 def suite():
     suite = trytond.tests.test_tryton.suite()


--
[email protected] mailing list

Reply via email to