I have an orders doctype which has multiple sections and i have opted to use virtual doctypes to update the different sections of the order. SO i have the first virtual doctype called order schedule which is supposed to add a new order. So in my order schedule doctype (py) i have
class OrderSchedule(Document):
def db_insert(self, *args, **kwargs):
d = self.get_valid_dict(convert_dates_to_str=True)
new_doc = frappe.new_doc("Order")
new_doc.update(d)
new_doc.insert()
def load_from_db(self):
doc = frappe.get_doc('Order', self.name)
doc_json = doc.as_dict()
doc_json.doctype = self.doctype
doc_json.modified = doc.modified
super(Document, self).__init__(doc_json)
def db_update(self):
d = self.get_valid_dict(convert_dates_to_str=False)
exclude_fields = []
doc = frappe.get_doc("Order", self.name)
for fieldname, value in d.items():
if fieldname not in exclude_fields:
doc.set(fieldname, value)
doc.save()
The above works during the first save but any further edits or during submit i get an error
frappe.exceptions.TimestampMismatchError: Error: Document has been modified after you have opened it ( Please refresh to get the latest document
Upon checking the console log i have noticed its caused by a frappe method check_if_latest in document.py. and by comenting out check_if_latest in frappe document.py it works.
Commenting frappe code is not optimal because of future updates, so is there a way i can fix this or skip the check_if_latest during document save.