I find it hard to read this type of comments, increasingly common in the forum.
I understand your point of view and I also complained (without writing it in the forum) that there is no complete example data.
Now when you are already profiting from the system (not a bad word, just that you get money out of it), as was our case too, it cannot demand what you are demanding.
It’s like saying “I’m missing X thing and I can’t earn money! just do something for free and that’s it”.
Here is the idea of our script, in case it is useful to someone else. We have an original fixed date, and based on that it makes the calculations at the moment the bench command is thrown.
As I said before, it requires a lot of work to write the necessary doctypes (and the first bd data example!), but the methodology that Frappe uses to create the demos is much more complicated.
```python
def setear_fechas(doctype, dates=[], child_dates={}, related_doctype=''):
"""
doctype (str): Quotation
dates (list): ['transaction_date', 'valid_till']
child_dates (dict): {'Payment Schedule': 'due_date'}
related_doctype (str): 'Stock Ledger Entry'
"""
import datetime
def get_new_date(old_date):
if not old_date:
return
old_time = None
if type(old_date) == datetime.datetime:
old_time = old_date.time()
old_date = old_date.date()
fecha_demo = datetime.date(2020, 12, 18)
fecha_hoy = datetime.date.today()
diff = (fecha_demo - old_date).days
value = fecha_hoy - datetime.timedelta(days=diff)
if old_time:
return datetime.datetime.combine(value, old_time)
return value
docs = frappe.get_all(doctype, fields=['name'] + dates)
for doc_data in docs:
# Cambia las fechas al doctype en si
for field_name in dates:
value = get_new_date(doc_data[field_name])
if value:
frappe.db.set_value(doctype, doc_data['name'], field_name, value)
# Cambia la fecha en los doctypes hijos, por ahora soporta cambiar un valor por doctype hijo
for child_doctype, field in child_dates.items():
children_docs = frappe.get_all(child_doctype, filters={'parent': doc_data['name']}, fields=['name', field])
for children_doc in children_docs:
value = get_new_date(children_doc[field])
if value:
frappe.db.set_value(child_doctype, children_doc['name'], field, value)
if related_doctype:
relateds = frappe.get_all(related_doctype, filters={'voucher_no': doc_data['name']}, fields=['name', 'posting_date'])
for related in relateds:
value = get_new_date(related['posting_date'])
if value:
frappe.db.set_value(related_doctype, related['name'], 'posting_date', value)
frappe.db.commit()
doc = frappe.get_doc(doctype, doc_data['name'])
try:
doc.set_status()
frappe.db.set_value(doctype, doc_data['name'], 'status', doc.status)
frappe.db.commit()
except Exception as e:
print(e)
def setear_status():
import frappe
doctypes = [doctype['name'] for doctype in frappe.get_all('DocType', {'issingle': 0})]
for doctype in doctypes:
try:
all_documents = [dt['name'] for dt in frappe.get_all(doctype)]
except Exception:
continue
for dn in all_documents:
doc = frappe.get_doc(doctype, dn)
try:
doc.set_status()
frappe.db.set_value(doctype, dn, 'status', doc.status)
frappe.db.commit()
except Exception:
break
# STOCK
setear_fechas('Stock Entry', dates=['posting_date'], related_doctype='Stock Ledger Entry')
setear_fechas('Material Request', dates=['transaction_date', 'schedule_date'], child_dates={'Material Request Item': 'schedule_date'})
setear_fechas('Stock Reconciliation', dates=['posting_date'])
setear_fechas('Stock Reconciliation', dates=['posting_date'])
setear_fechas('Landed Cost Voucher', dates=['posting_date'], child_dates={'Landed Cost Purchase Receipt': 'posting_date'})
setear_fechas('Delivery Note', dates=['posting_date', 'lr_date'], related_doctype='Stock Ledger Entry')
setear_fechas('Purchase Receipt', dates=['posting_date'], related_doctype='Stock Ledger Entry')
setear_fechas('Delivery Trip', dates=['departure_time'], child_dates={'Delivery Stop': 'estimated_arrival'})
setear_fechas('Batch', dates=['manufacturing_date'])
setear_fechas('Serial No', dates=['warranty_expiry_date','amc_expiry_date'])
setear_fechas('Item', dates=['end_of_life'])
# Accounting
setear_fechas('Sales Invoice', dates=['posting_date', 'due_date','po_date'], child_dates={'Payment Schedule': 'due_date', 'Sales Invoice Payment': 'clearance_date'}, related_doctype='GL Entry')
setear_fechas('Journal Entry', dates=['posting_date','clearance_date','bill_date','bill_date','due_date'])
setear_fechas('Purchase Invoice', dates=['posting_date', 'due_date','bill_date'], child_dates={'Payment Schedule': 'due_date'}, related_doctype='GL Entry')
setear_fechas('Period Closing Voucher', dates=['transaction_date','posting_date'])
setear_fechas('Accounting Period', dates=['start_date','end_date'])