Quellcode durchsuchen

Merge pull request #904 from nabinhait/hotfix

Allowed precision upto 9 for Float, Currency, Percent fieldtype
version-14
Nabin Hait vor 10 Jahren
Ursprung
Commit
aef4b10caf
6 geänderte Dateien mit 43 neuen und 24 gelöschten Zeilen
  1. +2
    -2
      frappe/core/doctype/custom_field/custom_field.json
  2. +5
    -5
      frappe/core/doctype/custom_field/custom_field.py
  3. +11
    -0
      frappe/core/doctype/customize_form/customize_form.py
  4. +2
    -2
      frappe/core/doctype/customize_form_field/customize_form_field.json
  5. +2
    -2
      frappe/core/doctype/docfield/docfield.json
  6. +21
    -13
      frappe/model/db_schema.py

+ 2
- 2
frappe/core/doctype/custom_field/custom_field.json Datei anzeigen

@@ -68,7 +68,7 @@
"fieldname": "precision",
"fieldtype": "Select",
"label": "Precision",
"options": "\n1\n2\n3\n4\n5\n6",
"options": "\n1\n2\n3\n4\n5\n6\n7\n8\n9",
"permlevel": 0,
"precision": ""
},
@@ -267,7 +267,7 @@
],
"icon": "icon-glass",
"idx": 1,
"modified": "2014-09-05 07:41:13.076820",
"modified": "2014-11-07 12:59:28.734894",
"modified_by": "Administrator",
"module": "Core",
"name": "Custom Field",


+ 5
- 5
frappe/core/doctype/custom_field/custom_field.py Datei anzeigen

@@ -3,7 +3,7 @@

from __future__ import unicode_literals
import frappe
from frappe.utils import cint, cstr
from frappe.utils import cstr
from frappe import _

from frappe.model.document import Document
@@ -30,12 +30,12 @@ class CustomField(Document):
frappe.throw(_("Fieldname not set for Custom Field"))

def on_update(self):
# validate field
from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype

frappe.clear_cache(doctype=self.dt)

validate_fields_for_doctype(self.dt)
if not getattr(self, "ignore_validate", None):
# validate field
from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype
validate_fields_for_doctype(self.dt)

# create property setter to emulate insert after
self.create_property_setter()


+ 11
- 0
frappe/core/doctype/customize_form/customize_form.py Datei anzeigen

@@ -8,6 +8,7 @@ from __future__ import unicode_literals
"""
import frappe, json
from frappe import _
from frappe.utils import cint
from frappe.model.document import Document
from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype

@@ -103,6 +104,7 @@ class CustomizeForm(Document):
self.make_property_setter(property=property, value=self.get(property),
property_type=self.doctype_properties[property])

update_db = False
for df in self.get("customize_form_fields"):
if df.get("__islocal"):
continue
@@ -122,9 +124,17 @@ class CustomizeForm(Document):
.format(df.idx))
continue

elif property == "precision" and cint(df.get("precision")) > 6 \
and cint(df.get("precision")) > cint(meta_df[0].get("precision")):
update_db = True

self.make_property_setter(property=property, value=df.get(property),
property_type=self.docfield_properties[property], fieldname=df.fieldname)

if update_db:
from frappe.model.db_schema import updatedb
updatedb(self.doc_type)

def update_custom_fields(self):
for df in self.get("customize_form_fields"):
if df.get("__islocal"):
@@ -159,6 +169,7 @@ class CustomizeForm(Document):
changed = True

if changed:
custom_field.ignore_validate = True
custom_field.save()

def delete_custom_fields(self):


+ 2
- 2
frappe/core/doctype/customize_form_field/customize_form_field.json Datei anzeigen

@@ -86,7 +86,7 @@
"fieldname": "precision",
"fieldtype": "Select",
"label": "Precision",
"options": "\n1\n2\n3\n4\n5\n6",
"options": "\n1\n2\n3\n4\n5\n6\n7\n8\n9",
"permlevel": 0,
"precision": ""
},
@@ -278,7 +278,7 @@
"idx": 1,
"issingle": 0,
"istable": 1,
"modified": "2014-09-05 07:41:29.641454",
"modified": "2014-11-07 11:08:52.125289",
"modified_by": "Administrator",
"module": "Core",
"name": "Customize Form Field",


+ 2
- 2
frappe/core/doctype/docfield/docfield.json Datei anzeigen

@@ -97,7 +97,7 @@
"fieldname": "precision",
"fieldtype": "Select",
"label": "Precision",
"options": "\n1\n2\n3\n4\n5\n6",
"options": "\n1\n2\n3\n4\n5\n6\n7\n8\n9",
"permlevel": 0,
"print_hide": 1
},
@@ -314,7 +314,7 @@
"in_dialog": 1,
"issingle": 0,
"istable": 1,
"modified": "2014-09-05 07:41:05.956027",
"modified": "2014-11-07 11:40:55.281141",
"modified_by": "Administrator",
"module": "Core",
"name": "DocField",


+ 21
- 13
frappe/model/db_schema.py Datei anzeigen

@@ -11,7 +11,7 @@ Syncs a database table to the `DocType` (metadata)
import os
import frappe
from frappe import _
from frappe.utils import cstr
from frappe.utils import cstr, cint

type_map = {
'Currency': ('decimal', '18,6')
@@ -94,20 +94,23 @@ class DbTable:
get columns from docfields and custom fields
"""
fl = frappe.db.sql("SELECT * FROM tabDocField WHERE parent = %s", self.doctype, as_dict = 1)
precisions = {}

