Repository: inventree/InvenTree

Issue:
Cancel purchase order - Error object
### Please verify that this bug has NOT been raised before.

- [X] I checked and didn't find a similar issue

### Describe the bug*

When trying to cancel a purchase order, I get an error and the order does not get cancelled.

### Steps to Reproduce

1. Create purchase order with a supplier
2. Add order items (optional)
3. Issue order (optional)
4. Cancel order

### Expected behaviour

Order gets cancelled.

### Deployment Method

- [X] Docker
- [ ] Bare metal

### Version Information

# Version Information:
InvenTree-Version: 0.13.0
Django Version: 3.2.23
Commit Hash: 301afaa
Commit Date: 2023-12-15

Database: postgresql
Debug-Mode: False
Deployed using Docker: True
Platform: Linux-5.15.0-91-generic-x86_64-with
Installer: DOC

Active plugins: [{'name': 'InvenTreeBarcode', 'slug': 'inventreebarcode', 'version': '2.0.0'}, {'name': 'InvenTreeCoreNotificationsPlugin', 'slug': 'inventreecorenotificationsplugin', 'version': '1.0.0'}, {'name': 'InvenTreeCurrencyExchange', 'slug': 'inventreecurrencyexchange', 'version': '1.0.0'}, {'name': 'InvenTreeLabel', 'slug': 'inventreelabel', 'version': '1.0.0'}, {'name': 'InvenTreeLabelSheet', 'slug': 'inventreelabelsheet', 'version': '1.0.0'}, {'name': 'DigiKeyPlugin', 'slug': 'digikeyplugin', 'version': '1.0.0'}, {'name': 'LCSCPlugin', 'slug': 'lcscplugin', 'version': '1.0.0'}, {'name': 'MouserPlugin', 'slug': 'mouserplugin', 'version': '1.0.0'}, {'name': 'TMEPlugin', 'slug': 'tmeplugin', 'version': '1.0.0'}]


### Please verify if you can reproduce this bug on the demo site.

- [X] I can reproduce this bug on the demo site.

### Relevant log output

```shell
192.168.2.3 - - [26/Dec/2023:13:44:47 +0000] "GET /api/order/po-line/?search=&offset=0&limit=25&order=1&part_detail=true HTTP/1.0" 200 2162 "https://inventree-server/order/purchase-order/1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0"
'bool' object is not callable
/root/.local/lib/python3.10/site-packages/django/db/models/fields/__init__.py:1358: RuntimeWarning: DateTimeField NotificationEntry.updated received a naive datetime (2023-12-25 00:00:00) while time zone support is active.
  warnings.warn("DateTimeField %s.%s received a naive datetime "
Internal Server Error: /api/order/po/1/cancel/
```



Discussion:
Ca reporduce on stable. Thank you for the report @pdsccode !
@pdsccode bugfix is in review; we are currently on holiday break so it might take a few days till `latest` receives the fix - stay tuned on https://github.com/inventree/InvenTree/pull/6137
No Problem. Not a dealbreaker for me so take your time and relax a bit. 😉

Resolving patch:
diff --git a/InvenTree/order/serializers.py b/InvenTree/order/serializers.py
--- a/InvenTree/order/serializers.py
+++ b/InvenTree/order/serializers.py
@@ -247,7 +247,7 @@ def get_context_data(self):
         self.order = self.context['order']
 
         return {
-            'can_cancel': self.order.can_cancel(),
+            'can_cancel': self.order.can_cancel,
         }
 
     def save(self):
@@ -1219,7 +1219,7 @@ def get_context_data(self):
         order = self.context['order']
 
         return {
-            'can_cancel': order.can_cancel(),
+            'can_cancel': order.can_cancel,
         }
 
     def save(self):


Test patch: