def preserve_naming_series_options_in_property_setter(self): """Preserve naming_series as property setter if it does not exist""" naming_series = self.get("fields", {"fieldname": "naming_series"}) if not naming_series: return # check if atleast 1 record exists if not (dataent.db.table_exists(self.name) and dataent.db.sql( "select name from `tab{}` limit 1".format(self.name))): return existing_property_setter = dataent.db.get_value( "Property Setter", { "doc_type": self.name, "property": "options", "field_name": "naming_series" }) if not existing_property_setter: make_property_setter(self.name, "naming_series", "options", naming_series[0].options, "Text", validate_fields_for_doctype=False) if naming_series[0].default: make_property_setter(self.name, "naming_series", "default", naming_series[0].default, "Text", validate_fields_for_doctype=False)
def set_property_setter(doctype, local_doc, original_doc): ''' compare doctype_properties and docfield_properties and create property_setter ''' # doctype_properties reset for dp in doctype_properties: # make property_setter to mimic changes made in local json if dp in local_doc and dp not in original_doc: make_property_setter(doctype, '', dp, local_doc[dp], doctype_properties[dp], for_doctype=True) local_fields = get_fields_dict(local_doc) original_fields = get_fields_dict(original_doc) # iterate through field and properties of each of those field for docfield in original_fields: for prop in original_fields[docfield]: # skip fields that are not in local_fields if docfield not in local_fields: continue if prop in docfield_properties and prop in local_fields[docfield]\ and original_fields[docfield][prop] != local_fields[docfield][prop]: # make property_setter equivalent of local changes make_property_setter(doctype, docfield, prop, local_fields[docfield][prop],\ docfield_properties[prop])
def validate(self): from dataent.custom.doctype.property_setter.property_setter import make_property_setter if self.get('instructor_created_by') == 'Naming Series': make_property_setter('Instructor', "naming_series", "hidden", 0, "Check") else: make_property_setter('Instructor', "naming_series", "hidden", 1, "Check")
def enable_payment_schedule_in_print(self): show_in_print = cint(self.show_payment_schedule_in_print) for doctype in ("Sales Order", "Sales Invoice", "Purchase Order", "Purchase Invoice"): make_property_setter(doctype, "due_date", "print_hide", show_in_print, "Check") make_property_setter(doctype, "payment_schedule", "print_hide", 0 if show_in_print else 1, "Check")
def execute(): dataent.reload_doc('projects', 'doctype', 'timesheet') dataent.reload_doc('projects', 'doctype', 'timesheet_detail') dataent.reload_doc('accounts', 'doctype', 'sales_invoice_timesheet') make_property_setter('Timesheet', "naming_series", "options", 'TS-', "Text") make_property_setter('Timesheet', "naming_series", "default", 'TS-', "Text")
def toggle_hide_tax_id(self): self.hide_tax_id = cint(self.hide_tax_id) # Make property setters to hide tax_id fields for doctype in ("Sales Order", "Sales Invoice", "Delivery Note"): make_property_setter(doctype, "tax_id", "hidden", self.hide_tax_id, "Check") make_property_setter(doctype, "tax_id", "print_hide", self.hide_tax_id, "Check")
def test_update_fields(self): self.insert_test_events() results = global_search.search('Every Month') self.assertEqual(len(results), 0) doctype = "Event" from dataent.custom.doctype.property_setter.property_setter import make_property_setter make_property_setter(doctype, "repeat_on", "in_global_search", 1, "Int") global_search.rebuild_for_doctype(doctype) results = global_search.search('Every Month') self.assertEqual(len(results), 3)
def toggle_in_words(self): self.disable_in_words = cint(self.disable_in_words) # Make property setters to hide in words fields for doctype in ("Quotation", "Sales Order", "Sales Invoice", "Delivery Note", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"): make_property_setter(doctype, "in_words", "hidden", self.disable_in_words, "Check") make_property_setter(doctype, "in_words", "print_hide", self.disable_in_words, "Check")
def set_sales_order_field(): for data in dataent.db.sql( """select doc_type, field_name, property, value, property_type from `tabProperty Setter` where doc_type = 'Purchase Order Item' and field_name in('material_request', 'material_request_item')""", as_dict=True): if data.field_name == 'material_request': make_property_setter(data.doc_type, 'sales_order', data.property, data.value, data.property_type) else: make_property_setter(data.doc_type, 'sales_order_item', data.property, data.value, data.property_type)
def _make_property_setter(property_name, value): property_setter = dataent.db.exists( 'Property Setter', { 'doc_type': doctype, 'field_name': 'naming_series', 'property': property_name }) if property_setter: dataent.db.set_value('Property Setter', property_setter, 'value', value) else: make_property_setter(doctype, "naming_series", "options", value, "Text")
def setUp(self): global_search.setup_global_search_table() self.assertTrue('__global_search' in dataent.db.get_tables()) doctype = "Event" global_search.reset() from dataent.custom.doctype.property_setter.property_setter import make_property_setter make_property_setter(doctype, "subject", "in_global_search", 1, "Int") make_property_setter(doctype, "event_type", "in_global_search", 1, "Int") make_property_setter(doctype, "roles", "in_global_search", 1, "Int") make_property_setter(doctype, "repeat_on", "in_global_search", 0, "Int")
def toggle_rounded_total(self): self.disable_rounded_total = cint(self.disable_rounded_total) # Make property setters to hide rounded total fields for doctype in ("Quotation", "Sales Order", "Sales Invoice", "Delivery Note", "Supplier Quotation", "Purchase Order"): make_property_setter(doctype, "base_rounded_total", "hidden", self.disable_rounded_total, "Check") make_property_setter(doctype, "base_rounded_total", "print_hide", 1, "Check") make_property_setter(doctype, "rounded_total", "hidden", self.disable_rounded_total, "Check") make_property_setter(doctype, "rounded_total", "print_hide", self.disable_rounded_total, "Check")
def set_by_naming_series(doctype, fieldname, naming_series, hide_name_field=True): from dataent.custom.doctype.property_setter.property_setter import make_property_setter if naming_series: make_property_setter(doctype, "naming_series", "hidden", 0, "Check") make_property_setter(doctype, "naming_series", "reqd", 1, "Check") # set values for mandatory try: dataent.db.sql( """update `tab{doctype}` set naming_series={s} where ifnull(naming_series, '')=''""".format(doctype=doctype, s="%s"), get_default_naming_series(doctype)) except NamingSeriesNotSetError: pass if hide_name_field: make_property_setter(doctype, fieldname, "reqd", 0, "Check") make_property_setter(doctype, fieldname, "hidden", 1, "Check") else: make_property_setter(doctype, "naming_series", "reqd", 0, "Check") make_property_setter(doctype, "naming_series", "hidden", 1, "Check") if hide_name_field: make_property_setter(doctype, fieldname, "hidden", 0, "Check") make_property_setter(doctype, fieldname, "reqd", 1, "Check") # set values for mandatory dataent.db.sql( """update `tab{doctype}` set `{fieldname}`=`name` where ifnull({fieldname}, '')=''""".format(doctype=doctype, fieldname=fieldname))
def enable_fields_for_cost_center_settings(self): show_field = 0 if cint( self.allow_cost_center_in_entry_of_bs_account) else 1 for doctype in ("Sales Invoice", "Purchase Invoice", "Payment Entry"): make_property_setter(doctype, "cost_center", "hidden", show_field, "Check")
def set_series(doctype, value): doc = dataent.db.exists('Property Setter', {'doc_type': doctype, 'property': 'autoname'}) if doc: dataent.db.set_value('Property Setter', doc, 'value', value) else: make_property_setter(doctype, '', 'autoname', value, '', for_doctype = True)
def update_values(dt, tax_table): dataent.reload_doctype(dt) dataent.reload_doctype(dt + " Item") dataent.reload_doctype(tax_table) net_total_precision = get_field_precision( dataent.get_meta(dt).get_field("net_total")) for field in ("total", "base_total", "base_net_total"): make_property_setter(dt, field, "precision", net_total_precision, "Select") rate_field_precision = get_field_precision( dataent.get_meta(dt + " Item").get_field("rate")) for field in ("net_rate", "base_net_rate", "net_amount", "base_net_amount", "base_rate", "base_amount"): make_property_setter(dt + " Item", field, "precision", rate_field_precision, "Select") tax_amount_precision = get_field_precision( dataent.get_meta(tax_table).get_field("tax_amount")) for field in ("base_tax_amount", "total", "base_total", "tax_amount_after_discount_amount", "base_tax_amount_after_discount_amount"): make_property_setter(tax_table, field, "precision", tax_amount_precision, "Select") # update net_total, discount_on dataent.db.sql(""" UPDATE `tab{0}` SET total = round(net_total, {1}), base_total = round(net_total*conversion_rate, {1}), net_total = round(base_net_total / conversion_rate, {1}), apply_discount_on = "Grand Total" WHERE docstatus < 2 """.format(dt, net_total_precision)) # update net_amount dataent.db.sql(""" UPDATE `tab{0}` par, `tab{1}` item SET item.base_net_amount = round(item.base_amount, {2}), item.base_net_rate = round(item.base_rate, {2}), item.net_amount = round(item.base_amount / par.conversion_rate, {2}), item.net_rate = round(item.base_rate / par.conversion_rate, {2}), item.base_amount = round(item.amount * par.conversion_rate, {2}), item.base_rate = round(item.rate * par.conversion_rate, {2}) WHERE par.name = item.parent and par.docstatus < 2 """.format(dt, dt + " Item", rate_field_precision)) # update tax in party currency dataent.db.sql(""" UPDATE `tab{0}` par, `tab{1}` tax SET tax.base_tax_amount = round(tax.tax_amount, {2}), tax.tax_amount = round(tax.tax_amount / par.conversion_rate, {2}), tax.base_total = round(tax.total, {2}), tax.total = round(tax.total / conversion_rate, {2}), tax.base_tax_amount_after_discount_amount = round(tax.tax_amount_after_discount_amount, {2}), tax.tax_amount_after_discount_amount = round(tax.tax_amount_after_discount_amount / conversion_rate, {2}) WHERE par.name = tax.parent and par.docstatus < 2 """.format(dt, tax_table, tax_amount_precision))