try:
if not frappe.flags.in_install_app:
custom_fl = frappe.db.sql("""\
SELECT * FROM `tabCustom Field`
WHERE dt = %s AND docstatus < 2""", (self.doctype,), as_dict=1)
if custom_fl: fl += custom_fl
except Exception, e:
if e.args[0]!=1146: # ignore no custom field
raise

# get precision from property setters
for ps in frappe.get_all("Property Setter", fields=["field_name", "value"],
filters={"doc_type": self.doctype, "doctype_or_field": "DocField", "property": "precision"}):
precisions[ps.field_name] = ps.value

for f in fl:
self.columns[f['fieldname']] = DbColumn(self, f['fieldname'],
f['fieldtype'], f.get('length'), f.get('default'),
f.get('search_index'), f.get('options'))
f['fieldtype'], f.get('length'), f.get('default'), f.get('search_index'),
f.get('options'), precisions.get(f['fieldname']) or f.get('precision'))

def get_columns_from_db(self):
self.show_columns = frappe.db.sql("desc `%s`" % self.name)
@@ -212,7 +215,7 @@ class DbTable:
frappe.db.sql("alter table `{}` {}".format(self.name, ", ".join(query)))

class DbColumn:
def __init__(self, table, fieldname, fieldtype, length, default, set_index, options):
def __init__(self, table, fieldname, fieldtype, length, default, set_index, options, precision):
self.table = table
self.fieldname = fieldname
self.fieldtype = fieldtype
@@ -220,9 +223,10 @@ class DbColumn:
self.set_index = set_index
self.default = default
self.options = options
self.precision = precision

def get_definition(self, with_default=1):
ret = get_definition(self.fieldtype)
ret = get_definition(self.fieldtype, self.precision)

if with_default and self.default and (self.default not in default_shortcuts) \
and not self.default.startswith(":") and ret not in ['text', 'longtext']:
@@ -406,7 +410,7 @@ def remove_all_foreign_keys():
for f in fklist:
frappe.db.sql("alter table `tab%s` drop foreign key `%s`" % (t[0], f[1]))

def get_definition(fieldtype):
def get_definition(fieldtype, precision=None):
d = type_map.get(fieldtype)

if not d:
@@ -414,12 +418,16 @@ def get_definition(fieldtype):

ret = d[0]
if d[1]:
ret += '(' + d[1] + ')'
length = d[1]
if fieldtype in ["Float", "Currency", "Percent"] and cint(precision) > 6:
length = '18,9'
ret += '(' + length + ')'

return ret


def add_column(doctype, column_name, fieldtype):
def add_column(doctype, column_name, fieldtype, precision=None):
frappe.db.commit()
frappe.db.sql("alter table `tab%s` add column %s %s" % (doctype,
column_name, get_definition(fieldtype)))
column_name, get_definition(fieldtype, precision)))


Laden…
Abbrechen
Speichern