Merge branch 'master' into develop
This commit is contained in:
commit
47ecf4c513
3 changed files with 18 additions and 5 deletions
|
|
@ -13,7 +13,7 @@ import os, sys, importlib, inspect, json
|
|||
from .exceptions import *
|
||||
from .utils.jinja import get_jenv, get_template, render_template
|
||||
|
||||
__version__ = '7.1.20'
|
||||
__version__ = '7.1.21'
|
||||
__title__ = "Frappe Framework"
|
||||
|
||||
local = Local()
|
||||
|
|
|
|||
|
|
@ -517,7 +517,16 @@ class BaseDocument(object):
|
|||
values = frappe.db.get_value(self.doctype, self.name, constants, as_dict=True)
|
||||
|
||||
for fieldname in constants:
|
||||
if self.get(fieldname) != values.get(fieldname):
|
||||
df = self.meta.get_field(fieldname)
|
||||
|
||||
# This conversion to string only when fieldtype is Date
|
||||
if df.fieldtype == 'Date':
|
||||
value = str(values.get(fieldname))
|
||||
|
||||
else:
|
||||
value = values.get(fieldname)
|
||||
|
||||
if self.get(fieldname) != value:
|
||||
frappe.throw(_("Value cannot be changed for {0}").format(self.meta.get_label(fieldname)),
|
||||
frappe.CannotChangeConstantError)
|
||||
|
||||
|
|
|
|||
|
|
@ -285,12 +285,16 @@ class Document(BaseDocument):
|
|||
return
|
||||
|
||||
if rows:
|
||||
# delete rows that do not match the ones in the
|
||||
# document
|
||||
frappe.db.sql("""delete from `tab{0}` where parent=%s
|
||||
# select rows that do not match the ones in the document
|
||||
deleted_rows = frappe.db.sql("""select name from `tab{0}` where parent=%s
|
||||
and parenttype=%s and parentfield=%s
|
||||
and name not in ({1})""".format(df.options, ','.join(['%s'] * len(rows))),
|
||||
[self.name, self.doctype, fieldname] + rows)
|
||||
if len(deleted_rows) > 0:
|
||||
# delete rows that do not match the ones in the document
|
||||
frappe.db.sql("""delete from `tab{0}` where name in ({1})""".format(df.options,
|
||||
','.join(['%s'] * len(deleted_rows))), tuple(row[0] for row in deleted_rows))
|
||||
|
||||
else:
|
||||
# no rows found, delete all rows
|
||||
frappe.db.sql("""delete from `tab{0}` where parent=%s
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue