changeset 4650f85e3897 in modules/purchase_requisition:default
details: 
https://hg.tryton.org/modules/purchase_requisition?cmd=changeset;node=4650f85e3897
description:
        Rename purchase requisition state from cancel to cancelled

        issue8927
        review325441002
diffstat:

 CHANGELOG                               |   2 +
 doc/index.rst                           |   2 +-
 purchase.py                             |  37 ++++++++++++++++++++++----------
 tests/scenario_purchase_requisition.rst |   2 +-
 4 files changed, 29 insertions(+), 14 deletions(-)

diffs (136 lines):

diff -r a69ba5943155 -r 4650f85e3897 CHANGELOG
--- a/CHANGELOG Mon May 04 12:24:49 2020 +0200
+++ b/CHANGELOG Thu Jun 04 11:07:28 2020 +0100
@@ -1,3 +1,5 @@
+* Rename purchase requisition state from cancel to cancelled
+
 Version 5.6.0 - 2020-05-04
 * Bug fixes (see mercurial logs for details)
 * Add employee on requisitions for some states
diff -r a69ba5943155 -r 4650f85e3897 doc/index.rst
--- a/doc/index.rst     Mon May 04 12:24:49 2020 +0200
+++ b/doc/index.rst     Thu Jun 04 11:07:28 2020 +0100
@@ -28,5 +28,5 @@
 
 - Total: The total amount.
 - State: The state of the purchase requisition. May take one of the following
-  values: Draft, Waiting, Rejected, Processing, Done, Canceled.
+  values: Draft, Waiting, Rejected, Processing, Done, Cancelled.
 - Company: The company which issue the purchase requisition.
diff -r a69ba5943155 -r 4650f85e3897 purchase.py
--- a/purchase.py       Mon May 04 12:24:49 2020 +0200
+++ b/purchase.py       Thu Jun 04 11:07:28 2020 +0100
@@ -110,7 +110,7 @@
     supply_date = fields.Date(
         'Supply Date',
         states={
-            'required': ~Eval('state').in_(['draft', 'cancel']),
+            'required': ~Eval('state').in_(['draft', 'cancelled']),
             'readonly': _states['readonly'],
             },
         depends=_depends)
@@ -141,9 +141,9 @@
         states=_states, depends=_depends)
 
     approved_by = employee_field(
-        "Approved By", states=['approved', 'processing', 'done', 'cancel'])
+        "Approved By", states=['approved', 'processing', 'done', 'cancelled'])
     rejected_by = employee_field(
-        "Rejected By", states=['rejected', 'processing', 'done', 'cancel'])
+        "Rejected By", states=['rejected', 'processing', 'done', 'cancelled'])
     state = fields.Selection([
             ('draft', "Draft"),
             ('waiting', "Waiting"),
@@ -151,7 +151,7 @@
             ('approved', "Approved"),
             ('processing', "Processing"),
             ('done', "Done"),
-            ('cancel', "Canceled"),
+            ('cancelled', "Cancelled"),
             ], "State", readonly=True, required=True)
 
     del _states
@@ -160,9 +160,9 @@
     def __setup__(cls):
         super(PurchaseRequisition, cls).__setup__()
         cls._transitions |= set((
-                ('cancel', 'draft'),
+                ('cancelled', 'draft'),
                 ('rejected', 'draft'),
-                ('draft', 'cancel'),
+                ('draft', 'cancelled'),
                 ('draft', 'waiting'),
                 ('waiting', 'draft'),
                 ('waiting', 'rejected'),
@@ -179,8 +179,8 @@
                     },
                 'draft': {
                     'invisible': ~Eval('state').in_(
-                        ['cancel', 'waiting', 'approved', 'rejected']),
-                    'icon': If(Eval('state').in_(['cancel', 'rejected']),
+                        ['cancelled', 'waiting', 'approved', 'rejected']),
+                    'icon': If(Eval('state').in_(['cancelled', 'rejected']),
                         'tryton-undo',
                         'tryton-back'),
                     'depends': ['state'],
@@ -210,7 +210,19 @@
                 })
         # The states where amounts are cached
         cls._states_cached = ['approved', 'done', 'rejected',
-            'processing', 'cancel']
+            'processing', 'cancelled']
+
+    @classmethod
+    def __register__(cls, module_name):
+        cursor = Transaction().connection.cursor()
+        table = cls.__table__()
+
+        super().__register__(module_name)
+
+        # Migration from 5.6: rename state cancel to cancelled
+        cursor.execute(*table.update(
+                [table.state], ['cancelled'],
+                where=table.state == 'cancel'))
 
     @classmethod
     def default_state(cls):
@@ -300,7 +312,8 @@
     @classmethod
     def view_attributes(cls):
         return [
-            ('/tree', 'visual', If(Eval('state') == 'cancel', 'muted', '')),
+            ('/tree', 'visual',
+                If(Eval('state') == 'cancelled', 'muted', '')),
             ]
 
     @classmethod
@@ -322,7 +335,7 @@
         # Cancel before delete
         cls.cancel(requisitions)
         for requisition in requisitions:
-            if requisition.state != 'cancel':
+            if requisition.state != 'cancelled':
                 raise AccessError(
                     gettext('purchase_requisition.msg_delete_cancel',
                         requisition=requisition.rec_name))
@@ -349,7 +362,7 @@
 
     @classmethod
     @ModelView.button
-    @Workflow.transition('cancel')
+    @Workflow.transition('cancelled')
     def cancel(cls, requisitions):
         cls.store_cache(requisitions)
 
diff -r a69ba5943155 -r 4650f85e3897 tests/scenario_purchase_requisition.rst
--- a/tests/scenario_purchase_requisition.rst   Mon May 04 12:24:49 2020 +0200
+++ b/tests/scenario_purchase_requisition.rst   Thu Jun 04 11:07:28 2020 +0100
@@ -342,7 +342,7 @@
     >>> requisition_line.quantity = 4.0
     >>> requisition.click('cancel')
     >>> requisition.state
-    'cancel'
+    'cancelled'
 
 Create purchase requisition, wait then reject::
 

Reply via email to