Try ERPNext Try Frappe Cloud Buy Support Partners Foundation

Doc Customization (TypeError: 'datetime.date' object is not iterable)

Hi,
I recently added a field to the “Purchase Receipt Item” form to include the field from the linked child table Batch. the reason, I need to print receipt labels that include the expiry_date field.

I added a new filed to the above form and used the “Fetch From” function in the new field to return the date from the Batch Child Table (see below).

Once I rebooted the server the field is now visible on “new” receipts. However, the receipt will no longer save. And I get the above subject error. Before I added the new field the Purchase receipts were working perfectly fine. And opening previously saved receipts does not contain the new Expiry Date field.

Here is the last server error file:
[ERROR] 2021-03-30 19:53:45,300 | /home/frappe/frappe-bench/apps/frappe/frappe/app.py:
Site: site1.local
Form Dict: {
“action”: “Save”,
“cmd”: “frappe.desk.form.save.savedocs”,
“doc”: “{“owner”:”****@********.com",“idx”:0,“docstatus”:0,“naming_series”:“MAT-PRE-.YYYY.-”,“supplier”:“Alchem, Inc.”,“supplier_name”:blush:
}
Request Error
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 67, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 59, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 24, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 64, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1074, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 21, in savedocs
doc.save()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 273, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 296, in _save
self.insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 224, in insert
self._validate_links()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 759, in _validate_links
result = d.get_invalid_links(is_submittable=self.meta.is_submittable)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 479, in get_invalid_links
‘name’, cache=True))
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py”, line 401, in get_value
order_by, cache=cache)
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py”, line 445, in get_values
out = self._get_values_from_table(fields, filters, doctype, as_dict, debug, order_by, update)
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py”, line 586, in _get_values_from_table
conditions, values = self.build_conditions(filters)
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py”, line 364, in build_conditions
for f in filters:
TypeError: ‘datetime.date’ object is not iterable
[ERROR] 2021-03-30 19:53:45,563 | /home/frappe/frappe-bench/apps/frappe/frappe/utils/error.py:
New Exception collected with id: 2021-03-30 19:53:45.302982-192.168.1.1-ef8

Can someone please point me to a possible solution?

I’ve been doing a bit more digging. And, it appears that the date is formatted incorrectly by using the “Fetch From” function in the form customization process, i.e., The expiry_date format in the Batch table appears as “mm-dd-yyyy” and the “fetched” date in the Purchase Receipt Items appears as “yyyy-mm-dd”. My guess is that this may be why it’s throwing the exception. Can someone please let me know:

  1. Is this likely?
  2. How can I format the new field? Can I format it in the same call statement field where it’s fetched?

ANY help would be appreciated. Please.

I figured it out, after a ton of searching:
It turns out the field type was incorrect. I had used the batch_no field (already in the doc type) as the template for the new field, i.e., I used “link” as the original field type that was giving me the error. After changing it to “data” I was able to save the modification and the field was available for use in the row.

However, now I have another issue due to this change:
When adding a new Batch record from the receipts line. Originally, the new item was pre-populated in the new record form. However, since a new field was added the pre-polulation no longer takes place.

I’m going to place another question on this forum. But, I guess I will have to answer them myself in time. Either way, hopefully, it helps others here looking for answers :slight_smile:

1 Like

This is answered. But, I can’t seem to find the “answered” toggle.