Merge branch 'develop' of github.com:frappe/frappe into bg-rename_doc
This commit is contained in:
commit
448fb8a207
121 changed files with 2131 additions and 780 deletions
59
cypress/fixtures/child_table_doctype_1.js
Normal file
59
cypress/fixtures/child_table_doctype_1.js
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
export default {
|
||||
name: "Child Table Doctype 1",
|
||||
actions: [],
|
||||
custom: 1,
|
||||
autoname: "format: Test-{####}",
|
||||
creation: "2022-02-09 20:15:21.242213",
|
||||
doctype: "DocType",
|
||||
editable_grid: 1,
|
||||
engine: "InnoDB",
|
||||
fields: [
|
||||
{
|
||||
fieldname: "data",
|
||||
fieldtype: "Data",
|
||||
in_list_view: 1,
|
||||
label: "Data"
|
||||
},
|
||||
{
|
||||
fieldname: "barcode",
|
||||
fieldtype: "Barcode",
|
||||
in_list_view: 1,
|
||||
label: "Barcode"
|
||||
},
|
||||
{
|
||||
fieldname: "check",
|
||||
fieldtype: "Check",
|
||||
in_list_view: 1,
|
||||
label: "Check"
|
||||
},
|
||||
{
|
||||
fieldname: "rating",
|
||||
fieldtype: "Rating",
|
||||
in_list_view: 1,
|
||||
label: "Rating"
|
||||
},
|
||||
{
|
||||
fieldname: "duration",
|
||||
fieldtype: "Duration",
|
||||
in_list_view: 1,
|
||||
label: "Duration"
|
||||
},
|
||||
{
|
||||
fieldname: "date",
|
||||
fieldtype: "Date",
|
||||
in_list_view: 1,
|
||||
label: "Date"
|
||||
}
|
||||
],
|
||||
links: [],
|
||||
istable: 1,
|
||||
modified: "2022-02-10 12:03:12.603763",
|
||||
modified_by: "Administrator",
|
||||
module: "Custom",
|
||||
naming_rule: "By fieldname",
|
||||
owner: "Administrator",
|
||||
permissions: [],
|
||||
sort_field: 'modified',
|
||||
sort_order: 'ASC',
|
||||
track_changes: 1
|
||||
};
|
||||
|
|
@ -20,6 +20,12 @@ export default {
|
|||
label: "Child Table",
|
||||
options: "Child Table Doctype",
|
||||
reqd: 1
|
||||
},
|
||||
{
|
||||
fieldname: "child_table_1",
|
||||
fieldtype: "Table",
|
||||
label: "Child Table 1",
|
||||
options: "Child Table Doctype 1"
|
||||
}
|
||||
],
|
||||
links: [],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import doctype_with_child_table from '../fixtures/doctype_with_child_table';
|
||||
import child_table_doctype from '../fixtures/child_table_doctype';
|
||||
import child_table_doctype_1 from '../fixtures/child_table_doctype_1';
|
||||
import doctype_to_link from '../fixtures/doctype_to_link';
|
||||
const doctype_to_link_name = doctype_to_link.name;
|
||||
const child_table_doctype_name = child_table_doctype.name;
|
||||
|
|
@ -9,6 +10,7 @@ context('Dashboard links', () => {
|
|||
cy.visit('/login');
|
||||
cy.login();
|
||||
cy.insert_doc('DocType', child_table_doctype, true);
|
||||
cy.insert_doc('DocType', child_table_doctype_1, true);
|
||||
cy.insert_doc('DocType', doctype_with_child_table, true);
|
||||
cy.insert_doc('DocType', doctype_to_link, true);
|
||||
return cy.window().its('frappe').then(frappe => {
|
||||
|
|
|
|||
107
cypress/integration/grid_search.js
Normal file
107
cypress/integration/grid_search.js
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
import doctype_with_child_table from '../fixtures/doctype_with_child_table';
|
||||
import child_table_doctype from '../fixtures/child_table_doctype';
|
||||
import child_table_doctype_1 from '../fixtures/child_table_doctype_1';
|
||||
const doctype_with_child_table_name = doctype_with_child_table.name;
|
||||
|
||||
context('Grid Search', () => {
|
||||
before(() => {
|
||||
cy.visit('/login');
|
||||
cy.login();
|
||||
cy.visit('/app/website');
|
||||
cy.insert_doc('DocType', child_table_doctype, true);
|
||||
cy.insert_doc('DocType', child_table_doctype_1, true);
|
||||
cy.insert_doc('DocType', doctype_with_child_table, true);
|
||||
return cy.window().its('frappe').then(frappe => {
|
||||
return frappe.xcall("frappe.tests.ui_test_helpers.insert_doctype_with_child_table_record", {
|
||||
name: doctype_with_child_table_name
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Test search row visibility', () => {
|
||||
cy.window().its('frappe').then(frappe => {
|
||||
frappe.model.user_settings.save('Doctype With Child Table', 'GridView', {
|
||||
'Child Table Doctype 1': [
|
||||
{'fieldname': 'data', 'columns': 2},
|
||||
{'fieldname': 'barcode', 'columns': 1},
|
||||
{'fieldname': 'check', 'columns': 1},
|
||||
{'fieldname': 'rating', 'columns': 2},
|
||||
{'fieldname': 'duration', 'columns': 2},
|
||||
{'fieldname': 'date', 'columns': 2}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
cy.visit(`/app/doctype-with-child-table/Test Grid Search`);
|
||||
|
||||
cy.get('.frappe-control[data-fieldname="child_table_1"]').as('table');
|
||||
cy.get('@table').find('.grid-row-check:last').click();
|
||||
cy.get('@table').find('.grid-footer').contains('Delete').click();
|
||||
cy.get('.grid-heading-row .grid-row .search').should('not.exist');
|
||||
});
|
||||
|
||||
it('test search field for different fieldtypes', () => {
|
||||
cy.visit(`/app/doctype-with-child-table/Test Grid Search`);
|
||||
|
||||
cy.get('.frappe-control[data-fieldname="child_table_1"]').as('table');
|
||||
|
||||
// Index Column
|
||||
cy.get('@table').find('.grid-heading-row .row-index.search input').type('3');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 2);
|
||||
cy.get('@table').find('.grid-heading-row .row-index.search input').clear();
|
||||
|
||||
// Data Column
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Data"]').type('Data');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 1);
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Data"]').clear();
|
||||
|
||||
// Barcode Column
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Barcode"]').type('092');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 4);
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Barcode"]').clear();
|
||||
|
||||
// Check Column
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Check"]').type('1');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 9);
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Check"]').clear();
|
||||
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Check"]').type('0');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 11);
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Check"]').clear();
|
||||
|
||||
// Rating Column
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Rating"]').type('3');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 3);
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Rating"]').clear();
|
||||
|
||||
// Duration Column
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Duration"]').type('3d');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 3);
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Duration"]').clear();
|
||||
|
||||
// Date Column
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Date"]').type('2022');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 4);
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Date"]').clear();
|
||||
});
|
||||
|
||||
it('test with multiple filter', () => {
|
||||
cy.get('.frappe-control[data-fieldname="child_table_1"]').as('table');
|
||||
|
||||
// Data Column
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Data"]').type('a');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 10);
|
||||
|
||||
// Barcode Column
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Barcode"]').type('0');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 8);
|
||||
|
||||
// Duration Column
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Duration"]').type('d');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 5);
|
||||
|
||||
// Date Column
|
||||
cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Date"]').type('02-');
|
||||
cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 2);
|
||||
});
|
||||
});
|
||||
38
cypress/integration/list_paging.js
Normal file
38
cypress/integration/list_paging.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
context('List Paging', () => {
|
||||
before(() => {
|
||||
cy.login();
|
||||
cy.visit('/app/website');
|
||||
return cy.window().its('frappe').then(frappe => {
|
||||
return frappe.call("frappe.tests.ui_test_helpers.create_multiple_todo_records");
|
||||
});
|
||||
});
|
||||
|
||||
it('test load more with count selection buttons', () => {
|
||||
cy.visit('/app/todo/view/report');
|
||||
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '20 of');
|
||||
cy.get('.list-paging-area .btn-more').click();
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '40 of');
|
||||
cy.get('.list-paging-area .btn-more').click();
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '60 of');
|
||||
|
||||
cy.get('.list-paging-area .btn-group .btn-paging[data-value="100"]').click();
|
||||
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '100 of');
|
||||
cy.get('.list-paging-area .btn-more').click();
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '200 of');
|
||||
cy.get('.list-paging-area .btn-more').click();
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '300 of');
|
||||
|
||||
// check if refresh works after load more
|
||||
cy.get('.page-head .standard-actions [data-original-title="Refresh"]').click();
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '300 of');
|
||||
|
||||
cy.get('.list-paging-area .btn-group .btn-paging[data-value="500"]').click();
|
||||
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '500 of');
|
||||
cy.get('.list-paging-area .btn-more').click();
|
||||
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '1000 of');
|
||||
});
|
||||
});
|
||||
22
cypress/integration/number_card.js
Normal file
22
cypress/integration/number_card.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
context('Number Card', () => {
|
||||
before(() => {
|
||||
cy.login();
|
||||
cy.visit('/app/website');
|
||||
});
|
||||
|
||||
it('Check filter populate for child table doctype', () => {
|
||||
cy.visit('/app/number-card/new-number-card-1');
|
||||
cy.get('[data-fieldname="parent_document_type"]').should('have.css', 'display', 'none');
|
||||
|
||||
cy.get_field('document_type', 'Link');
|
||||
cy.fill_field('document_type', 'Workspace Link', 'Link').focus().blur();
|
||||
cy.get_field('document_type', 'Link').should('have.value', 'Workspace Link');
|
||||
|
||||
cy.fill_field('label', 'Test Number Card', 'Data');
|
||||
|
||||
cy.get('[data-fieldname="filters_json"]').click().wait(200);
|
||||
cy.get('.modal-body .filter-action-buttons .add-filter').click();
|
||||
cy.get('.modal-body .fieldname-select-area').click();
|
||||
cy.get('.modal-actions .btn-modal-close').click();
|
||||
});
|
||||
});
|
||||
|
|
@ -13,9 +13,6 @@ context('Report View', () => {
|
|||
'enabled': 0,
|
||||
'docstatus': 1 // submit document
|
||||
}, true);
|
||||
return cy.window().its('frappe').then(frappe => {
|
||||
return frappe.call("frappe.tests.ui_test_helpers.create_multiple_contact_records");
|
||||
});
|
||||
});
|
||||
|
||||
it('Field with enabled allow_on_submit should be editable.', () => {
|
||||
|
|
@ -43,32 +40,4 @@ context('Report View', () => {
|
|||
expect(r.message.enabled).to.equals(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('test load more with count selection buttons', () => {
|
||||
cy.visit('/app/contact/view/report');
|
||||
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '20 of');
|
||||
cy.get('.list-paging-area .btn-more').click();
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '40 of');
|
||||
cy.get('.list-paging-area .btn-more').click();
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '60 of');
|
||||
|
||||
cy.get('.list-paging-area .btn-group .btn-paging[data-value="100"]').click();
|
||||
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '100 of');
|
||||
cy.get('.list-paging-area .btn-more').click();
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '200 of');
|
||||
cy.get('.list-paging-area .btn-more').click();
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '300 of');
|
||||
|
||||
// check if refresh works after load more
|
||||
cy.get('.page-head .standard-actions [data-original-title="Refresh"]').click();
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '300 of');
|
||||
|
||||
cy.get('.list-paging-area .btn-group .btn-paging[data-value="500"]').click();
|
||||
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '500 of');
|
||||
cy.get('.list-paging-area .btn-more').click();
|
||||
cy.get('.list-paging-area .list-count').should('contain.text', '1000 of');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ const cliui = require("cliui")();
|
|||
const chalk = require("chalk");
|
||||
const html_plugin = require("./frappe-html");
|
||||
const rtlcss = require('rtlcss');
|
||||
const postCssPlugin = require("esbuild-plugin-postcss2").default;
|
||||
const postCssPlugin = require("@frappe/esbuild-plugin-postcss2").default;
|
||||
const ignore_assets = require("./ignore-assets");
|
||||
const sass_options = require("./sass_options");
|
||||
const build_cleanup_plugin = require("./build-cleanup");
|
||||
|
|
@ -286,7 +286,7 @@ function get_watch_config() {
|
|||
notify_redis({ error });
|
||||
} else {
|
||||
let {
|
||||
assets_json,
|
||||
new_assets_json,
|
||||
prev_assets_json
|
||||
} = await write_assets_json(result.metafile);
|
||||
|
||||
|
|
@ -294,7 +294,7 @@ function get_watch_config() {
|
|||
if (prev_assets_json) {
|
||||
changed_files = get_rebuilt_assets(
|
||||
prev_assets_json,
|
||||
assets_json
|
||||
new_assets_json
|
||||
);
|
||||
|
||||
let timestamp = new Date().toLocaleTimeString();
|
||||
|
|
@ -384,6 +384,7 @@ let prev_assets_json;
|
|||
let curr_assets_json;
|
||||
|
||||
async function write_assets_json(metafile) {
|
||||
let rtl = false;
|
||||
prev_assets_json = curr_assets_json;
|
||||
let out = {};
|
||||
for (let output in metafile.outputs) {
|
||||
|
|
@ -392,13 +393,14 @@ async function write_assets_json(metafile) {
|
|||
if (info.entryPoint) {
|
||||
let key = path.basename(info.entryPoint);
|
||||
if (key.endsWith('.css') && asset_path.includes('/css-rtl/')) {
|
||||
rtl = true;
|
||||
key = `rtl_${key}`;
|
||||
}
|
||||
out[key] = asset_path;
|
||||
}
|
||||
}
|
||||
|
||||
let assets_json_path = path.resolve(assets_path, "assets.json");
|
||||
let assets_json_path = path.resolve(assets_path, `assets${rtl?'-rtl':''}.json`);
|
||||
let assets_json;
|
||||
try {
|
||||
assets_json = await fs.promises.readFile(assets_json_path, "utf-8");
|
||||
|
|
@ -407,21 +409,21 @@ async function write_assets_json(metafile) {
|
|||
}
|
||||
assets_json = JSON.parse(assets_json);
|
||||
// update with new values
|
||||
assets_json = Object.assign({}, assets_json, out);
|
||||
curr_assets_json = assets_json;
|
||||
let new_assets_json = Object.assign({}, assets_json, out);
|
||||
curr_assets_json = new_assets_json;
|
||||
|
||||
await fs.promises.writeFile(
|
||||
assets_json_path,
|
||||
JSON.stringify(assets_json, null, 4)
|
||||
JSON.stringify(new_assets_json, null, 4)
|
||||
);
|
||||
await update_assets_json_in_cache(assets_json);
|
||||
await update_assets_json_in_cache();
|
||||
return {
|
||||
assets_json,
|
||||
new_assets_json,
|
||||
prev_assets_json
|
||||
};
|
||||
}
|
||||
|
||||
function update_assets_json_in_cache(assets_json) {
|
||||
function update_assets_json_in_cache() {
|
||||
// update assets_json cache in redis, so that it can be read directly by python
|
||||
return new Promise(resolve => {
|
||||
let client = get_redis_subscriber("redis_cache");
|
||||
|
|
@ -429,7 +431,7 @@ function update_assets_json_in_cache(assets_json) {
|
|||
client.on("error", _ => {
|
||||
log_warn("Cannot connect to redis_cache to update assets_json");
|
||||
});
|
||||
client.set("assets_json", JSON.stringify(assets_json), err => {
|
||||
client.del("assets_json", err => {
|
||||
client.unref();
|
||||
resolve();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ module.exports = {
|
|||
.then(content => {
|
||||
content = scrub_html_template(content);
|
||||
return {
|
||||
contents: `\n\tfrappe.templates['${filename}'] = \`${content}\`;\n`
|
||||
contents: `\n\tfrappe.templates['${filename}'] = \`${content}\`;\n`,
|
||||
watchFiles: [filepath]
|
||||
};
|
||||
})
|
||||
.catch(() => {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ from frappe.query_builder import (
|
|||
patch_query_execute,
|
||||
patch_query_aggregation,
|
||||
)
|
||||
from frappe.utils.data import cstr
|
||||
|
||||
__version__ = '14.0.0-dev'
|
||||
|
||||
|
|
@ -215,6 +216,7 @@ def init(site, sites_path=None, new_site=False):
|
|||
local.cache = {}
|
||||
local.document_cache = {}
|
||||
local.meta_cache = {}
|
||||
local.autoincremented_status_map = {site: -1}
|
||||
local.form_dict = _dict()
|
||||
local.session = _dict()
|
||||
local.dev_server = _dev_server
|
||||
|
|
@ -851,8 +853,7 @@ def set_value(doctype, docname, fieldname, value=None):
|
|||
return frappe.client.set_value(doctype, docname, fieldname, value)
|
||||
|
||||
def get_cached_doc(*args, **kwargs):
|
||||
if args and len(args) > 1 and isinstance(args[1], str):
|
||||
key = get_document_cache_key(args[0], args[1])
|
||||
if key := can_cache_doc(args):
|
||||
# local cache
|
||||
doc = local.document_cache.get(key)
|
||||
if doc:
|
||||
|
|
@ -870,8 +871,24 @@ def get_cached_doc(*args, **kwargs):
|
|||
|
||||
return doc
|
||||
|
||||
def can_cache_doc(args):
|
||||
"""
|
||||
Determine if document should be cached based on get_doc params.
|
||||
Returns cache key if doc can be cached, None otherwise.
|
||||
"""
|
||||
|
||||
if not args:
|
||||
return
|
||||
|
||||
doctype = args[0]
|
||||
name = doctype if len(args) == 1 else args[1]
|
||||
|
||||
# Only cache if both doctype and name are strings
|
||||
if isinstance(doctype, str) and isinstance(name, str):
|
||||
return get_document_cache_key(doctype, name)
|
||||
|
||||
def get_document_cache_key(doctype, name):
|
||||
return '{0}::{1}'.format(doctype, name)
|
||||
return f'{doctype}::{name}'
|
||||
|
||||
def clear_document_cache(doctype, name):
|
||||
cache().hdel("last_modified", doctype)
|
||||
|
|
@ -912,8 +929,7 @@ def get_doc(*args, **kwargs):
|
|||
doc = frappe.model.document.get_doc(*args, **kwargs)
|
||||
|
||||
# set in cache
|
||||
if args and len(args) > 1:
|
||||
key = get_document_cache_key(args[0], args[1])
|
||||
if key := can_cache_doc(args):
|
||||
local.document_cache[key] = doc
|
||||
cache().hset('document_cache', key, doc.as_dict())
|
||||
|
||||
|
|
@ -963,8 +979,7 @@ def delete_doc(doctype=None, name=None, force=0, ignore_doctypes=None, for_reloa
|
|||
|
||||
def delete_doc_if_exists(doctype, name, force=0):
|
||||
"""Delete document if exists."""
|
||||
if db.exists(doctype, name):
|
||||
delete_doc(doctype, name, force=force)
|
||||
delete_doc(doctype, name, force=force, ignore_missing=True)
|
||||
|
||||
def reload_doctype(doctype, force=False, reset_permissions=False):
|
||||
"""Reload DocType from model (`[module]/[doctype]/[name]/[name].json`) files."""
|
||||
|
|
@ -1002,7 +1017,7 @@ def get_module(modulename):
|
|||
|
||||
def scrub(txt):
|
||||
"""Returns sluggified string. e.g. `Sales Order` becomes `sales_order`."""
|
||||
return txt.replace(' ', '_').replace('-', '_').lower()
|
||||
return cstr(txt).replace(' ', '_').replace('-', '_').lower()
|
||||
|
||||
def unscrub(txt):
|
||||
"""Returns titlified string. e.g. `sales_order` becomes `Sales Order`."""
|
||||
|
|
@ -1237,9 +1252,10 @@ def get_newargs(fn, kwargs):
|
|||
if hasattr(fn, 'fnargs'):
|
||||
fnargs = fn.fnargs
|
||||
else:
|
||||
fnargs = inspect.getfullargspec(fn).args
|
||||
fnargs.extend(inspect.getfullargspec(fn).kwonlyargs)
|
||||
varkw = inspect.getfullargspec(fn).varkw
|
||||
fullargspec = inspect.getfullargspec(fn)
|
||||
fnargs = fullargspec.args
|
||||
fnargs.extend(fullargspec.kwonlyargs)
|
||||
varkw = fullargspec.varkw
|
||||
|
||||
newargs = {}
|
||||
for a in kwargs:
|
||||
|
|
|
|||
|
|
@ -325,6 +325,7 @@ def get_desk_settings():
|
|||
def get_notification_settings():
|
||||
return frappe.get_cached_doc('Notification Settings', frappe.session.user)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_link_title_doctypes():
|
||||
dts = frappe.get_all("DocType", {"show_title_field_in_link": 1})
|
||||
custom_dts = frappe.get_all(
|
||||
|
|
|
|||
|
|
@ -677,7 +677,9 @@ def _drop_site(site, db_root_username=None, db_root_password=None, archived_site
|
|||
|
||||
try:
|
||||
if not no_backup:
|
||||
scheduled_backup(ignore_files=False, force=True)
|
||||
click.secho(f"Taking backup of {site}", fg="green")
|
||||
odb = scheduled_backup(ignore_files=False, force=True, verbose=True)
|
||||
odb.print_summary()
|
||||
except Exception as err:
|
||||
if force:
|
||||
pass
|
||||
|
|
@ -692,6 +694,7 @@ def _drop_site(site, db_root_username=None, db_root_password=None, archived_site
|
|||
click.echo("\n".join(messages))
|
||||
sys.exit(1)
|
||||
|
||||
click.secho("Dropping site database and user", fg="green")
|
||||
drop_user_and_database(frappe.conf.db_name, db_root_username, db_root_password)
|
||||
|
||||
archived_sites_path = archived_sites_path or os.path.join(frappe.get_app_path('frappe'), '..', '..', '..', 'archived', 'sites')
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ from urllib.parse import unquote
|
|||
from frappe.utils.user import is_system_user
|
||||
from frappe.contacts.doctype.contact.contact import get_contact_name
|
||||
from frappe.automation.doctype.assignment_rule.assignment_rule import apply as apply_assignment_rule
|
||||
from parse import compile
|
||||
|
||||
exclude_from_linked_with = True
|
||||
|
||||
|
|
@ -114,6 +115,44 @@ class Communication(Document, CommunicationEmailMixin):
|
|||
frappe.publish_realtime('new_message', self.as_dict(),
|
||||
user=self.reference_name, after_commit=True)
|
||||
|
||||
def set_signature_in_email_content(self):
|
||||
"""Set sender's User.email_signature or default outgoing's EmailAccount.signature to the email
|
||||
"""
|
||||
if not self.content:
|
||||
return
|
||||
|
||||
quill_parser = compile('<div class="ql-editor read-mode">{}</div>')
|
||||
email_body = quill_parser.parse(self.content)
|
||||
|
||||
if not email_body:
|
||||
return
|
||||
|
||||
email_body = email_body[0]
|
||||
|
||||
user_email_signature = frappe.db.get_value(
|
||||
"User",
|
||||
self.sender,
|
||||
"email_signature",
|
||||
) if self.sender else None
|
||||
|
||||
signature = user_email_signature or frappe.db.get_value(
|
||||
"Email Account",
|
||||
{"default_outgoing": 1, "add_signature": 1},
|
||||
"signature",
|
||||
)
|
||||
|
||||
if not signature:
|
||||
return
|
||||
|
||||
_signature = quill_parser.parse(signature)[0] if "ql-editor" in signature else None
|
||||
|
||||
if (_signature or signature) not in self.content:
|
||||
self.content = f'{self.content}</p><br><p class="signature">{signature}'
|
||||
|
||||
def before_save(self):
|
||||
if not self.flags.skip_add_signature:
|
||||
self.set_signature_in_email_content()
|
||||
|
||||
def on_update(self):
|
||||
# add to _comment property of the doctype, so it shows up in
|
||||
# comments count for the list view
|
||||
|
|
|
|||
|
|
@ -22,12 +22,30 @@ OUTGOING_EMAIL_ACCOUNT_MISSING = _("""
|
|||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make(doctype=None, name=None, content=None, subject=None, sent_or_received = "Sent",
|
||||
sender=None, sender_full_name=None, recipients=None, communication_medium="Email", send_email=False,
|
||||
print_html=None, print_format=None, attachments='[]', send_me_a_copy=False, cc=None, bcc=None,
|
||||
flags=None, read_receipt=None, print_letterhead=True, email_template=None, communication_type=None,
|
||||
ignore_permissions=False) -> Dict[str, str]:
|
||||
"""Make a new communication.
|
||||
def make(
|
||||
doctype=None,
|
||||
name=None,
|
||||
content=None,
|
||||
subject=None,
|
||||
sent_or_received="Sent",
|
||||
sender=None,
|
||||
sender_full_name=None,
|
||||
recipients=None,
|
||||
communication_medium="Email",
|
||||
send_email=False,
|
||||
print_html=None,
|
||||
print_format=None,
|
||||
attachments="[]",
|
||||
send_me_a_copy=False,
|
||||
cc=None,
|
||||
bcc=None,
|
||||
read_receipt=None,
|
||||
print_letterhead=True,
|
||||
email_template=None,
|
||||
communication_type=None,
|
||||
**kwargs,
|
||||
) -> Dict[str, str]:
|
||||
"""Make a new communication. Checks for email permissions for specified Document.
|
||||
|
||||
:param doctype: Reference DocType.
|
||||
:param name: Reference Document name.
|
||||
|
|
@ -44,17 +62,71 @@ def make(doctype=None, name=None, content=None, subject=None, sent_or_received =
|
|||
:param send_me_a_copy: Send a copy to the sender (default **False**).
|
||||
:param email_template: Template which is used to compose mail .
|
||||
"""
|
||||
is_error_report = (doctype=="User" and name==frappe.session.user and subject=="Error Report")
|
||||
send_me_a_copy = cint(send_me_a_copy)
|
||||
if kwargs:
|
||||
from frappe.utils.commands import warn
|
||||
warn(
|
||||
f"Options {kwargs} used in frappe.core.doctype.communication.email.make "
|
||||
"are deprecated or unsupported",
|
||||
category=DeprecationWarning
|
||||
)
|
||||
|
||||
if not ignore_permissions:
|
||||
if doctype and name and not is_error_report and not frappe.has_permission(doctype, "email", name) and not (flags or {}).get('ignore_doctype_permissions'):
|
||||
raise frappe.PermissionError("You are not allowed to send emails related to: {doctype} {name}".format(
|
||||
doctype=doctype, name=name))
|
||||
if doctype and name and not frappe.has_permission(doctype=doctype, ptype="email", doc=name):
|
||||
raise frappe.PermissionError(
|
||||
f"You are not allowed to send emails related to: {doctype} {name}"
|
||||
)
|
||||
|
||||
if not sender:
|
||||
sender = get_formatted_email(frappe.session.user)
|
||||
return _make(
|
||||
doctype=doctype,
|
||||
name=name,
|
||||
content=content,
|
||||
subject=subject,
|
||||
sent_or_received=sent_or_received,
|
||||
sender=sender,
|
||||
sender_full_name=sender_full_name,
|
||||
recipients=recipients,
|
||||
communication_medium=communication_medium,
|
||||
send_email=send_email,
|
||||
print_html=print_html,
|
||||
print_format=print_format,
|
||||
attachments=attachments,
|
||||
send_me_a_copy=cint(send_me_a_copy),
|
||||
cc=cc,
|
||||
bcc=bcc,
|
||||
read_receipt=read_receipt,
|
||||
print_letterhead=print_letterhead,
|
||||
email_template=email_template,
|
||||
communication_type=communication_type,
|
||||
add_signature=False,
|
||||
)
|
||||
|
||||
|
||||
def _make(
|
||||
doctype=None,
|
||||
name=None,
|
||||
content=None,
|
||||
subject=None,
|
||||
sent_or_received="Sent",
|
||||
sender=None,
|
||||
sender_full_name=None,
|
||||
recipients=None,
|
||||
communication_medium="Email",
|
||||
send_email=False,
|
||||
print_html=None,
|
||||
print_format=None,
|
||||
attachments="[]",
|
||||
send_me_a_copy=False,
|
||||
cc=None,
|
||||
bcc=None,
|
||||
read_receipt=None,
|
||||
print_letterhead=True,
|
||||
email_template=None,
|
||||
communication_type=None,
|
||||
add_signature=True,
|
||||
) -> Dict[str, str]:
|
||||
"""Internal method to make a new communication that ignores Permission checks.
|
||||
"""
|
||||
|
||||
sender = sender or get_formatted_email(frappe.session.user)
|
||||
recipients = list_to_str(recipients) if isinstance(recipients, list) else recipients
|
||||
cc = list_to_str(cc) if isinstance(cc, list) else cc
|
||||
bcc = list_to_str(bcc) if isinstance(bcc, list) else bcc
|
||||
|
|
@ -77,7 +149,9 @@ def make(doctype=None, name=None, content=None, subject=None, sent_or_received =
|
|||
"read_receipt":read_receipt,
|
||||
"has_attachment": 1 if attachments else 0,
|
||||
"communication_type": communication_type,
|
||||
}).insert(ignore_permissions=True)
|
||||
})
|
||||
comm.flags.skip_add_signature = not add_signature
|
||||
comm.insert(ignore_permissions=True)
|
||||
|
||||
# if not committed, delayed task doesn't find the communication
|
||||
if attachments:
|
||||
|
|
@ -87,17 +161,21 @@ def make(doctype=None, name=None, content=None, subject=None, sent_or_received =
|
|||
|
||||
if cint(send_email):
|
||||
if not comm.get_outgoing_email_account():
|
||||
frappe.throw(msg=OUTGOING_EMAIL_ACCOUNT_MISSING, exc=frappe.OutgoingEmailError)
|
||||
frappe.throw(
|
||||
msg=OUTGOING_EMAIL_ACCOUNT_MISSING, exc=frappe.OutgoingEmailError
|
||||
)
|
||||
|
||||
comm.send_email(print_html=print_html, print_format=print_format,
|
||||
send_me_a_copy=send_me_a_copy, print_letterhead=print_letterhead)
|
||||
comm.send_email(
|
||||
print_html=print_html,
|
||||
print_format=print_format,
|
||||
send_me_a_copy=send_me_a_copy,
|
||||
print_letterhead=print_letterhead,
|
||||
)
|
||||
|
||||
emails_not_sent_to = comm.exclude_emails_list(include_sender=send_me_a_copy)
|
||||
|
||||
return {
|
||||
"name": comm.name,
|
||||
"emails_not_sent_to": ", ".join(emails_not_sent_to)
|
||||
}
|
||||
return {"name": comm.name, "emails_not_sent_to": ", ".join(emails_not_sent_to)}
|
||||
|
||||
|
||||
def validate_email(doc: "Communication") -> None:
|
||||
"""Validate Email Addresses of Recipients and CC"""
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import unittest
|
|||
from urllib.parse import quote
|
||||
|
||||
import frappe
|
||||
from frappe.email.doctype.email_queue.email_queue import EmailQueue
|
||||
from frappe.core.doctype.communication.communication import get_emails
|
||||
from frappe.email.doctype.email_queue.email_queue import EmailQueue
|
||||
|
||||
test_records = frappe.get_test_records('Communication')
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ class TestCommunication(unittest.TestCase):
|
|||
|
||||
self.assertIn(("Note", note.name), doc_links)
|
||||
|
||||
def parse_emails(self):
|
||||
def test_parse_emails(self):
|
||||
emails = get_emails(
|
||||
[
|
||||
'comm_recipient+DocType+DocName@example.com',
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ class DataExporter:
|
|||
d = doc.copy()
|
||||
meta = frappe.get_meta(dt)
|
||||
if self.all_doctypes:
|
||||
d.name = '"'+ d.name+'"'
|
||||
d.name = f'"{d.name}"'
|
||||
|
||||
if len(rows) < rowidx + 1:
|
||||
rows.append([""] * (len(self.columns) + 1))
|
||||
|
|
|
|||
|
|
@ -61,6 +61,13 @@ frappe.ui.form.on('DocType', {
|
|||
frm.events.set_naming_rule_description(frm);
|
||||
},
|
||||
|
||||
istable: (frm) => {
|
||||
if (frm.doc.istable && frm.is_new()) {
|
||||
frm.set_value('autoname', 'autoincrement');
|
||||
frm.set_value('allow_rename', 0);
|
||||
}
|
||||
},
|
||||
|
||||
naming_rule: function(frm) {
|
||||
// set the "autoname" property based on naming_rule
|
||||
if (frm.doc.naming_rule && !frm.__from_autoname) {
|
||||
|
|
@ -70,6 +77,10 @@ frappe.ui.form.on('DocType', {
|
|||
|
||||
if (frm.doc.naming_rule=='Set by user') {
|
||||
frm.set_value('autoname', 'Prompt');
|
||||
} else if (frm.doc.naming_rule === 'Autoincrement') {
|
||||
frm.set_value('autoname', 'autoincrement');
|
||||
// set allow rename to be false when using autoincrement
|
||||
frm.set_value('allow_rename', 0);
|
||||
} else if (frm.doc.naming_rule=='By fieldname') {
|
||||
frm.set_value('autoname', 'field:');
|
||||
} else if (frm.doc.naming_rule=='By "Naming Series" field') {
|
||||
|
|
@ -91,6 +102,7 @@ frappe.ui.form.on('DocType', {
|
|||
set_naming_rule_description(frm) {
|
||||
let naming_rule_description = {
|
||||
'Set by user': '',
|
||||
'Autoincrement': 'Uses Auto Increment feature of database.<br><b>WARNING: After using this option, any other naming option will not be accessible.</b>',
|
||||
'By fieldname': 'Format: <code>field:[fieldname]</code>. Valid fieldname must exist',
|
||||
'By "Naming Series" field': 'Format: <code>naming_series:[fieldname]</code>. Fieldname called <code>naming_series</code> must exist',
|
||||
'Expression': 'Format: <code>format:EXAMPLE-{MM}morewords{fieldname1}-{fieldname2}-{#####}</code> - Replace all braced words (fieldnames, date words (DD, MM, YY), series) with their value. Outside braces, any characters can be used.',
|
||||
|
|
@ -111,6 +123,8 @@ frappe.ui.form.on('DocType', {
|
|||
frm.__from_autoname = true;
|
||||
if (frm.doc.autoname.toLowerCase() === 'prompt') {
|
||||
frm.set_value('naming_rule', 'Set by user');
|
||||
} else if (frm.doc.autoname.toLowerCase() === 'autoincrement') {
|
||||
frm.set_value('naming_rule', 'Autoincrement');
|
||||
} else if (frm.doc.autoname.startsWith('field:')) {
|
||||
frm.set_value('naming_rule', 'By fieldname');
|
||||
} else if (frm.doc.autoname.startsWith('naming_series:')) {
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@
|
|||
"label": "Naming"
|
||||
},
|
||||
{
|
||||
"description": "Naming Options:\n<ol><li><b>field:[fieldname]</b> - By Field</li><li><b>naming_series:</b> - By Naming Series (field called naming_series must be present</li><li><b>Prompt</b> - Prompt user for a name</li><li><b>[series]</b> - Series by prefix (separated by a dot); for example PRE.#####</li>\n<li><b>format:EXAMPLE-{MM}morewords{fieldname1}-{fieldname2}-{#####}</b> - Replace all braced words (fieldnames, date words (DD, MM, YY), series) with their value. Outside braces, any characters can be used.</li></ol>",
|
||||
"description": "Naming Options:\n<ol><li><b>field:[fieldname]</b> - By Field</li><li><b>autoincrement</b> - Uses Databases' Auto Increment feature</li><li><b>naming_series:</b> - By Naming Series (field called naming_series must be present</li><li><b>Prompt</b> - Prompt user for a name</li><li><b>[series]</b> - Series by prefix (separated by a dot); for example PRE.#####</li>\n<li><b>format:EXAMPLE-{MM}morewords{fieldname1}-{fieldname2}-{#####}</b> - Replace all braced words (fieldnames, date words (DD, MM, YY), series) with their value. Outside braces, any characters can be used.</li></ol>",
|
||||
"fieldname": "autoname",
|
||||
"fieldtype": "Data",
|
||||
"label": "Auto Name",
|
||||
|
|
@ -216,6 +216,7 @@
|
|||
"oldfieldtype": "Data"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.naming_rule !== \"Autoincrement\"",
|
||||
"fieldname": "name_case",
|
||||
"fieldtype": "Select",
|
||||
"label": "Name Case",
|
||||
|
|
@ -282,6 +283,7 @@
|
|||
},
|
||||
{
|
||||
"default": "1",
|
||||
"depends_on": "eval:doc.naming_rule !== \"Autoincrement\"",
|
||||
"fieldname": "allow_rename",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow Rename",
|
||||
|
|
@ -565,7 +567,7 @@
|
|||
"fieldtype": "Select",
|
||||
"label": "Naming Rule",
|
||||
"length": 40,
|
||||
"options": "\nSet by user\nBy fieldname\nBy \"Naming Series\" field\nExpression\nExpression (old style)\nRandom\nBy script"
|
||||
"options": "\nSet by user\nAutoincrement\nBy fieldname\nBy \"Naming Series\" field\nExpression\nExpression (old style)\nRandom\nBy script"
|
||||
},
|
||||
{
|
||||
"fieldname": "migration_hash",
|
||||
|
|
@ -593,6 +595,7 @@
|
|||
],
|
||||
"icon": "fa fa-bolt",
|
||||
"idx": 6,
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [
|
||||
{
|
||||
"group": "Views",
|
||||
|
|
@ -670,10 +673,11 @@
|
|||
"link_fieldname": "reference_doctype"
|
||||
}
|
||||
],
|
||||
"modified": "2022-01-07 16:07:06.196534",
|
||||
"modified": "2022-02-15 21:47:16.467217",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Core",
|
||||
"name": "DocType",
|
||||
"naming_rule": "Set by user",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
|
|
@ -703,5 +707,6 @@
|
|||
"show_name_in_global_search": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
|
|
@ -60,6 +60,7 @@ class DocType(Document):
|
|||
|
||||
self.check_developer_mode()
|
||||
|
||||
self.validate_autoname()
|
||||
self.validate_name()
|
||||
|
||||
self.set_defaults_for_single_and_table()
|
||||
|
|
@ -714,6 +715,18 @@ class DocType(Document):
|
|||
self.name)
|
||||
return max_idx and max_idx[0][0] or 0
|
||||
|
||||
def validate_autoname(self):
|
||||
if not self.is_new():
|
||||
doc_before_save = self.get_doc_before_save()
|
||||
if doc_before_save:
|
||||
if (self.autoname == "autoincrement" and doc_before_save.autoname != "autoincrement") \
|
||||
or (self.autoname != "autoincrement" and doc_before_save.autoname == "autoincrement"):
|
||||
frappe.throw(_("Cannot change to/from Autoincrement naming rule"))
|
||||
|
||||
else:
|
||||
if self.autoname == "autoincrement":
|
||||
self.allow_rename = 0
|
||||
|
||||
def validate_name(self, name=None):
|
||||
if not name:
|
||||
name = self.name
|
||||
|
|
@ -732,9 +745,12 @@ class DocType(Document):
|
|||
frappe.throw(_("DocType's name should not start or end with whitespace"), frappe.NameError)
|
||||
|
||||
# a DocType's name should not start with a number or underscore
|
||||
# and should only contain letters, numbers and underscore
|
||||
if not re.match(r"^(?![\W])[^\d_\s][\w ]+$", name, **flags):
|
||||
frappe.throw(_("DocType's name should start with a letter and it can only consist of letters, numbers, spaces and underscores"), frappe.NameError)
|
||||
# and should only contain letters, numbers, underscore, and hyphen
|
||||
if not re.match(r"^(?![\W])[^\d_\s][\w -]+$", name, **flags):
|
||||
frappe.throw(_(
|
||||
"A DocType's name should start with a letter and can only "
|
||||
"consist of letters, numbers, spaces, underscores and hyphens"
|
||||
), frappe.NameError, title="Invalid Name")
|
||||
|
||||
validate_route_conflict(self.doctype, self.name)
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class TestDocType(unittest.TestCase):
|
|||
self.assertRaises(frappe.NameError, new_doctype("8Some DocType").insert)
|
||||
self.assertRaises(frappe.NameError, new_doctype("Some (DocType)").insert)
|
||||
self.assertRaises(frappe.NameError, new_doctype("Some Doctype with a name whose length is more than 61 characters").insert)
|
||||
for name in ("Some DocType", "Some_DocType"):
|
||||
for name in ("Some DocType", "Some_DocType", "Some-DocType"):
|
||||
if frappe.db.exists("DocType", name):
|
||||
frappe.delete_doc("DocType", name)
|
||||
|
||||
|
|
@ -505,7 +505,23 @@ class TestDocType(unittest.TestCase):
|
|||
|
||||
dt.delete()
|
||||
|
||||
def new_doctype(name, unique=0, depends_on='', fields=None):
|
||||
def test_autoincremented_doctype_transition(self):
|
||||
frappe.delete_doc("testy_autoinc_dt")
|
||||
dt = new_doctype("testy_autoinc_dt", autoincremented=True).insert(ignore_permissions=True)
|
||||
dt.autoname = "hash"
|
||||
|
||||
try:
|
||||
dt.save(ignore_permissions=True)
|
||||
except frappe.ValidationError as e:
|
||||
self.assertEqual(e.args[0], "Cannot change to/from Autoincrement naming rule")
|
||||
else:
|
||||
self.fail("Shouldnt be possible to transition autoincremented doctype to any other naming rule")
|
||||
finally:
|
||||
# cleanup
|
||||
dt.delete(ignore_permissions=True)
|
||||
|
||||
|
||||
def new_doctype(name, unique=0, depends_on='', fields=None, autoincremented=False):
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "DocType",
|
||||
"module": "Core",
|
||||
|
|
@ -521,7 +537,8 @@ def new_doctype(name, unique=0, depends_on='', fields=None):
|
|||
"role": "System Manager",
|
||||
"read": 1,
|
||||
}],
|
||||
"name": name
|
||||
"name": name,
|
||||
"autoname": "autoincrement" if autoincremented else ""
|
||||
})
|
||||
|
||||
if fields:
|
||||
|
|
|
|||
|
|
@ -382,7 +382,7 @@ class TestFile(unittest.TestCase):
|
|||
}).insert(ignore_permissions=True)
|
||||
|
||||
test_file.make_thumbnail()
|
||||
self.assertEquals(test_file.thumbnail_url, '/files/image_small.jpg')
|
||||
self.assertEqual(test_file.thumbnail_url, '/files/image_small.jpg')
|
||||
|
||||
# test web image without extension
|
||||
test_file = frappe.get_doc({
|
||||
|
|
@ -399,7 +399,7 @@ class TestFile(unittest.TestCase):
|
|||
test_file.reload()
|
||||
test_file.file_url = "/files/image_small.jpg"
|
||||
test_file.make_thumbnail(suffix="xs", crop=True)
|
||||
self.assertEquals(test_file.thumbnail_url, '/files/image_small_xs.jpg')
|
||||
self.assertEqual(test_file.thumbnail_url, '/files/image_small_xs.jpg')
|
||||
|
||||
frappe.clear_messages()
|
||||
test_file.db_set('thumbnail_url', None)
|
||||
|
|
@ -407,7 +407,7 @@ class TestFile(unittest.TestCase):
|
|||
test_file.file_url = frappe.utils.get_url('unknown.jpg')
|
||||
test_file.make_thumbnail(suffix="xs")
|
||||
self.assertEqual(json.loads(frappe.message_log[0]).get("message"), f"File '{frappe.utils.get_url('unknown.jpg')}' not found")
|
||||
self.assertEquals(test_file.thumbnail_url, None)
|
||||
self.assertEqual(test_file.thumbnail_url, None)
|
||||
|
||||
def test_file_unzip(self):
|
||||
file_path = frappe.get_app_path('frappe', 'www/_test/assets/file.zip')
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class Role(Document):
|
|||
|
||||
def get_info_based_on_role(role, field='email'):
|
||||
''' Get information of all users that have been assigned this role '''
|
||||
users = frappe.get_list("Has Role", filters={"role": role, "parenttype": "User"},
|
||||
users = frappe.get_list("Has Role", filters={"role": role}, parent_doctype="User",
|
||||
fields=["parent as user_name"])
|
||||
|
||||
return get_user_info(users, field)
|
||||
|
|
|
|||
|
|
@ -112,7 +112,10 @@ class TestServerScript(unittest.TestCase):
|
|||
self.assertEqual(frappe.get_doc('Server Script', 'test_return_value').execute_method(), 'hello')
|
||||
|
||||
def test_permission_query(self):
|
||||
self.assertTrue('where (1 = 1)' in frappe.db.get_list('ToDo', run=False))
|
||||
if frappe.conf.db_type == "mariadb":
|
||||
self.assertTrue('where (1 = 1)' in frappe.db.get_list('ToDo', run=False))
|
||||
else:
|
||||
self.assertTrue('where (1 = \'1\')' in frappe.db.get_list('ToDo', run=False))
|
||||
self.assertTrue(isinstance(frappe.db.get_list('ToDo'), list))
|
||||
|
||||
def test_attribute_error(self):
|
||||
|
|
|
|||
|
|
@ -668,8 +668,7 @@
|
|||
"link_fieldname": "user"
|
||||
}
|
||||
],
|
||||
"max_attachments": 5,
|
||||
"modified": "2022-01-03 11:53:25.250822",
|
||||
"modified": "2022-03-09 01:47:56.745069",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Core",
|
||||
"name": "User",
|
||||
|
|
|
|||
|
|
@ -253,8 +253,8 @@ class User(Document):
|
|||
self.email_new_password(new_password)
|
||||
|
||||
except frappe.OutgoingEmailError:
|
||||
print(frappe.get_traceback())
|
||||
pass # email server not set, don't send email
|
||||
# email server not set, don't send email
|
||||
frappe.log_error(frappe.get_traceback())
|
||||
|
||||
@Document.hook
|
||||
def validate_reset_password(self):
|
||||
|
|
|
|||
|
|
@ -44,8 +44,9 @@ frappe.ui.form.on('User Permission', {
|
|||
|
||||
set_applicable_for_constraint: frm => {
|
||||
frm.toggle_reqd('applicable_for', !frm.doc.apply_to_all_doctypes);
|
||||
|
||||
if (frm.doc.apply_to_all_doctypes && frm.doc.applicable_for) {
|
||||
frm.set_value('applicable_for', null);
|
||||
frm.set_value('applicable_for', null, null, true);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ frappe.ui.form.on("Customize Form", {
|
|||
},
|
||||
|
||||
onload: function(frm) {
|
||||
frm.disable_save();
|
||||
frm.set_query("doc_type", function() {
|
||||
return {
|
||||
translate_values: false,
|
||||
|
|
@ -110,7 +109,7 @@ frappe.ui.form.on("Customize Form", {
|
|||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
frm.disable_save();
|
||||
frm.disable_save(true);
|
||||
frm.page.clear_icons();
|
||||
|
||||
if (frm.doc.doc_type) {
|
||||
|
|
@ -169,7 +168,7 @@ frappe.ui.form.on("Customize Form", {
|
|||
doc_type = localStorage.getItem("customize_doctype");
|
||||
}
|
||||
if (doc_type) {
|
||||
setTimeout(() => frm.set_value("doc_type", doc_type), 1000);
|
||||
setTimeout(() => frm.set_value("doc_type", doc_type, false, true), 1000);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -341,11 +340,11 @@ frappe.customize_form.confirm = function(msg, frm) {
|
|||
}
|
||||
|
||||
frappe.customize_form.clear_locals_and_refresh = function(frm) {
|
||||
delete frm.doc.__unsaved;
|
||||
// clear doctype from locals
|
||||
frappe.model.clear_doc("DocType", frm.doc.doc_type);
|
||||
delete frappe.meta.docfield_copy[frm.doc.doc_type];
|
||||
|
||||
frm.refresh();
|
||||
}
|
||||
};
|
||||
|
||||
extend_cscript(cur_frm.cscript, new frappe.model.DocTypeController({frm: cur_frm}));
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ def setup_database(force, source_sql=None, verbose=None, no_mariadb_socket=False
|
|||
def drop_user_and_database(db_name, root_login=None, root_password=None):
|
||||
import frappe
|
||||
if frappe.conf.db_type == 'postgres':
|
||||
pass
|
||||
import frappe.database.postgres.setup_db
|
||||
return frappe.database.postgres.setup_db.drop_user_and_database(db_name, root_login, root_password)
|
||||
else:
|
||||
import frappe.database.mariadb.setup_db
|
||||
return frappe.database.mariadb.setup_db.drop_user_and_database(db_name, root_login, root_password)
|
||||
|
|
|
|||
|
|
@ -119,6 +119,9 @@ class Database(object):
|
|||
if not run:
|
||||
return query
|
||||
|
||||
# remove \n \t from start and end of query
|
||||
query = re.sub(r'^\s*|\s*$', '', query)
|
||||
|
||||
if re.search(r'ifnull\(', query, flags=re.IGNORECASE):
|
||||
# replaces ifnull in query with coalesce
|
||||
query = re.sub(r'ifnull\(', 'coalesce(', query, flags=re.IGNORECASE)
|
||||
|
|
@ -142,8 +145,6 @@ class Database(object):
|
|||
self.log_query(query, values, debug, explain)
|
||||
|
||||
if values!=():
|
||||
if isinstance(values, dict):
|
||||
values = dict(values)
|
||||
|
||||
# MySQL-python==1.2.5 hack!
|
||||
if not isinstance(values, (dict, tuple, list)):
|
||||
|
|
@ -181,7 +182,7 @@ class Database(object):
|
|||
print(e)
|
||||
raise
|
||||
|
||||
if ignore_ddl and (self.is_missing_column(e) or self.is_missing_table(e) or self.cant_drop_field_or_key(e)):
|
||||
if ignore_ddl and (self.is_missing_column(e) or self.is_table_missing(e) or self.cant_drop_field_or_key(e)):
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
|
|
@ -386,7 +387,7 @@ class Database(object):
|
|||
"""
|
||||
|
||||
ret = self.get_values(doctype, filters, fieldname, ignore, as_dict, debug,
|
||||
order_by, cache=cache, for_update=for_update, run=run, pluck=pluck, distinct=distinct)
|
||||
order_by, cache=cache, for_update=for_update, run=run, pluck=pluck, distinct=distinct, limit=1)
|
||||
|
||||
if not run:
|
||||
return ret
|
||||
|
|
@ -395,7 +396,7 @@ class Database(object):
|
|||
|
||||
def get_values(self, doctype, filters=None, fieldname="name", ignore=None, as_dict=False,
|
||||
debug=False, order_by="KEEP_DEFAULT_ORDERING", update=None, cache=False, for_update=False,
|
||||
run=True, pluck=False, distinct=False):
|
||||
run=True, pluck=False, distinct=False, limit=None):
|
||||
"""Returns multiple document properties.
|
||||
|
||||
:param doctype: DocType name.
|
||||
|
|
@ -425,14 +426,15 @@ class Database(object):
|
|||
|
||||
if isinstance(filters, list):
|
||||
out = self._get_value_for_many_names(
|
||||
doctype,
|
||||
filters,
|
||||
fieldname,
|
||||
order_by,
|
||||
doctype=doctype,
|
||||
names=filters,
|
||||
field=fieldname,
|
||||
order_by=order_by,
|
||||
debug=debug,
|
||||
run=run,
|
||||
pluck=pluck,
|
||||
distinct=distinct,
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
else:
|
||||
|
|
@ -446,17 +448,18 @@ class Database(object):
|
|||
if order_by:
|
||||
order_by = "modified" if order_by == "KEEP_DEFAULT_ORDERING" else order_by
|
||||
out = self._get_values_from_table(
|
||||
fields,
|
||||
filters,
|
||||
doctype,
|
||||
as_dict,
|
||||
debug,
|
||||
order_by,
|
||||
update,
|
||||
fields=fields,
|
||||
filters=filters,
|
||||
doctype=doctype,
|
||||
as_dict=as_dict,
|
||||
debug=debug,
|
||||
order_by=order_by,
|
||||
update=update,
|
||||
for_update=for_update,
|
||||
run=run,
|
||||
pluck=pluck,
|
||||
distinct=distinct
|
||||
distinct=distinct,
|
||||
limit=limit,
|
||||
)
|
||||
except Exception as e:
|
||||
if ignore and (frappe.db.is_missing_column(e) or frappe.db.is_table_missing(e)):
|
||||
|
|
@ -625,6 +628,7 @@ class Database(object):
|
|||
run=True,
|
||||
pluck=False,
|
||||
distinct=False,
|
||||
limit=None,
|
||||
):
|
||||
field_objects = []
|
||||
|
||||
|
|
@ -643,6 +647,7 @@ class Database(object):
|
|||
field_objects=field_objects,
|
||||
fields=fields,
|
||||
distinct=distinct,
|
||||
limit=limit,
|
||||
)
|
||||
if (
|
||||
fields == "*"
|
||||
|
|
@ -656,7 +661,7 @@ class Database(object):
|
|||
)
|
||||
return r
|
||||
|
||||
def _get_value_for_many_names(self, doctype, names, field, order_by, debug=False, run=True, pluck=False, distinct=False):
|
||||
def _get_value_for_many_names(self, doctype, names, field, order_by, debug=False, run=True, pluck=False, distinct=False, limit=None):
|
||||
names = list(filter(None, names))
|
||||
if names:
|
||||
return self.get_all(
|
||||
|
|
@ -669,6 +674,7 @@ class Database(object):
|
|||
as_list=1,
|
||||
run=run,
|
||||
distinct=distinct,
|
||||
limit_page_length=limit
|
||||
)
|
||||
else:
|
||||
return {}
|
||||
|
|
@ -884,27 +890,39 @@ class Database(object):
|
|||
return self.sql("select name from `tab{doctype}` limit 1".format(doctype=doctype))
|
||||
|
||||
def exists(self, dt, dn=None, cache=False):
|
||||
"""Returns true if document exists.
|
||||
"""Return the document name of a matching document, or None.
|
||||
|
||||
:param dt: DocType name.
|
||||
:param dn: Document name or filter dict."""
|
||||
if isinstance(dt, str):
|
||||
if dt!="DocType" and dt==dn:
|
||||
return True # single always exists (!)
|
||||
try:
|
||||
return self.get_value(dt, dn, "name", cache=cache)
|
||||
except Exception:
|
||||
return None
|
||||
Note: `cache` only works if `dt` and `dn` are of type `str`.
|
||||
|
||||
elif isinstance(dt, dict) and dt.get('doctype'):
|
||||
try:
|
||||
conditions = []
|
||||
for d in dt:
|
||||
if d == 'doctype': continue
|
||||
conditions.append([d, '=', dt[d]])
|
||||
return self.get_all(dt['doctype'], filters=conditions, as_list=1)
|
||||
except Exception:
|
||||
return None
|
||||
## Examples
|
||||
|
||||
Pass doctype and docname (only in this case we can cache the result)
|
||||
|
||||
```
|
||||
exists("User", "jane@example.org", cache=True)
|
||||
```
|
||||
|
||||
Pass a dict of filters including the `"doctype"` key:
|
||||
|
||||
```
|
||||
exists({"doctype": "User", "full_name": "Jane Doe"})
|
||||
```
|
||||
|
||||
Pass the doctype and a dict of filters:
|
||||
|
||||
```
|
||||
exists("User", {"full_name": "Jane Doe"})
|
||||
```
|
||||
"""
|
||||
if dt != "DocType" and dt == dn:
|
||||
# single always exists (!)
|
||||
return dn
|
||||
|
||||
if isinstance(dt, dict):
|
||||
dt = dt.copy() # don't modify the original dict
|
||||
dt, dn = dt.pop("doctype"), dt
|
||||
|
||||
return self.get_value(dt, dn, ignore=True, cache=cache)
|
||||
|
||||
def count(self, dt, filters=None, debug=False, cache=False):
|
||||
"""Returns `COUNT(*)` for given DocType and filters."""
|
||||
|
|
@ -1028,7 +1046,7 @@ class Database(object):
|
|||
return []
|
||||
|
||||
def is_missing_table_or_column(self, e):
|
||||
return self.is_missing_column(e) or self.is_missing_table(e)
|
||||
return self.is_missing_column(e) or self.is_table_missing(e)
|
||||
|
||||
def multisql(self, sql_dict, values=(), **kwargs):
|
||||
current_dialect = frappe.db.db_type or 'mariadb'
|
||||
|
|
|
|||
|
|
@ -154,6 +154,10 @@ class MariaDBDatabase(Database):
|
|||
def is_table_missing(e):
|
||||
return e.args[0] == ER.NO_SUCH_TABLE
|
||||
|
||||
@staticmethod
|
||||
def is_missing_table(e):
|
||||
return MariaDBDatabase.is_table_missing(e)
|
||||
|
||||
@staticmethod
|
||||
def is_missing_column(e):
|
||||
return e.args[0] == ER.BAD_FIELD_ERROR
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
import frappe
|
||||
from frappe import _
|
||||
from frappe.database.schema import DBTable
|
||||
from frappe.database.sequence import create_sequence
|
||||
from frappe.model import log_types
|
||||
|
||||
|
||||
class MariaDBTable(DBTable):
|
||||
def create(self):
|
||||
additional_definitions = ""
|
||||
engine = self.meta.get("engine") or "InnoDB"
|
||||
varchar_len = frappe.db.VARCHAR_LEN
|
||||
name_column = f"name varchar({varchar_len}) primary key"
|
||||
|
||||
# columns
|
||||
column_defs = self.get_column_definitions()
|
||||
|
|
@ -29,9 +33,27 @@ class MariaDBTable(DBTable):
|
|||
)
|
||||
) + ',\n'
|
||||
|
||||
# creating sequence(s)
|
||||
if (not self.meta.issingle and self.meta.autoname == "autoincrement")\
|
||||
or self.doctype in log_types:
|
||||
|
||||
# NOTE: using a very small cache - as during backup, if the sequence was used in anyform,
|
||||
# it drops the cache and uses the next non cached value in setval func and
|
||||
# puts that in the backup file, which will start the counter
|
||||
# from that value when inserting any new record in the doctype.
|
||||
# By default the cache is 1000 which will mess up the sequence when
|
||||
# using the system after a restore.
|
||||
# issue link: https://jira.mariadb.org/browse/MDEV-21786
|
||||
create_sequence(self.doctype, check_not_exists=True, cache=50)
|
||||
|
||||
# NOTE: not used nextval func as default as the ability to restore
|
||||
# database with sequences has bugs in mariadb and gives a scary error.
|
||||
# issue link: https://jira.mariadb.org/browse/MDEV-21786
|
||||
name_column = "name bigint primary key"
|
||||
|
||||
# create table
|
||||
query = f"""create table `{self.table_name}` (
|
||||
name varchar({varchar_len}) not null primary key,
|
||||
{name_column},
|
||||
creation datetime(6),
|
||||
modified datetime(6),
|
||||
modified_by varchar({varchar_len}),
|
||||
|
|
|
|||
|
|
@ -99,16 +99,13 @@ class PostgresDatabase(Database):
|
|||
return db_size[0].get('database_size')
|
||||
|
||||
# pylint: disable=W0221
|
||||
def sql(self, *args, **kwargs):
|
||||
if args:
|
||||
# since tuple is immutable
|
||||
args = list(args)
|
||||
args[0] = modify_query(args[0])
|
||||
args = tuple(args)
|
||||
elif kwargs.get('query'):
|
||||
kwargs['query'] = modify_query(kwargs.get('query'))
|
||||
|
||||
return super(PostgresDatabase, self).sql(*args, **kwargs)
|
||||
def sql(self, query, values=(), *args, **kwargs):
|
||||
return super(PostgresDatabase, self).sql(
|
||||
modify_query(query),
|
||||
modify_values(values),
|
||||
*args,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def get_tables(self, cached=True):
|
||||
return [d[0] for d in self.sql("""select table_name
|
||||
|
|
@ -153,6 +150,10 @@ class PostgresDatabase(Database):
|
|||
def is_table_missing(e):
|
||||
return getattr(e, 'pgcode', None) == '42P01'
|
||||
|
||||
@staticmethod
|
||||
def is_missing_table(e):
|
||||
return PostgresDatabase.is_table_missing(e)
|
||||
|
||||
@staticmethod
|
||||
def is_missing_column(e):
|
||||
return getattr(e, 'pgcode', None) == '42703'
|
||||
|
|
@ -335,12 +336,47 @@ def modify_query(query):
|
|||
query = replace_locate_with_strpos(query)
|
||||
# select from requires ""
|
||||
if re.search('from tab', query, flags=re.IGNORECASE):
|
||||
query = re.sub('from tab([a-zA-Z]*)', r'from "tab\1"', query, flags=re.IGNORECASE)
|
||||
query = re.sub(r'from tab([\w-]*)', r'from "tab\1"', query, flags=re.IGNORECASE)
|
||||
|
||||
# only find int (with/without signs), ignore decimals (with/without signs), ignore hashes (which start with numbers),
|
||||
# drop .0 from decimals and add quotes around them
|
||||
#
|
||||
# >>> query = "c='abcd' , a >= 45, b = -45.0, c = 40, d=4500.0, e=3500.53, f=40psdfsd, g=9092094312, h=12.00023"
|
||||
# >>> re.sub(r"([=><]+)\s*(?!\d+[a-zA-Z])(?![+-]?\d+\.\d\d+)([+-]?\d+)(\.0)?", r"\1 '\2'", query)
|
||||
# "c='abcd' , a >= '45', b = '-45', c = '40', d= '4500', e=3500.53, f=40psdfsd, g= '9092094312', h=12.00023
|
||||
|
||||
query = re.sub(r"([=><]+)\s*(?!\d+[a-zA-Z])(?![+-]?\d+\.\d\d+)([+-]?\d+)(\.0)?", r"\1 '\2'", query)
|
||||
return query
|
||||
|
||||
def modify_values(values):
|
||||
def stringify_value(value):
|
||||
if isinstance(value, int):
|
||||
value = str(value)
|
||||
elif isinstance(value, float):
|
||||
truncated_float = int(value)
|
||||
if value == truncated_float:
|
||||
value = str(truncated_float)
|
||||
|
||||
return value
|
||||
|
||||
if not values:
|
||||
return values
|
||||
|
||||
if isinstance(values, dict):
|
||||
for k, v in values.items():
|
||||
values[k] = stringify_value(v)
|
||||
elif isinstance(values, (tuple, list)):
|
||||
new_values = []
|
||||
for val in values:
|
||||
new_values.append(stringify_value(val))
|
||||
values = new_values
|
||||
else:
|
||||
values = stringify_value(values)
|
||||
|
||||
return values
|
||||
|
||||
def replace_locate_with_strpos(query):
|
||||
# strpos is the locate equivalent in postgres
|
||||
if re.search(r'locate\(', query, flags=re.IGNORECASE):
|
||||
query = re.sub(r'locate\(([^,]+),([^)]+)\)', r'strpos(\2, \1)', query, flags=re.IGNORECASE)
|
||||
query = re.sub(r'locate\(([^,]+),([^)]+)(\)?)\)', r'strpos(\2\3, \1)', query, flags=re.IGNORECASE)
|
||||
return query
|
||||
|
|
|
|||
|
|
@ -2,10 +2,14 @@ import frappe
|
|||
from frappe import _
|
||||
from frappe.utils import cint, flt
|
||||
from frappe.database.schema import DBTable, get_definition
|
||||
from frappe.database.sequence import create_sequence
|
||||
from frappe.model import log_types
|
||||
|
||||
|
||||
class PostgresTable(DBTable):
|
||||
def create(self):
|
||||
varchar_len = frappe.db.VARCHAR_LEN
|
||||
name_column = f"name varchar({varchar_len}) primary key"
|
||||
|
||||
additional_definitions = ""
|
||||
# columns
|
||||
|
|
@ -26,9 +30,21 @@ class PostgresTable(DBTable):
|
|||
)
|
||||
)
|
||||
|
||||
# creating sequence(s)
|
||||
if (not self.meta.issingle and self.meta.autoname == "autoincrement")\
|
||||
or self.doctype in log_types:
|
||||
|
||||
# The sequence cache is per connection.
|
||||
# Since we're opening and closing connections for every transaction this results in skipping the cache
|
||||
# to the next non-cached value hence not using cache in postgres.
|
||||
# ref: https://stackoverflow.com/questions/21356375/postgres-9-0-4-sequence-skipping-numbers
|
||||
create_sequence(self.doctype, check_not_exists=True)
|
||||
name_column = "name bigint primary key"
|
||||
|
||||
# TODO: set docstatus length
|
||||
# create table
|
||||
frappe.db.sql(f"""create table `{self.table_name}` (
|
||||
name varchar({varchar_len}) not null primary key,
|
||||
{name_column},
|
||||
creation timestamp(6),
|
||||
modified timestamp(6),
|
||||
modified_by varchar({varchar_len}),
|
||||
|
|
|
|||
|
|
@ -95,3 +95,11 @@ def get_root_connection(root_login=None, root_password=None):
|
|||
frappe.local.flags.root_connection = frappe.database.get_db(user=root_login, password=root_password)
|
||||
|
||||
return frappe.local.flags.root_connection
|
||||
|
||||
|
||||
def drop_user_and_database(db_name, root_login, root_password):
|
||||
root_conn = get_root_connection(frappe.flags.root_login or root_login, frappe.flags.root_password or root_password)
|
||||
root_conn.commit()
|
||||
root_conn.sql(f"SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = %s", (db_name, ))
|
||||
root_conn.sql(f"DROP DATABASE IF EXISTS {db_name}")
|
||||
root_conn.sql(f"DROP USER IF EXISTS {db_name}")
|
||||
|
|
|
|||
80
frappe/database/sequence.py
Normal file
80
frappe/database/sequence.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
from frappe import db, scrub
|
||||
|
||||
|
||||
def create_sequence(
|
||||
doctype_name: str,
|
||||
*,
|
||||
slug: str = "_id_seq",
|
||||
check_not_exists: bool = False,
|
||||
cycle: bool = False,
|
||||
cache: int = 0,
|
||||
start_value: int = 0,
|
||||
increment_by: int = 0,
|
||||
min_value: int = 0,
|
||||
max_value: int = 0
|
||||
) -> str:
|
||||
|
||||
query = "create sequence"
|
||||
sequence_name = scrub(doctype_name + slug)
|
||||
|
||||
if check_not_exists:
|
||||
query += " if not exists"
|
||||
|
||||
query += f" {sequence_name}"
|
||||
|
||||
if cache:
|
||||
query += f" cache {cache}"
|
||||
else:
|
||||
# in postgres, the default is cache 1
|
||||
if db.db_type == "mariadb":
|
||||
query += " nocache"
|
||||
|
||||
if start_value:
|
||||
# default is 1
|
||||
query += f" start with {start_value}"
|
||||
|
||||
if increment_by:
|
||||
# default is 1
|
||||
query += f" increment by {increment_by}"
|
||||
|
||||
if min_value:
|
||||
# default is 1
|
||||
query += f" min value {min_value}"
|
||||
|
||||
if max_value:
|
||||
query += f" max value {max_value}"
|
||||
|
||||
if not cycle:
|
||||
if db.db_type == "mariadb":
|
||||
query += " nocycle"
|
||||
else:
|
||||
query += " cycle"
|
||||
|
||||
db.sql(query)
|
||||
|
||||
return sequence_name
|
||||
|
||||
|
||||
def get_next_val(doctype_name: str, slug: str = "_id_seq") -> int:
|
||||
if db.db_type == "postgres":
|
||||
return db.sql(f"select nextval(\'\"{scrub(doctype_name + slug)}\"\')")[0][0]
|
||||
return db.sql(f"select nextval(`{scrub(doctype_name + slug)}`)")[0][0]
|
||||
|
||||
|
||||
def set_next_val(
|
||||
doctype_name: str,
|
||||
next_val: int,
|
||||
*,
|
||||
slug: str = "_id_seq",
|
||||
is_val_used :bool = False
|
||||
) -> None:
|
||||
|
||||
if not is_val_used:
|
||||
is_val_used = 0 if db.db_type == "mariadb" else "f"
|
||||
else:
|
||||
is_val_used = 1 if db.db_type == "mariadb" else "t"
|
||||
|
||||
if db.db_type == "postgres":
|
||||
db.sql(f"SELECT SETVAL('\"{scrub(doctype_name + slug)}\"', {next_val}, '{is_val_used}')")
|
||||
else:
|
||||
db.sql(f"SELECT SETVAL(`{scrub(doctype_name + slug)}`, {next_val}, {is_val_used})")
|
||||
|
|
@ -28,6 +28,7 @@ frappe.ui.form.on('Number Card', {
|
|||
frm.trigger('render_filters_table');
|
||||
}
|
||||
frm.trigger('create_add_to_dashboard_button');
|
||||
frm.trigger('set_parent_document_type');
|
||||
},
|
||||
|
||||
create_add_to_dashboard_button: function(frm) {
|
||||
|
|
@ -141,7 +142,9 @@ frappe.ui.form.on('Number Card', {
|
|||
frm.set_value('filters_json', '[]');
|
||||
frm.set_value('dynamic_filters_json', '[]');
|
||||
frm.set_value('aggregate_function_based_on', '');
|
||||
frm.set_value('parent_document_type', '');
|
||||
frm.trigger('set_options');
|
||||
frm.trigger('set_parent_document_type');
|
||||
},
|
||||
|
||||
set_options: function(frm) {
|
||||
|
|
@ -317,6 +320,7 @@ frappe.ui.form.on('Number Card', {
|
|||
frm.filter_group = new frappe.ui.FilterGroup({
|
||||
parent: dialog.get_field('filter_area').$wrapper,
|
||||
doctype: frm.doc.document_type,
|
||||
parent_doctype: frm.doc.parent_document_type,
|
||||
on_change: () => {},
|
||||
});
|
||||
filters && frm.filter_group.add_filters_to_filter_group(filters);
|
||||
|
|
@ -436,6 +440,36 @@ frappe.ui.form.on('Number Card', {
|
|||
|
||||
frm.dynamic_filter_table.find('tbody').html(filter_rows);
|
||||
}
|
||||
},
|
||||
|
||||
set_parent_document_type: async function(frm) {
|
||||
let document_type = frm.doc.document_type;
|
||||
let doc_is_table = document_type &&
|
||||
(await frappe.db.get_value('DocType', document_type, 'istable')).message.istable;
|
||||
|
||||
frm.set_df_property('parent_document_type', 'hidden', !doc_is_table);
|
||||
|
||||
if (document_type && doc_is_table) {
|
||||
let parent = await frappe.db.get_list('DocField', {
|
||||
filters: {
|
||||
'fieldtype': 'Table',
|
||||
'options': document_type
|
||||
},
|
||||
fields: ['parent']
|
||||
});
|
||||
|
||||
parent && frm.set_query('parent_document_type', function() {
|
||||
return {
|
||||
filters: {
|
||||
"name": ['in', parent.map(({ parent }) => parent)]
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
if (parent.length === 1) {
|
||||
frm.set_value('parent_document_type', parent[0].parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
"aggregate_function_based_on",
|
||||
"column_break_2",
|
||||
"document_type",
|
||||
"parent_document_type",
|
||||
"report_field",
|
||||
"report_function",
|
||||
"is_public",
|
||||
|
|
@ -188,10 +189,17 @@
|
|||
"label": "Function",
|
||||
"mandatory_depends_on": "eval: doc.type == 'Report'",
|
||||
"options": "Sum\nAverage\nMinimum\nMaximum"
|
||||
},
|
||||
{
|
||||
"description": "The document type selected is a child table, so the parent document type is required.",
|
||||
"fieldname": "parent_document_type",
|
||||
"fieldtype": "Link",
|
||||
"label": "Parent Document Type",
|
||||
"options": "DocType"
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2020-07-23 11:11:03.391719",
|
||||
"modified": "2022-03-10 15:34:38.210910",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Desk",
|
||||
"name": "Number Card",
|
||||
|
|
@ -234,6 +242,7 @@
|
|||
"search_fields": "label, document_type",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"title_field": "label",
|
||||
"track_changes": 1
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
# License: MIT. See LICENSE
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import cint
|
||||
from frappe.model.naming import append_number_if_name_exists
|
||||
|
|
@ -17,6 +18,13 @@ class NumberCard(Document):
|
|||
if frappe.db.exists("Number Card", self.name):
|
||||
self.name = append_number_if_name_exists('Number Card', self.name)
|
||||
|
||||
def validate(self):
|
||||
if not self.document_type:
|
||||
frappe.throw(_("Document type is required to create a number card"))
|
||||
|
||||
if self.document_type and frappe.get_meta(self.document_type).istable and not self.parent_document_type:
|
||||
frappe.throw(_("Parent document type is required to create a number card"))
|
||||
|
||||
def on_update(self):
|
||||
if frappe.conf.developer_mode and self.is_standard:
|
||||
export_to_files(record_list=[['Number Card', self.name]], record_module=self.module)
|
||||
|
|
|
|||
|
|
@ -88,15 +88,16 @@ frappe.ui.form.on('System Console', {
|
|||
<td>${row.Progress}</td>
|
||||
</tr>`
|
||||
}
|
||||
|
||||
frm.get_field('processlist').html(`
|
||||
<p class='text-muted'>Requested on: ${timestamp}</p>
|
||||
<table class='table-bordered' style='width: 100%'>
|
||||
<thead><tr>
|
||||
<th width='10%'>Id</ht>
|
||||
<th width='5%'>Id</ht>
|
||||
<th width='10%'>Time</ht>
|
||||
<th width='10%'>State</ht>
|
||||
<th width='60%'>Info</ht>
|
||||
<th width='10%'>Progress</ht>
|
||||
<th width='15%'>Progress / Wait Event</ht>
|
||||
</tr></thead>
|
||||
<tbody>${rows}</thead>`);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -41,4 +41,14 @@ def execute_code(doc):
|
|||
@frappe.whitelist()
|
||||
def show_processlist():
|
||||
frappe.only_for('System Manager')
|
||||
return frappe.db.sql('show full processlist', as_dict=1)
|
||||
|
||||
return frappe.db.multisql({
|
||||
"postgres": """
|
||||
SELECT pid AS "Id",
|
||||
query_start AS "Time",
|
||||
state AS "State",
|
||||
query AS "Info",
|
||||
wait_event AS "Progress"
|
||||
FROM pg_stat_activity""",
|
||||
"mariadb": "show full processlist"
|
||||
}, as_dict=True)
|
||||
|
|
|
|||
|
|
@ -277,6 +277,7 @@ def sort_page(workspace_pages, pages):
|
|||
doc = frappe.get_doc('Workspace', page.name)
|
||||
doc.sequence_id = seq + 1
|
||||
doc.parent_page = d.get('parent_page') or ""
|
||||
doc.flags.ignore_links = True
|
||||
doc.save(ignore_permissions=True)
|
||||
break
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: MIT. See LICENSE
|
||||
|
||||
import json
|
||||
from collections import defaultdict
|
||||
import itertools
|
||||
from typing import List
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
import frappe
|
||||
import frappe.desk.form.load
|
||||
|
|
@ -367,7 +368,7 @@ def get_exempted_doctypes():
|
|||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_linked_docs(doctype, name, linkinfo=None, for_doctype=None):
|
||||
def get_linked_docs(doctype: str, name: str, linkinfo: Optional[Dict] = None) -> Dict[str, List]:
|
||||
if isinstance(linkinfo, str):
|
||||
# additional fields are added in linkinfo
|
||||
linkinfo = json.loads(linkinfo)
|
||||
|
|
@ -377,23 +378,21 @@ def get_linked_docs(doctype, name, linkinfo=None, for_doctype=None):
|
|||
if not linkinfo:
|
||||
return results
|
||||
|
||||
if for_doctype:
|
||||
links = frappe.get_doc(doctype, name).get_link_filters(for_doctype)
|
||||
|
||||
if links:
|
||||
linkinfo = links
|
||||
|
||||
if for_doctype in linkinfo:
|
||||
# only get linked with for this particular doctype
|
||||
linkinfo = { for_doctype: linkinfo.get(for_doctype) }
|
||||
else:
|
||||
return results
|
||||
|
||||
for dt, link in linkinfo.items():
|
||||
filters = []
|
||||
link["doctype"] = dt
|
||||
link_meta_bundle = frappe.desk.form.load.get_meta_bundle(dt)
|
||||
try:
|
||||
link_meta_bundle = frappe.desk.form.load.get_meta_bundle(dt)
|
||||
except Exception as e:
|
||||
if isinstance(e, frappe.DoesNotExistError):
|
||||
if frappe.local.message_log:
|
||||
frappe.local.message_log.pop()
|
||||
continue
|
||||
linkmeta = link_meta_bundle[0]
|
||||
|
||||
if not linkmeta.has_permission():
|
||||
continue
|
||||
|
||||
if not linkmeta.get("issingle"):
|
||||
fields = [d.fieldname for d in linkmeta.get("fields", {
|
||||
"in_list_view": 1,
|
||||
|
|
@ -456,6 +455,13 @@ def get_linked_docs(doctype, name, linkinfo=None, for_doctype=None):
|
|||
|
||||
return results
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get(doctype, docname):
|
||||
linked_doctypes = get_linked_doctypes(doctype=doctype)
|
||||
return get_linked_docs(doctype=doctype, name=docname, linkinfo=linked_doctypes)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_linked_doctypes(doctype, without_ignore_user_permissions_enabled=False):
|
||||
"""add list of doctypes this doctype is 'linked' with.
|
||||
|
|
@ -470,6 +476,7 @@ def get_linked_doctypes(doctype, without_ignore_user_permissions_enabled=False):
|
|||
else:
|
||||
return frappe.cache().hget("linked_doctypes", doctype, lambda: _get_linked_doctypes(doctype))
|
||||
|
||||
|
||||
def _get_linked_doctypes(doctype, without_ignore_user_permissions_enabled=False):
|
||||
ret = {}
|
||||
# find fields where this doctype is linked
|
||||
|
|
@ -499,6 +506,7 @@ def _get_linked_doctypes(doctype, without_ignore_user_permissions_enabled=False)
|
|||
|
||||
return ret
|
||||
|
||||
|
||||
def get_linked_fields(doctype, without_ignore_user_permissions_enabled=False):
|
||||
|
||||
filters = [['fieldtype','=', 'Link'], ['options', '=', doctype]]
|
||||
|
|
@ -529,6 +537,7 @@ def get_linked_fields(doctype, without_ignore_user_permissions_enabled=False):
|
|||
|
||||
return ret
|
||||
|
||||
|
||||
def get_dynamic_linked_fields(doctype, without_ignore_user_permissions_enabled=False):
|
||||
ret = {}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import frappe.desk.form.meta
|
|||
from frappe.model.utils.user_settings import get_user_settings
|
||||
from frappe.permissions import get_doc_permissions
|
||||
from frappe.desk.form.document_follow import is_document_followed
|
||||
from frappe.utils.data import cstr
|
||||
from frappe import _
|
||||
from frappe import _dict
|
||||
from urllib.parse import quote
|
||||
|
|
@ -124,7 +125,6 @@ def get_docinfo(doc=None, doctype=None, name=None):
|
|||
update_user_info(docinfo)
|
||||
|
||||
frappe.response["docinfo"] = docinfo
|
||||
return docinfo
|
||||
|
||||
def add_comments(doc, docinfo):
|
||||
# divide comments into separate lists
|
||||
|
|
@ -356,7 +356,7 @@ def get_document_email(doctype, name):
|
|||
return None
|
||||
|
||||
email = email.split("@")
|
||||
return "{0}+{1}+{2}@{3}".format(email[0], quote(doctype), quote(name), email[1])
|
||||
return "{0}+{1}+{2}@{3}".format(email[0], quote(doctype), quote(cstr(name)), email[1])
|
||||
|
||||
def get_automatic_email_link():
|
||||
return frappe.db.get_value("Email Account", {"enable_incoming": 1, "enable_automatic_linking": 1}, "email_id")
|
||||
|
|
|
|||
|
|
@ -352,14 +352,10 @@ def export_query():
|
|||
)
|
||||
return
|
||||
|
||||
columns = get_columns_dict(data.columns)
|
||||
|
||||
from frappe.utils.xlsxutils import make_xlsx
|
||||
|
||||
data["result"] = handle_duration_fieldtype_values(
|
||||
data.get("result"), data.get("columns")
|
||||
)
|
||||
xlsx_data, column_widths = build_xlsx_data(columns, data, visible_idx, include_indentation)
|
||||
format_duration_fields(data)
|
||||
xlsx_data, column_widths = build_xlsx_data(data, visible_idx, include_indentation)
|
||||
xlsx_file = make_xlsx(xlsx_data, "Query Report", column_widths=column_widths)
|
||||
|
||||
frappe.response["filename"] = report_name + ".xlsx"
|
||||
|
|
@ -367,39 +363,18 @@ def export_query():
|
|||
frappe.response["type"] = "binary"
|
||||
|
||||
|
||||
def handle_duration_fieldtype_values(result, columns):
|
||||
for i, col in enumerate(columns):
|
||||
fieldtype = None
|
||||
if isinstance(col, str):
|
||||
col = col.split(":")
|
||||
if len(col) > 1:
|
||||
if col[1]:
|
||||
fieldtype = col[1]
|
||||
if "/" in fieldtype:
|
||||
fieldtype, options = fieldtype.split("/")
|
||||
else:
|
||||
fieldtype = "Data"
|
||||
else:
|
||||
fieldtype = col.get("fieldtype")
|
||||
def format_duration_fields(data: frappe._dict) -> None:
|
||||
for i, col in enumerate(data.columns):
|
||||
if col.get("fieldtype") != "Duration":
|
||||
continue
|
||||
|
||||
if fieldtype == "Duration":
|
||||
for entry in range(0, len(result)):
|
||||
row = result[entry]
|
||||
if isinstance(row, dict):
|
||||
val_in_seconds = row[col.fieldname]
|
||||
if val_in_seconds:
|
||||
duration_val = format_duration(val_in_seconds)
|
||||
row[col.fieldname] = duration_val
|
||||
else:
|
||||
val_in_seconds = row[i]
|
||||
if val_in_seconds:
|
||||
duration_val = format_duration(val_in_seconds)
|
||||
row[i] = duration_val
|
||||
|
||||
return result
|
||||
for row in data.result:
|
||||
index = col.fieldname if isinstance(row, dict) else i
|
||||
if row[index]:
|
||||
row[index] = format_duration(row[index])
|
||||
|
||||
|
||||
def build_xlsx_data(columns, data, visible_idx, include_indentation, ignore_visible_idx=False):
|
||||
def build_xlsx_data(data, visible_idx, include_indentation, ignore_visible_idx=False):
|
||||
result = [[]]
|
||||
column_widths = []
|
||||
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ def scrub_custom_query(query, key, txt):
|
|||
def relevance_sorter(key, query, as_dict):
|
||||
value = _(key.name if as_dict else key[0])
|
||||
return (
|
||||
value.lower().startswith(query.lower()) is not True,
|
||||
cstr(value).lower().startswith(query.lower()) is not True,
|
||||
value
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ from frappe.utils.csvutils import to_csv
|
|||
from frappe.utils.xlsxutils import make_xlsx
|
||||
from frappe.desk.query_report import build_xlsx_data
|
||||
|
||||
max_reports_per_user = frappe.local.conf.max_reports_per_user or 3
|
||||
|
||||
|
||||
class AutoEmailReport(Document):
|
||||
def autoname(self):
|
||||
|
|
@ -46,6 +44,8 @@ class AutoEmailReport(Document):
|
|||
def validate_report_count(self):
|
||||
'''check that there are only 3 enabled reports per user'''
|
||||
count = frappe.db.sql('select count(*) from `tabAuto Email Report` where user=%s and enabled=1', self.user)[0][0]
|
||||
max_reports_per_user = frappe.local.conf.max_reports_per_user or 3
|
||||
|
||||
if count > max_reports_per_user + (-1 if self.flags.in_insert else 0):
|
||||
frappe.throw(_('Only {0} emailed reports are allowed per user').format(max_reports_per_user))
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ class AutoEmailReport(Document):
|
|||
report_data['columns'] = columns
|
||||
report_data['result'] = data
|
||||
|
||||
xlsx_data, column_widths = build_xlsx_data(columns, report_data, [], 1, ignore_visible_idx=True)
|
||||
xlsx_data, column_widths = build_xlsx_data(report_data, [], 1, ignore_visible_idx=True)
|
||||
xlsx_file = make_xlsx(xlsx_data, "Auto Email Report", column_widths=column_widths)
|
||||
return xlsx_file.getvalue()
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ class AutoEmailReport(Document):
|
|||
report_data['columns'] = columns
|
||||
report_data['result'] = data
|
||||
|
||||
xlsx_data, column_widths = build_xlsx_data(columns, report_data, [], 1, ignore_visible_idx=True)
|
||||
xlsx_data, column_widths = build_xlsx_data(report_data, [], 1, ignore_visible_idx=True)
|
||||
return to_csv(xlsx_data)
|
||||
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -236,8 +236,7 @@
|
|||
"index_web_pages_for_search": 1,
|
||||
"is_published_field": "published",
|
||||
"links": [],
|
||||
"max_attachments": 3,
|
||||
"modified": "2021-12-06 20:09:37.963141",
|
||||
"modified": "2022-03-09 01:48:16.741603",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Email",
|
||||
"name": "Newsletter",
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class TestNewsletterMixin:
|
|||
"reference_name": newsletter,
|
||||
})
|
||||
frappe.delete_doc("Newsletter", newsletter)
|
||||
frappe.db.delete("Newsletter Email Group", newsletter)
|
||||
frappe.db.delete("Newsletter Email Group", {"parent": newsletter})
|
||||
newsletters.remove(newsletter)
|
||||
|
||||
def setup_email_group(self):
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ def get_context(context):
|
|||
|
||||
def send_an_email(self, doc, context):
|
||||
from email.utils import formataddr
|
||||
from frappe.core.doctype.communication.email import make as make_communication
|
||||
from frappe.core.doctype.communication.email import _make as make_communication
|
||||
subject = self.subject
|
||||
if "{" in subject:
|
||||
subject = frappe.render_template(self.subject, context)
|
||||
|
|
@ -216,7 +216,8 @@ def get_context(context):
|
|||
# Add mail notification to communication list
|
||||
# No need to add if it is already a communication.
|
||||
if doc.doctype != 'Communication':
|
||||
make_communication(doctype=doc.doctype,
|
||||
make_communication(
|
||||
doctype=doc.doctype,
|
||||
name=doc.name,
|
||||
content=message,
|
||||
subject=subject,
|
||||
|
|
@ -228,7 +229,7 @@ def get_context(context):
|
|||
cc=cc,
|
||||
bcc=bcc,
|
||||
communication_type='Automated Message',
|
||||
ignore_permissions=True)
|
||||
)
|
||||
|
||||
def send_a_slack_msg(self, doc, context):
|
||||
send_slack_message(
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ class TestNotification(unittest.TestCase):
|
|||
self.assertTrue(email_queue)
|
||||
|
||||
# check if description is changed after alert since set_property_after_alert is set
|
||||
self.assertEquals(todo.description, 'Changed by Notification')
|
||||
self.assertEqual(todo.description, 'Changed by Notification')
|
||||
|
||||
recipients = [d.recipient for d in email_queue.recipients]
|
||||
self.assertTrue('test2@example.com' in recipients)
|
||||
|
|
|
|||
|
|
@ -259,17 +259,12 @@ def get_formatted_html(subject, message, footer=None, print_html=None,
|
|||
|
||||
email_account = email_account or EmailAccount.find_outgoing(match_by_email=sender)
|
||||
|
||||
signature = None
|
||||
if "<!-- signature-included -->" not in message:
|
||||
signature = get_signature(email_account)
|
||||
|
||||
rendered_email = frappe.get_template("templates/emails/standard.html").render({
|
||||
"brand_logo": get_brand_logo(email_account) if with_container or header else None,
|
||||
"with_container": with_container,
|
||||
"site_url": get_url(),
|
||||
"header": get_header(header),
|
||||
"content": message,
|
||||
"signature": signature,
|
||||
"footer": get_footer(email_account, footer),
|
||||
"title": subject,
|
||||
"print_html": print_html,
|
||||
|
|
@ -281,8 +276,7 @@ def get_formatted_html(subject, message, footer=None, print_html=None,
|
|||
if unsubscribe_link:
|
||||
html = html.replace("<!--unsubscribe link here-->", unsubscribe_link.html)
|
||||
|
||||
html = inline_style_in_html(html)
|
||||
return html
|
||||
return inline_style_in_html(html)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_email_html(template, args, subject, header=None, with_container=False):
|
||||
|
|
|
|||
|
|
@ -203,12 +203,17 @@ def get_unread_update_logs(consumer_name, dt, dn):
|
|||
SELECT
|
||||
update_log.name
|
||||
FROM `tabEvent Update Log` update_log
|
||||
JOIN `tabEvent Update Log Consumer` consumer ON consumer.parent = update_log.name
|
||||
JOIN `tabEvent Update Log Consumer` consumer ON consumer.parent = %(log_name)s
|
||||
WHERE
|
||||
consumer.consumer = %(consumer)s
|
||||
AND update_log.ref_doctype = %(dt)s
|
||||
AND update_log.docname = %(dn)s
|
||||
""", {'consumer': consumer_name, "dt": dt, "dn": dn}, as_dict=0)]
|
||||
""", {
|
||||
"consumer": consumer_name,
|
||||
"dt": dt,
|
||||
"dn": dn,
|
||||
"log_name": "update_log.name" if frappe.conf.db_type == "mariadb" else "CAST(update_log.name AS VARCHAR)"
|
||||
}, as_dict=0)]
|
||||
|
||||
logs = frappe.get_all(
|
||||
'Event Update Log',
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import json
|
|||
import requests
|
||||
|
||||
import frappe
|
||||
from frappe.utils.data import cstr
|
||||
|
||||
|
||||
class AuthError(Exception):
|
||||
|
|
@ -122,7 +123,7 @@ class FrappeClient(object):
|
|||
'''Update a remote document
|
||||
|
||||
:param doc: dict or Document object to be updated remotely. `name` is mandatory for this'''
|
||||
url = self.url + "/api/resource/" + doc.get("doctype") + "/" + doc.get("name")
|
||||
url = self.url + "/api/resource/" + doc.get("doctype") + "/" + cstr(doc.get("name"))
|
||||
res = self.session.put(url, data={"data":frappe.as_json(doc)}, verify=self.verify, headers=self.headers)
|
||||
return frappe._dict(self.post_process(res))
|
||||
|
||||
|
|
@ -207,7 +208,7 @@ class FrappeClient(object):
|
|||
if fields:
|
||||
params["fields"] = json.dumps(fields)
|
||||
|
||||
res = self.session.get(self.url + "/api/resource/" + doctype + "/" + name,
|
||||
res = self.session.get(self.url + "/api/resource/" + doctype + "/" + cstr(name),
|
||||
params=params, verify=self.verify, headers=self.headers)
|
||||
|
||||
return self.post_process(res)
|
||||
|
|
|
|||
17
frappe/handler.py
Executable file → Normal file
17
frappe/handler.py
Executable file → Normal file
|
|
@ -225,11 +225,10 @@ def ping():
|
|||
|
||||
def run_doc_method(method, docs=None, dt=None, dn=None, arg=None, args=None):
|
||||
"""run a whitelisted controller method"""
|
||||
import json
|
||||
import inspect
|
||||
from inspect import getfullargspec
|
||||
|
||||
if not args:
|
||||
args = arg or ""
|
||||
if not args and arg:
|
||||
args = arg
|
||||
|
||||
if dt: # not called from a doctype (from a page)
|
||||
if not dn:
|
||||
|
|
@ -237,9 +236,7 @@ def run_doc_method(method, docs=None, dt=None, dn=None, arg=None, args=None):
|
|||
doc = frappe.get_doc(dt, dn)
|
||||
|
||||
else:
|
||||
if isinstance(docs, str):
|
||||
docs = json.loads(docs)
|
||||
|
||||
docs = frappe.parse_json(docs)
|
||||
doc = frappe.get_doc(docs)
|
||||
doc._original_modified = doc.modified
|
||||
doc.check_if_latest()
|
||||
|
|
@ -248,16 +245,16 @@ def run_doc_method(method, docs=None, dt=None, dn=None, arg=None, args=None):
|
|||
throw_permission_error()
|
||||
|
||||
try:
|
||||
args = json.loads(args)
|
||||
args = frappe.parse_json(args)
|
||||
except ValueError:
|
||||
args = args
|
||||
pass
|
||||
|
||||
method_obj = getattr(doc, method)
|
||||
fn = getattr(method_obj, '__func__', method_obj)
|
||||
is_whitelisted(fn)
|
||||
is_valid_http_method(fn)
|
||||
|
||||
fnargs = inspect.getfullargspec(method_obj).args
|
||||
fnargs = getfullargspec(method_obj).args
|
||||
|
||||
if not fnargs or (len(fnargs)==1 and fnargs[0]=="self"):
|
||||
response = doc.run_method(method)
|
||||
|
|
|
|||
|
|
@ -611,7 +611,7 @@ def is_downgrade(sql_file_path, verbose=False):
|
|||
downgrade = backup_version > current_version
|
||||
|
||||
if verbose and downgrade:
|
||||
print("Your site will be downgraded from Frappe {0} to {1}".format(current_version, backup_version))
|
||||
print(f"Your site will be downgraded from Frappe {backup_version} to {current_version}")
|
||||
|
||||
return downgrade
|
||||
|
||||
|
|
|
|||
|
|
@ -475,7 +475,7 @@ class BaseDocument(object):
|
|||
d = self.get_valid_dict(convert_dates_to_str=True, ignore_nulls = self.doctype in DOCTYPES_FOR_DOCTYPE)
|
||||
|
||||
# don't update name, as case might've been changed
|
||||
name = d['name']
|
||||
name = cstr(d['name'])
|
||||
del d['name']
|
||||
|
||||
columns = list(d)
|
||||
|
|
@ -963,7 +963,7 @@ class BaseDocument(object):
|
|||
from frappe.model.meta import get_default_df
|
||||
df = get_default_df(fieldname)
|
||||
|
||||
if not currency and df:
|
||||
if df.fieldtype == "Currency" and not currency:
|
||||
currency = self.get(df.get("options"))
|
||||
if not frappe.db.exists('Currency', currency, cache=True):
|
||||
currency = None
|
||||
|
|
|
|||
|
|
@ -164,7 +164,8 @@ class DatabaseQuery(object):
|
|||
|
||||
# left join parent, child tables
|
||||
for child in self.tables[1:]:
|
||||
args.tables += f" {self.join} {child} on ({child}.parent = {self.tables[0]}.name)"
|
||||
parent_name = self.cast_name(f"{self.tables[0]}.name")
|
||||
args.tables += f" {self.join} {child} on ({child}.parent = {parent_name})"
|
||||
|
||||
if self.grouped_or_conditions:
|
||||
self.conditions.append(f"({' or '.join(self.grouped_or_conditions)})")
|
||||
|
|
@ -318,21 +319,60 @@ class DatabaseQuery(object):
|
|||
]
|
||||
# add tables from fields
|
||||
if self.fields:
|
||||
for field in self.fields:
|
||||
if not ("tab" in field and "." in field) or any(x for x in sql_functions if x in field):
|
||||
for i, field in enumerate(self.fields):
|
||||
# add cast in locate/strpos
|
||||
func_found = False
|
||||
for func in sql_functions:
|
||||
if func in field.lower():
|
||||
self.fields[i] = self.cast_name(field, func)
|
||||
func_found = True
|
||||
break
|
||||
|
||||
if func_found or not ("tab" in field and "." in field):
|
||||
continue
|
||||
|
||||
table_name = field.split('.')[0]
|
||||
|
||||
if table_name.lower().startswith('group_concat('):
|
||||
table_name = table_name[13:]
|
||||
if table_name.lower().startswith('ifnull('):
|
||||
table_name = table_name[7:]
|
||||
if not table_name[0]=='`':
|
||||
table_name = f"`{table_name}`"
|
||||
if table_name not in self.tables:
|
||||
self.append_table(table_name)
|
||||
|
||||
def cast_name(self, column: str, sql_function: str = "",) -> str:
|
||||
if frappe.db.db_type == "postgres":
|
||||
if "name" in column.lower():
|
||||
if "cast(" not in column.lower() or "::" not in column:
|
||||
if not sql_function:
|
||||
return f"cast({column} as varchar)"
|
||||
|
||||
elif sql_function == "locate(":
|
||||
return re.sub(
|
||||
r'locate\(([^,]+),([^)]+)\)',
|
||||
r'locate(\1, cast(\2 as varchar))',
|
||||
column,
|
||||
flags=re.IGNORECASE
|
||||
)
|
||||
|
||||
elif sql_function == "strpos(":
|
||||
return re.sub(
|
||||
r'strpos\(([^,]+),([^)]+)\)',
|
||||
r'strpos(cast(\1 as varchar), \2)',
|
||||
column,
|
||||
flags=re.IGNORECASE
|
||||
)
|
||||
|
||||
elif sql_function == "ifnull(":
|
||||
return re.sub(
|
||||
r"ifnull\(([^,]+)",
|
||||
r"ifnull(cast(\1 as varchar)",
|
||||
column,
|
||||
flags=re.IGNORECASE
|
||||
)
|
||||
|
||||
return column
|
||||
|
||||
def append_table(self, table_name):
|
||||
self.tables.append(table_name)
|
||||
doctype = table_name[4:-1]
|
||||
|
|
@ -423,6 +463,8 @@ class DatabaseQuery(object):
|
|||
ifnull(`tabDocType`.`fieldname`, fallback) operator "value"
|
||||
"""
|
||||
|
||||
# TODO: refactor
|
||||
|
||||
from frappe.boot import get_additional_filters_from_hooks
|
||||
additional_filters_config = get_additional_filters_from_hooks()
|
||||
f = get_filter(self.doctype, f, additional_filters_config)
|
||||
|
|
@ -432,15 +474,16 @@ class DatabaseQuery(object):
|
|||
self.append_table(tname)
|
||||
|
||||
if 'ifnull(' in f.fieldname:
|
||||
column_name = f.fieldname
|
||||
column_name = self.cast_name(f.fieldname, "ifnull(")
|
||||
else:
|
||||
column_name = f"{tname}.{f.fieldname}"
|
||||
|
||||
can_be_null = True
|
||||
column_name = self.cast_name(f"{tname}.{f.fieldname}")
|
||||
|
||||
if f.operator.lower() in additional_filters_config:
|
||||
f.update(get_additional_filter_field(additional_filters_config, f, f.value))
|
||||
|
||||
meta = frappe.get_meta(f.doctype)
|
||||
can_be_null = True
|
||||
|
||||
# prepare in condition
|
||||
if f.operator.lower() in ('ancestors of', 'descendants of', 'not ancestors of', 'not descendants of'):
|
||||
values = f.value or ''
|
||||
|
|
@ -449,12 +492,8 @@ class DatabaseQuery(object):
|
|||
# if not isinstance(values, (list, tuple)):
|
||||
# values = values.split(",")
|
||||
|
||||
ref_doctype = f.doctype
|
||||
|
||||
if frappe.get_meta(f.doctype).get_field(f.fieldname) is not None :
|
||||
ref_doctype = frappe.get_meta(f.doctype).get_field(f.fieldname).options
|
||||
|
||||
result=[]
|
||||
field = meta.get_field(f.fieldname)
|
||||
ref_doctype = field.options if field else f.doctype
|
||||
|
||||
lft, rgt = '', ''
|
||||
if f.value:
|
||||
|
|
@ -474,29 +513,30 @@ class DatabaseQuery(object):
|
|||
}, order_by='`lft` DESC')
|
||||
|
||||
fallback = "''"
|
||||
value = [frappe.db.escape((v.name or '').strip(), percent=False) for v in result]
|
||||
value = [frappe.db.escape((cstr(v.name) or '').strip(), percent=False) for v in result]
|
||||
if len(value):
|
||||
value = f"({', '.join(value)})"
|
||||
else:
|
||||
value = "('')"
|
||||
|
||||
# changing operator to IN as the above code fetches all the parent / child values and convert into tuple
|
||||
# which can be directly used with IN operator to query.
|
||||
f.operator = 'not in' if f.operator.lower() in ('not ancestors of', 'not descendants of') else 'in'
|
||||
|
||||
|
||||
elif f.operator.lower() in ('in', 'not in'):
|
||||
values = f.value or ''
|
||||
if isinstance(values, str):
|
||||
values = values.split(",")
|
||||
|
||||
fallback = "''"
|
||||
value = [frappe.db.escape((v or '').strip(), percent=False) for v in values]
|
||||
value = [frappe.db.escape((cstr(v) or '').strip(), percent=False) for v in values]
|
||||
if len(value):
|
||||
value = f"({', '.join(value)})"
|
||||
else:
|
||||
value = "('')"
|
||||
|
||||
else:
|
||||
df = frappe.get_meta(f.doctype).get("fields", {"fieldname": f.fieldname})
|
||||
df = meta.get("fields", {"fieldname": f.fieldname})
|
||||
df = df[0] if df else None
|
||||
|
||||
if df and df.fieldtype in ("Check", "Float", "Int", "Currency", "Percent"):
|
||||
|
|
@ -513,7 +553,8 @@ class DatabaseQuery(object):
|
|||
fallback = "'0001-01-01 00:00:00'"
|
||||
|
||||
elif f.operator.lower() in ('between') and \
|
||||
(f.fieldname in ('creation', 'modified') or (df and (df.fieldtype=="Date" or df.fieldtype=="Datetime"))):
|
||||
(f.fieldname in ('creation', 'modified') or
|
||||
(df and (df.fieldtype=="Date" or df.fieldtype=="Datetime"))):
|
||||
|
||||
value = get_between_date_filter(f.value, df)
|
||||
fallback = "'0001-01-01 00:00:00'"
|
||||
|
|
@ -528,7 +569,7 @@ class DatabaseQuery(object):
|
|||
fallback = "''"
|
||||
can_be_null = True
|
||||
|
||||
if 'ifnull' not in column_name:
|
||||
if 'ifnull' not in column_name.lower():
|
||||
column_name = f'ifnull({column_name}, {fallback})'
|
||||
|
||||
elif df and df.fieldtype=="Date":
|
||||
|
|
@ -570,7 +611,7 @@ class DatabaseQuery(object):
|
|||
value = f"{tname}.{quote}{f.value.name}{quote}"
|
||||
|
||||
# escape value
|
||||
elif isinstance(value, str) and not f.operator.lower() == 'between':
|
||||
elif isinstance(value, str) and f.operator.lower() != 'between':
|
||||
value = f"{frappe.db.escape(value, percent=False)}"
|
||||
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ def update_naming_series(doc):
|
|||
and getattr(doc, "naming_series", None):
|
||||
revert_series_if_last(doc.naming_series, doc.name, doc)
|
||||
|
||||
elif doc.meta.autoname.split(":")[0] not in ("Prompt", "field", "hash"):
|
||||
elif doc.meta.autoname.split(":")[0] not in ("Prompt", "field", "hash", "autoincrement"):
|
||||
revert_series_if_last(doc.meta.autoname, doc.name, doc)
|
||||
|
||||
def delete_from_table(doctype, name, ignore_doctypes, doc):
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: MIT. See LICENSE
|
||||
|
||||
from typing import Optional
|
||||
from typing import Optional, TYPE_CHECKING, Union
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.database.sequence import get_next_val, set_next_val
|
||||
from frappe.utils import now_datetime, cint, cstr
|
||||
import re
|
||||
from frappe.model import log_types
|
||||
from frappe.query_builder import DocType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from frappe.model.meta import Meta
|
||||
|
||||
|
||||
def set_new_name(doc):
|
||||
"""
|
||||
|
|
@ -24,11 +28,16 @@ def set_new_name(doc):
|
|||
|
||||
doc.run_method("before_naming")
|
||||
|
||||
autoname = frappe.get_meta(doc.doctype).autoname or ""
|
||||
meta = frappe.get_meta(doc.doctype)
|
||||
autoname = meta.autoname or ""
|
||||
|
||||
if autoname.lower() != "prompt" and not frappe.flags.in_import:
|
||||
doc.name = None
|
||||
|
||||
if is_autoincremented(doc.doctype, meta):
|
||||
doc.name = get_next_val(doc.doctype)
|
||||
return
|
||||
|
||||
if getattr(doc, "amended_from", None):
|
||||
_set_amended_name(doc)
|
||||
return
|
||||
|
|
@ -64,9 +73,37 @@ def set_new_name(doc):
|
|||
doc.name = validate_name(
|
||||
doc.doctype,
|
||||
doc.name,
|
||||
frappe.get_meta(doc.doctype).get_field("name_case")
|
||||
meta.get_field("name_case")
|
||||
)
|
||||
|
||||
def is_autoincremented(doctype: str, meta: "Meta" = None):
|
||||
if doctype in log_types:
|
||||
if frappe.local.autoincremented_status_map.get(frappe.local.site) is None or \
|
||||
frappe.local.autoincremented_status_map[frappe.local.site] == -1:
|
||||
if frappe.db.sql(
|
||||
f"""select data_type FROM information_schema.columns
|
||||
where column_name = 'name' and table_name = 'tab{doctype}'"""
|
||||
)[0][0] == "bigint":
|
||||
frappe.local.autoincremented_status_map[frappe.local.site] = 1
|
||||
return True
|
||||
else:
|
||||
frappe.local.autoincremented_status_map[frappe.local.site] = 0
|
||||
|
||||
elif frappe.local.autoincremented_status_map[frappe.local.site]:
|
||||
return True
|
||||
|
||||
else:
|
||||
if not meta:
|
||||
meta = frappe.get_meta(doctype)
|
||||
|
||||
if getattr(meta, "issingle", False):
|
||||
return False
|
||||
|
||||
if meta.autoname == "autoincrement":
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def set_name_from_naming_options(autoname, doc):
|
||||
"""
|
||||
Get a name based on the autoname field option
|
||||
|
|
@ -284,9 +321,19 @@ def get_default_naming_series(doctype):
|
|||
return None
|
||||
|
||||
|
||||
def validate_name(doctype: str, name: str, case: Optional[str] = None):
|
||||
def validate_name(doctype: str, name: Union[int, str], case: Optional[str] = None):
|
||||
if not name:
|
||||
frappe.throw(_("No Name Specified for {0}").format(doctype))
|
||||
|
||||
if isinstance(name, int):
|
||||
if is_autoincremented(doctype):
|
||||
# this will set the sequence val to be the provided name and set it to be used
|
||||
# so that the sequence will start from the next val of the setted val(name)
|
||||
set_next_val(doctype, name, is_val_used=True)
|
||||
return name
|
||||
|
||||
frappe.throw(_("Invalid name type (integer) for varchar name column"), frappe.NameError)
|
||||
|
||||
if name.startswith("New "+doctype):
|
||||
frappe.throw(_("There were some errors setting the name, please contact the administrator"), frappe.NameError)
|
||||
if case == "Title Case":
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ def update_document_title(
|
|||
|
||||
title_field = doc.meta.get_title_field()
|
||||
|
||||
title_updated = (title_field != "name") and (updated_title != doc.get(title_field))
|
||||
name_updated = updated_name != doc.name
|
||||
title_updated = updated_title and (title_field != "name") and (updated_title != doc.get(title_field))
|
||||
name_updated = updated_name and (updated_name != doc.name)
|
||||
|
||||
if name_updated:
|
||||
if enqueue and not is_scheduler_inactive():
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from frappe.query_builder import DocType
|
|||
from frappe.utils import get_datetime, now
|
||||
|
||||
|
||||
def caclulate_hash(path: str) -> str:
|
||||
def calculate_hash(path: str) -> str:
|
||||
"""Calculate md5 hash of the file in binary mode
|
||||
|
||||
Args:
|
||||
|
|
@ -99,7 +99,7 @@ def import_file_by_path(path: str,force: bool = False,data_import: bool = False,
|
|||
print(f"{path} missing")
|
||||
return
|
||||
|
||||
calculated_hash = caclulate_hash(path)
|
||||
calculated_hash = calculate_hash(path)
|
||||
|
||||
if docs:
|
||||
if not isinstance(docs, list):
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ frappe.patches.v13_0.update_duration_options
|
|||
frappe.patches.v13_0.replace_old_data_import # 2020-06-24
|
||||
frappe.patches.v13_0.create_custom_dashboards_cards_and_charts
|
||||
frappe.patches.v13_0.rename_is_custom_field_in_dashboard_chart
|
||||
frappe.patches.v13_0.add_standard_navbar_items # 2020-12-15
|
||||
frappe.patches.v13_0.add_standard_navbar_items # 2022-03-15
|
||||
frappe.patches.v13_0.generate_theme_files_in_public_folder
|
||||
frappe.patches.v13_0.increase_password_length
|
||||
frappe.patches.v12_0.fix_email_id_formatting
|
||||
|
|
|
|||
|
|
@ -594,4 +594,4 @@ def is_parent_valid(child_doctype, parent_doctype):
|
|||
from frappe.core.utils import find
|
||||
parent_meta = frappe.get_meta(parent_doctype)
|
||||
child_table_field_exists = find(parent_meta.get_table_fields(), lambda d: d.options == child_doctype)
|
||||
return not parent_meta.istable and child_table_field_exists
|
||||
return not parent_meta.istable and child_table_field_exists
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ ul.tree-children {
|
|||
}
|
||||
.tree-link .node-parent,
|
||||
.tree-link .node-leaf {
|
||||
margin-right: 5px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
.tree-link.active i {
|
||||
color: #5e64ff;
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro
|
|||
if(this.frm) {
|
||||
me.parse_validate_and_set_in_model(null);
|
||||
me.refresh();
|
||||
me.frm.attachments.remove_attachment_by_filename(me.value, function() {
|
||||
me.parse_validate_and_set_in_model(null);
|
||||
me.frm.attachments.remove_attachment_by_filename(me.value, async () => {
|
||||
await me.parse_validate_and_set_in_model(null);
|
||||
me.refresh();
|
||||
me.frm.doc.docstatus == 1 ? me.frm.save('Update') : me.frm.save();
|
||||
});
|
||||
|
|
@ -110,9 +110,9 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro
|
|||
return this.value || null;
|
||||
}
|
||||
|
||||
on_upload_complete(attachment) {
|
||||
async on_upload_complete(attachment) {
|
||||
if(this.frm) {
|
||||
this.parse_validate_and_set_in_model(attachment.file_url);
|
||||
await this.parse_validate_and_set_in_model(attachment.file_url);
|
||||
this.frm.attachments.update_attachment(attachment);
|
||||
this.frm.doc.docstatus == 1 ? this.frm.save('Update') : this.frm.save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,6 +166,9 @@ frappe.ui.form.ControlAutocomplete = class ControlAutoComplete extends frappe.ui
|
|||
}
|
||||
|
||||
parse_options(options) {
|
||||
if (typeof options === 'string' && options[0] === '[') {
|
||||
options = frappe.utils.parse_json(options);
|
||||
}
|
||||
if (typeof options === 'string') {
|
||||
options = options.split('\n');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -454,7 +454,10 @@ class FormTimeline extends BaseTimeline {
|
|||
let edit_box = this.make_editable(edit_wrapper);
|
||||
let content_wrapper = comment_wrapper.find('.content');
|
||||
let more_actions_wrapper = comment_wrapper.find('.more-actions');
|
||||
if (frappe.model.can_delete("Comment")) {
|
||||
if (frappe.model.can_delete("Comment") && (
|
||||
frappe.session.user == doc.owner ||
|
||||
frappe.user.has_role("System Manager")
|
||||
)) {
|
||||
const delete_option = $(`
|
||||
<li>
|
||||
<a class="dropdown-item">
|
||||
|
|
|
|||
|
|
@ -246,10 +246,12 @@ frappe.ui.form.Form = class FrappeForm {
|
|||
var me = this;
|
||||
|
||||
// on main doc
|
||||
frappe.model.on(me.doctype, "*", function(fieldname, value, doc) {
|
||||
frappe.model.on(me.doctype, "*", function(fieldname, value, doc, skip_dirty_trigger=false) {
|
||||
// set input
|
||||
if(doc.name===me.docname) {
|
||||
me.dirty();
|
||||
if (cstr(doc.name) === me.docname) {
|
||||
if (!skip_dirty_trigger) {
|
||||
me.dirty();
|
||||
}
|
||||
|
||||
let field = me.fields_dict[fieldname];
|
||||
field && field.refresh(fieldname);
|
||||
|
|
@ -953,10 +955,12 @@ frappe.ui.form.Form = class FrappeForm {
|
|||
this.toolbar.set_primary_action();
|
||||
}
|
||||
|
||||
disable_save() {
|
||||
disable_save(set_dirty=false) {
|
||||
// IMPORTANT: this function should be called in refresh event
|
||||
this.save_disabled = true;
|
||||
this.toolbar.current_status = null;
|
||||
// field changes should make form dirty
|
||||
this.set_dirty = set_dirty;
|
||||
this.page.clear_primary_action();
|
||||
}
|
||||
|
||||
|
|
@ -1447,7 +1451,7 @@ frappe.ui.form.Form = class FrappeForm {
|
|||
return doc;
|
||||
}
|
||||
|
||||
set_value(field, value, if_missing) {
|
||||
set_value(field, value, if_missing, skip_dirty_trigger=false) {
|
||||
var me = this;
|
||||
var _set = function(f, v) {
|
||||
var fieldobj = me.fields_dict[f];
|
||||
|
|
@ -1467,7 +1471,7 @@ frappe.ui.form.Form = class FrappeForm {
|
|||
me.refresh_field(f);
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
return frappe.model.set_value(me.doctype, me.doc.name, f, v);
|
||||
return frappe.model.set_value(me.doctype, me.doc.name, f, v, me.fieldtype, skip_dirty_trigger);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ export default class Grid {
|
|||
&& this.frm.meta.__form_grid_templates[this.df.fieldname]) {
|
||||
this.template = this.frm.meta.__form_grid_templates[this.df.fieldname];
|
||||
}
|
||||
|
||||
this.filter = {};
|
||||
this.is_grid = true;
|
||||
this.debounced_refresh = this.refresh.bind(this);
|
||||
this.debounced_refresh = frappe.utils.debounce(this.debounced_refresh, 100);
|
||||
|
|
@ -274,6 +274,8 @@ export default class Grid {
|
|||
}
|
||||
|
||||
make_head() {
|
||||
if (this.prevent_build) return;
|
||||
|
||||
// labels
|
||||
if (this.header_row) {
|
||||
$(this.parent).find(".grid-heading-row .grid-row").remove();
|
||||
|
|
@ -286,12 +288,42 @@ export default class Grid {
|
|||
grid: this,
|
||||
configure_columns: true
|
||||
});
|
||||
|
||||
this.header_search = new GridRow({
|
||||
parent: $(this.parent).find(".grid-heading-row"),
|
||||
parent_df: this.df,
|
||||
docfields: this.docfields,
|
||||
frm: this.frm,
|
||||
grid: this,
|
||||
show_search: true
|
||||
});
|
||||
|
||||
Object.keys(this.filter).length !== 0 &&
|
||||
this.update_search_columns();
|
||||
}
|
||||
|
||||
refresh(force) {
|
||||
update_search_columns() {
|
||||
for (const field in this.filter) {
|
||||
if (this.filter[field] && !this.header_search.search_columns[field]) {
|
||||
delete this.filter[field];
|
||||
this.data = this.get_data(Object.keys(this.filter).length !== 0);
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.filter[field] && this.filter[field].value) {
|
||||
let $input = this.header_search.row_index.find('input');
|
||||
if (field && field !== 'row-index') {
|
||||
$input = this.header_search.search_columns[field].find('input');
|
||||
}
|
||||
$input.val(this.filter[field].value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
refresh() {
|
||||
if (this.frm && this.frm.setting_dependency) return;
|
||||
|
||||
this.data = this.get_data();
|
||||
this.data = this.get_data(Object.keys(this.filter).length !== 0);
|
||||
|
||||
!this.wrapper && this.make();
|
||||
let $rows = $(this.parent).find('.rows');
|
||||
|
|
@ -453,7 +485,7 @@ export default class Grid {
|
|||
}
|
||||
|
||||
make_sortable($rows) {
|
||||
new Sortable($rows.get(0), {
|
||||
this.grid_sortable = new Sortable($rows.get(0), {
|
||||
group: { name: this.df.fieldname },
|
||||
handle: '.sortable-handle',
|
||||
draggable: '.grid-row',
|
||||
|
|
@ -484,14 +516,78 @@ export default class Grid {
|
|||
$(this.frm.wrapper).trigger("grid-make-sortable", [this.frm]);
|
||||
}
|
||||
|
||||
get_data() {
|
||||
var data = this.frm ?
|
||||
this.frm.doc[this.df.fieldname] || []
|
||||
: this.df.data || this.get_modal_data();
|
||||
// data.sort(function(a, b) { return a.idx - b.idx});
|
||||
get_data(filter_field) {
|
||||
let data = [];
|
||||
if (filter_field) {
|
||||
data = this.get_filtered_data();
|
||||
} else {
|
||||
data = this.frm ?
|
||||
this.frm.doc[this.df.fieldname] || []
|
||||
: this.df.data || this.get_modal_data();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
get_filtered_data() {
|
||||
if (!this.frm) return;
|
||||
|
||||
let all_data = this.frm.doc[this.df.fieldname];
|
||||
|
||||
for (const field in this.filter) {
|
||||
all_data = all_data.filter(data => {
|
||||
let {df, value} = this.filter[field];
|
||||
return this.get_data_based_on_fieldtype(df, data, value.toLowerCase());
|
||||
});
|
||||
}
|
||||
|
||||
return all_data;
|
||||
}
|
||||
|
||||
get_data_based_on_fieldtype(df, data, value) {
|
||||
let fieldname = df.fieldname;
|
||||
let fieldtype = df.fieldtype;
|
||||
let fieldvalue = data[fieldname];
|
||||
|
||||
if (fieldtype === "Check") {
|
||||
value = frappe.utils.string_to_boolean(value);
|
||||
return (Boolean(fieldvalue) === value) && data;
|
||||
} else if (fieldtype === "Sr No" && data.idx.toString().includes(value)) {
|
||||
return data;
|
||||
} else if (fieldtype === "Duration" && fieldvalue) {
|
||||
let formatted_duration = frappe.utils.get_formatted_duration(fieldvalue);
|
||||
|
||||
if (formatted_duration.includes(value)) {
|
||||
return data;
|
||||
}
|
||||
} else if (fieldtype === "Barcode" && fieldvalue) {
|
||||
let barcode = fieldvalue.startsWith('<svg') ?
|
||||
$(fieldvalue).attr('data-barcode-value') : fieldvalue;
|
||||
|
||||
if (barcode.toLowerCase().includes(value)) {
|
||||
return data;
|
||||
}
|
||||
} else if (["Datetime", "Date"].includes(fieldtype) && fieldvalue) {
|
||||
let user_formatted_date = frappe.datetime.str_to_user(fieldvalue);
|
||||
|
||||
if (user_formatted_date.includes(value)) {
|
||||
return data;
|
||||
}
|
||||
} else if (["Currency", "Float", "Int", "Percent", "Rating"].includes(fieldtype)) {
|
||||
let num = fieldvalue || 0;
|
||||
|
||||
if (fieldtype === "Rating") {
|
||||
let out_of_rating = parseInt(df.options) || 5;
|
||||
num = num * out_of_rating;
|
||||
}
|
||||
|
||||
if (num.toString().indexOf(value) > -1) {
|
||||
return data;
|
||||
}
|
||||
} else if (fieldvalue && fieldvalue.toLowerCase().includes(value)) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
get_modal_data() {
|
||||
return this.df.get_data ? this.df.get_data().filter(data => {
|
||||
if (!this.deleted_docs || !in_list(this.deleted_docs, data.name)) {
|
||||
|
|
@ -501,9 +597,9 @@ export default class Grid {
|
|||
}
|
||||
|
||||
set_column_disp(fieldname, show) {
|
||||
if ($.isArray(fieldname)) {
|
||||
if (Array.isArray(fieldname)) {
|
||||
for (let field of fieldname) {
|
||||
this.update_docfield_property(field, "hidden", show);
|
||||
this.update_docfield_property(field, "hidden", show ? 0 : 1);
|
||||
this.set_editable_grid_column_disp(field, show);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -775,18 +871,19 @@ export default class Grid {
|
|||
}
|
||||
|
||||
setup_user_defined_columns() {
|
||||
if (this.frm) {
|
||||
let user_settings = frappe.get_user_settings(this.frm.doctype, 'GridView');
|
||||
if (user_settings && user_settings[this.doctype] && user_settings[this.doctype].length) {
|
||||
this.user_defined_columns = user_settings[this.doctype].map(row => {
|
||||
let column = frappe.meta.get_docfield(this.doctype, row.fieldname);
|
||||
if (column) {
|
||||
column.in_list_view = 1;
|
||||
column.columns = row.columns;
|
||||
return column;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!this.frm) return;
|
||||
|
||||
let user_settings = frappe.get_user_settings(this.frm.doctype, 'GridView');
|
||||
if (user_settings && user_settings[this.doctype] && user_settings[this.doctype].length) {
|
||||
this.user_defined_columns = user_settings[this.doctype].map(row => {
|
||||
let column = frappe.meta.get_docfield(this.doctype, row.fieldname);
|
||||
|
||||
if (column) {
|
||||
column.in_list_view = 1;
|
||||
column.columns = row.columns;
|
||||
return column;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export default class GridRow {
|
|||
this.set_docfields();
|
||||
this.columns = {};
|
||||
this.columns_list = [];
|
||||
this.row_check_html = '<input type="checkbox" class="grid-row-check pull-left">';
|
||||
this.row_check_html = '<input type="checkbox" class="grid-row-check">';
|
||||
this.make();
|
||||
}
|
||||
make() {
|
||||
|
|
@ -204,23 +204,65 @@ export default class GridRow {
|
|||
}));
|
||||
}
|
||||
render_row(refresh) {
|
||||
var me = this;
|
||||
if (this.show_search && !this.show_search_row()) return;
|
||||
|
||||
let me = this;
|
||||
this.set_row_index();
|
||||
|
||||
// index (1, 2, 3 etc)
|
||||
if(!this.row_index) {
|
||||
if (!this.row_index && !this.show_search) {
|
||||
// REDESIGN-TODO: Make translation contextual, this No is Number
|
||||
var txt = (this.doc ? this.doc.idx : __("No."));
|
||||
this.row_index = $(
|
||||
`<div class="row-index sortable-handle col">
|
||||
|
||||
this.row_check = $(
|
||||
`<div class="row-check sortable-handle col">
|
||||
${this.row_check_html}
|
||||
<span class="hidden-xs">${txt}</span></div>`)
|
||||
</div>`)
|
||||
.appendTo(this.row);
|
||||
|
||||
this.row_index = $(
|
||||
`<div class="row-index sortable-handle col hidden-xs">
|
||||
<span>${txt}</span>
|
||||
</div>`)
|
||||
.appendTo(this.row)
|
||||
.on('click', function(e) {
|
||||
if(!$(e.target).hasClass('grid-row-check')) {
|
||||
me.toggle_view();
|
||||
}
|
||||
});
|
||||
} else if (this.show_search) {
|
||||
this.row_check = $(
|
||||
`<div class="row-check col search"></div>`
|
||||
).appendTo(this.row);
|
||||
|
||||
this.row_index = $(
|
||||
`<div class="row-index col search hidden-xs">
|
||||
<input type="text" class="form-control input-xs text-center" >
|
||||
</div>`
|
||||
).appendTo(this.row);
|
||||
|
||||
this.row_index.find('input').on('keyup', frappe.utils.debounce((e) => {
|
||||
let df = {
|
||||
fieldtype: "Sr No"
|
||||
};
|
||||
|
||||
this.grid.filter['row-index'] = {
|
||||
df: df,
|
||||
value: e.target.value
|
||||
};
|
||||
|
||||
if (e.target.value == "") {
|
||||
delete this.grid.filter['row-index'];
|
||||
}
|
||||
|
||||
this.grid.grid_sortable
|
||||
.option('disabled', Object.keys(this.grid.filter).length !== 0);
|
||||
|
||||
this.grid.prevent_build = true;
|
||||
me.grid.refresh();
|
||||
this.grid.prevent_build = false;
|
||||
}, 500));
|
||||
frappe.utils.only_allow_num_decimal(this.row_index.find('input'));
|
||||
} else {
|
||||
this.row_index.find('span').html(txt);
|
||||
}
|
||||
|
|
@ -546,6 +588,7 @@ export default class GridRow {
|
|||
|
||||
setup_columns() {
|
||||
this.focus_set = false;
|
||||
this.search_columns = {};
|
||||
|
||||
this.grid.setup_visible_columns();
|
||||
this.grid.visible_columns.forEach((col, ci) => {
|
||||
|
|
@ -561,8 +604,10 @@ export default class GridRow {
|
|||
txt = __(txt);
|
||||
}
|
||||
let column;
|
||||
if (!this.columns[df.fieldname]) {
|
||||
if (!this.columns[df.fieldname] && !this.show_search) {
|
||||
column = this.make_column(df, colsize, txt, ci);
|
||||
} else if (!this.columns[df.fieldname] && this.show_search) {
|
||||
column = this.make_search_column(df, colsize);
|
||||
} else {
|
||||
column = this.columns[df.fieldname];
|
||||
this.refresh_field(df.fieldname, txt);
|
||||
|
|
@ -580,6 +625,77 @@ export default class GridRow {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (this.show_search) {
|
||||
// last empty column
|
||||
$(`<div class="col grid-static-col col-xs-1"></div>`)
|
||||
.appendTo(this.row);
|
||||
}
|
||||
}
|
||||
|
||||
show_search_row() {
|
||||
// show or remove search columns based on grid rows
|
||||
this.show_search = this.frm && this.frm.doc &&
|
||||
this.frm.doc[this.grid.df.fieldname] &&
|
||||
this.frm.doc[this.grid.df.fieldname].length >= 20;
|
||||
!this.show_search && this.wrapper.remove();
|
||||
return this.show_search;
|
||||
}
|
||||
|
||||
make_search_column(df, colsize) {
|
||||
let title = "";
|
||||
let input_class = "";
|
||||
let is_disabled = "";
|
||||
|
||||
if (["Text", "Small Text"].includes(df.fieldtype)) {
|
||||
input_class = "grid-overflow-no-ellipsis";
|
||||
} else if (["Int", "Currency", "Float", "Percent"].includes(df.fieldtype)) {
|
||||
input_class = "text-right";
|
||||
} else if (df.fieldtype === "Check") {
|
||||
title = __("1 = True & 0 = False");
|
||||
input_class = "text-center";
|
||||
} else if (df.fieldtype === 'Password') {
|
||||
is_disabled = 'disabled';
|
||||
title = __('Password cannot be filtered');
|
||||
}
|
||||
|
||||
let $col = $('<div class="col grid-static-col col-xs-'+colsize+' search"></div>')
|
||||
.appendTo(this.row);
|
||||
|
||||
let $search_input = $(`
|
||||
<input
|
||||
type="text"
|
||||
class="form-control input-xs ${input_class}"
|
||||
title="${title}"
|
||||
data-fieldtype="${df.fieldtype}"
|
||||
${is_disabled}
|
||||
>
|
||||
`).appendTo($col);
|
||||
|
||||
this.search_columns[df.fieldname] = $col;
|
||||
|
||||
$search_input.on('keyup', frappe.utils.debounce((e) => {
|
||||
this.grid.filter[df.fieldname] = {
|
||||
df: df,
|
||||
value: e.target.value
|
||||
};
|
||||
|
||||
if (e.target.value == '') {
|
||||
delete this.grid.filter[df.fieldname];
|
||||
}
|
||||
|
||||
this.grid.grid_sortable
|
||||
.option('disabled', Object.keys(this.grid.filter).length !== 0);
|
||||
|
||||
this.grid.prevent_build = true;
|
||||
this.grid.refresh();
|
||||
this.grid.prevent_build = false;
|
||||
}, 500));
|
||||
|
||||
["Currency", "Float", "Int", "Percent", "Rating"].includes(df.fieldtype) &&
|
||||
frappe.utils.only_allow_num_decimal($search_input);
|
||||
|
||||
return $col;
|
||||
}
|
||||
|
||||
make_column(df, colsize, txt, ci) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
// MIT License. See license.txt
|
||||
// Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
// MIT License. See LICENSE
|
||||
|
||||
|
||||
frappe.ui.form.LinkedWith = class LinkedWith {
|
||||
|
||||
constructor(opts) {
|
||||
$.extend(this, opts);
|
||||
}
|
||||
|
|
@ -21,29 +20,23 @@ frappe.ui.form.LinkedWith = class LinkedWith {
|
|||
}
|
||||
|
||||
make_dialog() {
|
||||
|
||||
this.dialog = new frappe.ui.Dialog({
|
||||
title: __("Linked With")
|
||||
});
|
||||
|
||||
this.dialog.on_page_show = () => {
|
||||
// execute ajax calls sequentially
|
||||
// 1. get linked doctypes
|
||||
// 2. load all doctypes
|
||||
// 3. load linked docs
|
||||
this.get_linked_doctypes()
|
||||
.then(() => this.load_doctypes())
|
||||
.then(() => this.links_not_permitted_or_missing())
|
||||
.then(() => this.get_linked_docs())
|
||||
.then(() => this.make_html());
|
||||
frappe.xcall(
|
||||
"frappe.desk.form.linked_with.get",
|
||||
{"doctype": cur_frm.doctype, "docname": cur_frm.docname},
|
||||
).then(r => {
|
||||
this.frm.__linked_docs = r;
|
||||
}).then(() => this.make_html());
|
||||
};
|
||||
}
|
||||
|
||||
make_html() {
|
||||
const linked_docs = this.frm.__linked_docs;
|
||||
|
||||
let html = '';
|
||||
|
||||
const linked_docs = this.frm.__linked_docs;
|
||||
const linked_doctypes = Object.keys(linked_docs);
|
||||
|
||||
if (linked_doctypes.length === 0) {
|
||||
|
|
@ -63,88 +56,6 @@ frappe.ui.form.LinkedWith = class LinkedWith {
|
|||
$(this.dialog.body).html(html);
|
||||
}
|
||||
|
||||
load_doctypes() {
|
||||
const already_loaded = Object.keys(locals.DocType);
|
||||
let doctypes_to_load = [];
|
||||
|
||||
if (this.frm.__linked_doctypes) {
|
||||
doctypes_to_load =
|
||||
Object.keys(this.frm.__linked_doctypes)
|
||||
.filter(doctype => !already_loaded.includes(doctype));
|
||||
}
|
||||
|
||||
// load all doctypes asynchronously using with_doctype
|
||||
const promises = doctypes_to_load.map(dt => {
|
||||
return frappe.model.with_doctype(dt, () => {
|
||||
if(frappe.listview_settings[dt]) {
|
||||
// add additional fields to __linked_doctypes
|
||||
this.frm.__linked_doctypes[dt].add_fields =
|
||||
frappe.listview_settings[dt].add_fields;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
links_not_permitted_or_missing() {
|
||||
let links = null;
|
||||
|
||||
if (this.frm.__linked_doctypes) {
|
||||
links =
|
||||
Object.keys(this.frm.__linked_doctypes)
|
||||
.filter(frappe.model.can_get_report);
|
||||
}
|
||||
|
||||
let flag;
|
||||
if(!links) {
|
||||
$(this.dialog.body).html(`${this.frm.__linked_doctypes
|
||||
? __("Not enough permission to see links")
|
||||
: __("Not Linked to any record")}`);
|
||||
flag = true;
|
||||
}
|
||||
flag = false;
|
||||
|
||||
// reject Promise if not_permitted or missing
|
||||
return new Promise(
|
||||
(resolve, reject) => flag ? reject() : resolve()
|
||||
);
|
||||
}
|
||||
|
||||
get_linked_doctypes() {
|
||||
return new Promise((resolve) => {
|
||||
if (this.frm.__linked_doctypes) {
|
||||
resolve();
|
||||
}
|
||||
|
||||
frappe.call({
|
||||
method: "frappe.desk.form.linked_with.get_linked_doctypes",
|
||||
args: {
|
||||
doctype: this.frm.doctype
|
||||
},
|
||||
callback: (r) => {
|
||||
this.frm.__linked_doctypes = r.message;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
get_linked_docs() {
|
||||
return frappe.call({
|
||||
method: "frappe.desk.form.linked_with.get_linked_docs",
|
||||
args: {
|
||||
doctype: this.frm.doctype,
|
||||
name: this.frm.docname,
|
||||
linkinfo: this.frm.__linked_doctypes,
|
||||
for_doctype: this.for_doctype
|
||||
},
|
||||
callback: (r) => {
|
||||
this.frm.__linked_docs = r.message || {};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
make_doc_head(heading) {
|
||||
return `
|
||||
<header class="level list-row list-row-head text-muted small">
|
||||
|
|
|
|||
|
|
@ -44,8 +44,17 @@ frappe.ui.form.Attachments = class Attachments {
|
|||
// add attachment objects
|
||||
var attachments = this.get_attachments();
|
||||
if(attachments.length) {
|
||||
attachments.forEach(function(attachment) {
|
||||
me.add_attachment(attachment)
|
||||
let exists = {};
|
||||
let unique_attachments = attachments.filter(attachment => {
|
||||
return Object.prototype.hasOwnProperty.call(
|
||||
exists,
|
||||
attachment.file_name
|
||||
)
|
||||
? false
|
||||
: (exists[attachment.file_name] = true);
|
||||
});
|
||||
unique_attachments.forEach(attachment => {
|
||||
me.add_attachment(attachment);
|
||||
});
|
||||
} else {
|
||||
this.attachments_label.removeClass("has-attachments");
|
||||
|
|
@ -75,7 +84,19 @@ frappe.ui.form.Attachments = class Attachments {
|
|||
remove_action = function(target_id) {
|
||||
frappe.confirm(__("Are you sure you want to delete the attachment?"),
|
||||
function() {
|
||||
me.remove_attachment(target_id);
|
||||
let target_attachment = me
|
||||
.get_attachments()
|
||||
.find(attachment => attachment.name === target_id);
|
||||
let to_be_removed = me
|
||||
.get_attachments()
|
||||
.filter(
|
||||
attachment =>
|
||||
attachment.file_name ===
|
||||
target_attachment.file_name
|
||||
);
|
||||
to_be_removed.forEach(attachment =>
|
||||
me.remove_attachment(attachment.name)
|
||||
);
|
||||
}
|
||||
);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -552,14 +552,14 @@ frappe.ui.form.Toolbar = class Toolbar {
|
|||
});
|
||||
}
|
||||
show_title_as_dirty() {
|
||||
if(this.frm.save_disabled)
|
||||
if (this.frm.save_disabled && !this.frm.set_dirty)
|
||||
return;
|
||||
|
||||
if(this.frm.doc.__unsaved) {
|
||||
if (this.frm.is_dirty()) {
|
||||
this.page.set_indicator(__("Not Saved"), "orange");
|
||||
}
|
||||
|
||||
$(this.frm.wrapper).attr("data-state", this.frm.doc.__unsaved ? "dirty" : "clean");
|
||||
$(this.frm.wrapper).attr("data-state", this.frm.is_dirty() ? "dirty" : "clean");
|
||||
}
|
||||
|
||||
show_jump_to_field_dialog() {
|
||||
|
|
|
|||
|
|
@ -760,6 +760,10 @@ class FilterArea {
|
|||
|
||||
const doctype_fields = this.list_view.meta.fields;
|
||||
const title_field = this.list_view.meta.title_field;
|
||||
const has_existing_filters = (
|
||||
this.list_view.filters
|
||||
&& this.list_view.filters.length > 0
|
||||
);
|
||||
|
||||
fields = fields.concat(
|
||||
doctype_fields
|
||||
|
|
@ -794,13 +798,17 @@ class FilterArea {
|
|||
options = options.join("\n");
|
||||
}
|
||||
}
|
||||
let default_value =
|
||||
fieldtype === "Link"
|
||||
? frappe.defaults.get_user_default(options)
|
||||
: null;
|
||||
|
||||
let default_value;
|
||||
|
||||
if (fieldtype === "Link" && !has_existing_filters) {
|
||||
default_value = frappe.defaults.get_user_default(options);
|
||||
}
|
||||
|
||||
if (["__default", "__global"].includes(default_value)) {
|
||||
default_value = null;
|
||||
}
|
||||
|
||||
return {
|
||||
fieldtype: fieldtype,
|
||||
label: __(df.label),
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ frappe.provide('frappe.views.list_view');
|
|||
window.cur_list = null;
|
||||
frappe.views.ListFactory = class ListFactory extends frappe.views.Factory {
|
||||
make (route) {
|
||||
var me = this;
|
||||
var doctype = route[1];
|
||||
const me = this;
|
||||
const doctype = route[1];
|
||||
|
||||
// List / Gantt / Kanban / etc
|
||||
// File is a special view
|
||||
|
|
@ -21,60 +21,58 @@ frappe.views.ListFactory = class ListFactory extends frappe.views.Factory {
|
|||
}
|
||||
|
||||
frappe.provide('frappe.views.list_view.' + doctype);
|
||||
const page_name = frappe.get_route_str();
|
||||
|
||||
if (!frappe.views.list_view[page_name]) {
|
||||
frappe.views.list_view[page_name] = new view_class({
|
||||
doctype: doctype,
|
||||
parent: me.make_page(true, page_name)
|
||||
});
|
||||
} else {
|
||||
frappe.container.change_to(page_name);
|
||||
}
|
||||
frappe.views.list_view[me.page_name] = new view_class({
|
||||
doctype: doctype,
|
||||
parent: me.make_page(true, me.page_name)
|
||||
});
|
||||
|
||||
me.set_cur_list();
|
||||
|
||||
|
||||
}
|
||||
|
||||
show() {
|
||||
before_show() {
|
||||
if (this.re_route_to_view()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.set_module_breadcrumb();
|
||||
super.show();
|
||||
}
|
||||
|
||||
on_show() {
|
||||
this.set_cur_list();
|
||||
cur_list && cur_list.show();
|
||||
if (cur_list) cur_list.show();
|
||||
}
|
||||
|
||||
re_route_to_view() {
|
||||
var route = frappe.get_route();
|
||||
var doctype = route[1];
|
||||
var last_route = frappe.route_history.slice(-2)[0];
|
||||
if (route[0] === 'List' && route.length === 2 && frappe.views.list_view[doctype]) {
|
||||
if(last_route && last_route[0]==='List' && last_route[1]===doctype) {
|
||||
// last route same as this route, so going back.
|
||||
// this happens because /app/List/Item will redirect to /app/List/Item/List
|
||||
// while coming from back button, the last 2 routes will be same, so
|
||||
// we know user is coming in the reverse direction (via back button)
|
||||
const doctype = this.route[1];
|
||||
const last_route = frappe.route_history.slice(-2)[0];
|
||||
if (
|
||||
this.route[0] === 'List' &&
|
||||
this.route.length === 2 &&
|
||||
frappe.views.list_view[doctype] &&
|
||||
last_route &&
|
||||
last_route[0] === 'List' &&
|
||||
last_route[1] === doctype
|
||||
) {
|
||||
// last route same as this route, so going back.
|
||||
// this happens because /app/List/Item will redirect to /app/List/Item/List
|
||||
// while coming from back button, the last 2 routes will be same, so
|
||||
// we know user is coming in the reverse direction (via back button)
|
||||
|
||||
// example:
|
||||
// Step 1: /app/List/Item redirects to /app/List/Item/List
|
||||
// Step 2: User hits "back" comes back to /app/List/Item
|
||||
// Step 3: Now we cannot send the user back to /app/List/Item/List so go back one more step
|
||||
window.history.go(-1);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// example:
|
||||
// Step 1: /app/List/Item redirects to /app/List/Item/List
|
||||
// Step 2: User hits "back" comes back to /app/List/Item
|
||||
// Step 3: Now we cannot send the user back to /app/List/Item/List so go back one more step
|
||||
window.history.go(-1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
set_module_breadcrumb() {
|
||||
if (frappe.route_history.length > 1) {
|
||||
var prev_route = frappe.route_history[frappe.route_history.length - 2];
|
||||
const prev_route = frappe.route_history[frappe.route_history.length - 2];
|
||||
if (prev_route[0] === 'modules') {
|
||||
var doctype = frappe.get_route()[1],
|
||||
module = prev_route[1];
|
||||
const doctype = this.route[1], module = prev_route[1];
|
||||
if (frappe.module_links[module] && frappe.module_links[module].includes(doctype)) {
|
||||
// save the last page from the breadcrumb was accessed
|
||||
frappe.breadcrumbs.set_doctype_module(doctype, module);
|
||||
|
|
@ -84,10 +82,8 @@ frappe.views.ListFactory = class ListFactory extends frappe.views.Factory {
|
|||
}
|
||||
|
||||
set_cur_list() {
|
||||
var route = frappe.get_route();
|
||||
var page_name = frappe.get_route_str();
|
||||
cur_list = frappe.views.list_view[page_name];
|
||||
if (cur_list && cur_list.doctype !== route[1]) {
|
||||
cur_list = frappe.views.list_view[this.page_name];
|
||||
if (cur_list && cur_list.doctype !== this.route[1]) {
|
||||
// changing...
|
||||
window.cur_list = null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ export default class ListSettings {
|
|||
let me = this;
|
||||
|
||||
if (me.removed_fields) {
|
||||
me.removed_fields.concat(fields);
|
||||
me.removed_fields = me.removed_fields.concat(fields);
|
||||
} else {
|
||||
me.removed_fields = fields;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,32 +83,15 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
|
|||
this.sort_by = this.view_user_settings.sort_by || "modified";
|
||||
this.sort_order = this.view_user_settings.sort_order || "desc";
|
||||
|
||||
// set filters from user_settings or list_settings
|
||||
if (
|
||||
this.view_user_settings.filters &&
|
||||
this.view_user_settings.filters.length
|
||||
) {
|
||||
// Priority 1: user_settings
|
||||
const saved_filters = this.view_user_settings.filters;
|
||||
this.filters = this.validate_filters(saved_filters);
|
||||
} else {
|
||||
// Priority 2: filters in listview_settings
|
||||
this.filters = (this.settings.filters || []).map((f) => {
|
||||
if (f.length === 3) {
|
||||
f = [this.doctype, f[0], f[1], f[2]];
|
||||
}
|
||||
return f;
|
||||
});
|
||||
}
|
||||
|
||||
// build menu items
|
||||
this.menu_items = this.menu_items.concat(this.get_menu_items());
|
||||
|
||||
// set filters from view_user_settings or list_settings
|
||||
if (
|
||||
this.view_user_settings.filters &&
|
||||
this.view_user_settings.filters.length
|
||||
) {
|
||||
// Priority 1: saved filters
|
||||
// Priority 1: view_user_settings
|
||||
const saved_filters = this.view_user_settings.filters;
|
||||
this.filters = this.validate_filters(saved_filters);
|
||||
} else {
|
||||
|
|
@ -932,7 +915,7 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
|
|||
return this.settings.get_form_link(doc);
|
||||
}
|
||||
|
||||
const docname = doc.name.match(/[%'"#\s]/)
|
||||
const docname = cstr(doc.name).match(/[%'"#\s]/)
|
||||
? encodeURIComponent(doc.name)
|
||||
: doc.name;
|
||||
|
||||
|
|
@ -1757,8 +1740,12 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
|
|||
const docnames = this.get_checked_items(true).map(
|
||||
(docname) => docname.toString()
|
||||
);
|
||||
let message = __("Delete {0} item permanently?", [docnames.length], "Title of confirmation dialog");
|
||||
if (docnames.length > 1) {
|
||||
message = __("Delete {0} items permanently?", [docnames.length], "Title of confirmation dialog");
|
||||
}
|
||||
frappe.confirm(
|
||||
__("Delete {0} items permanently?", [docnames.length], "Title of confirmation dialog"),
|
||||
message,
|
||||
() => {
|
||||
this.disable_list_update = true;
|
||||
bulk_operations.delete(docnames, () => {
|
||||
|
|
|
|||
|
|
@ -138,6 +138,7 @@ frappe.render_tree = function(opts) {
|
|||
opts.base_url = frappe.urllib.get_base_url();
|
||||
opts.landscape = false;
|
||||
opts.print_css = frappe.boot.print_css;
|
||||
opts.print_format_css_path = frappe.assets.bundled_asset('print_format.bundle.css');
|
||||
var tree = frappe.render_template("print_tree", opts);
|
||||
var w = window.open();
|
||||
|
||||
|
|
|
|||
|
|
@ -412,7 +412,7 @@ $.extend(frappe.model, {
|
|||
}
|
||||
},
|
||||
|
||||
set_value: function(doctype, docname, fieldname, value, fieldtype) {
|
||||
set_value: function(doctype, docname, fieldname, value, fieldtype, skip_dirty_trigger=false) {
|
||||
/* help: Set a value locally (if changed) and execute triggers */
|
||||
|
||||
var doc;
|
||||
|
|
@ -438,11 +438,11 @@ $.extend(frappe.model, {
|
|||
}
|
||||
|
||||
doc[key] = value;
|
||||
tasks.push(() => frappe.model.trigger(key, value, doc));
|
||||
tasks.push(() => frappe.model.trigger(key, value, doc, skip_dirty_trigger));
|
||||
} else {
|
||||
// execute link triggers (want to reselect to execute triggers)
|
||||
if(in_list(["Link", "Dynamic Link"], fieldtype) && doc) {
|
||||
tasks.push(() => frappe.model.trigger(key, value, doc));
|
||||
tasks.push(() => frappe.model.trigger(key, value, doc, skip_dirty_trigger));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -467,7 +467,7 @@ $.extend(frappe.model, {
|
|||
frappe.model.events[doctype][fieldname].push(fn);
|
||||
},
|
||||
|
||||
trigger: function(fieldname, value, doc) {
|
||||
trigger: function(fieldname, value, doc, skip_dirty_trigger=false) {
|
||||
const tasks = [];
|
||||
|
||||
function enqueue_events(events) {
|
||||
|
|
@ -477,7 +477,7 @@ $.extend(frappe.model, {
|
|||
if (!fn) continue;
|
||||
|
||||
tasks.push(() => {
|
||||
const return_value = fn(fieldname, value, doc);
|
||||
const return_value = fn(fieldname, value, doc, skip_dirty_trigger);
|
||||
|
||||
// if the trigger returns a promise, return it,
|
||||
// or use the default promise frappe.after_ajax
|
||||
|
|
@ -577,13 +577,15 @@ $.extend(frappe.model, {
|
|||
},
|
||||
|
||||
delete_doc: function(doctype, docname, callback) {
|
||||
var title = docname;
|
||||
var title_field = frappe.get_meta(doctype).title_field;
|
||||
let title = docname;
|
||||
const title_field = frappe.get_meta(doctype).title_field;
|
||||
if (frappe.get_meta(doctype).autoname == "hash" && title_field) {
|
||||
var title = frappe.model.get_value(doctype, docname, title_field);
|
||||
title += " (" + docname + ")";
|
||||
const value = frappe.model.get_value(doctype, docname, title_field);
|
||||
if (value) {
|
||||
title = `${value} (${docname})`;
|
||||
}
|
||||
}
|
||||
frappe.confirm(__("Permanently delete {0}?", [title]), function() {
|
||||
frappe.confirm(__("Permanently delete {0}?", [title.bold()]), function() {
|
||||
return frappe.call({
|
||||
method: 'frappe.client.delete',
|
||||
args: {
|
||||
|
|
|
|||
|
|
@ -134,7 +134,17 @@ frappe.msgprint = function(msg, title, is_minimizable) {
|
|||
}
|
||||
|
||||
if(data.message instanceof Array) {
|
||||
data.message.forEach(function(m) {
|
||||
let messages = data.message;
|
||||
const exceptions = messages
|
||||
.map(m => JSON.parse(m))
|
||||
.filter(m => m.raise_exception);
|
||||
|
||||
// only show exceptions if any exceptions exist
|
||||
if (exceptions.length) {
|
||||
messages = exceptions;
|
||||
}
|
||||
|
||||
messages.forEach(function(m) {
|
||||
frappe.msgprint(m);
|
||||
});
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -47,13 +47,17 @@ frappe.ui.Page = class Page {
|
|||
}
|
||||
|
||||
setup_scroll_handler() {
|
||||
window.addEventListener('scroll', () => {
|
||||
if (document.documentElement.scrollTop) {
|
||||
$('.page-head').toggleClass('drop-shadow', true);
|
||||
let last_scroll = 0;
|
||||
window.addEventListener('scroll', frappe.utils.throttle(() => {
|
||||
$('.page-head').toggleClass('drop-shadow', !!document.documentElement.scrollTop);
|
||||
let current_scroll = document.documentElement.scrollTop;
|
||||
if (current_scroll > 0 && last_scroll <= current_scroll) {
|
||||
$('.page-head').css("top", "-15px");
|
||||
} else {
|
||||
$('.page-head').removeClass('drop-shadow');
|
||||
$('.page-head').css("top", "var(--navbar-height)");
|
||||
}
|
||||
});
|
||||
last_scroll = current_scroll;
|
||||
}), 500);
|
||||
}
|
||||
|
||||
get_empty_state(title, message, primary_action) {
|
||||
|
|
|
|||
|
|
@ -196,6 +196,15 @@ Object.assign(frappe.utils, {
|
|||
}
|
||||
return true;
|
||||
},
|
||||
parse_json: function(str) {
|
||||
let parsed_json = '';
|
||||
try {
|
||||
parsed_json = JSON.parse(str);
|
||||
} catch (e) {
|
||||
return str;
|
||||
}
|
||||
return parsed_json;
|
||||
},
|
||||
strip_whitespace: function(html) {
|
||||
return (html || "").replace(/<p>\s*<\/p>/g, "").replace(/<br>(\s*<br>\s*)+/g, "<br><br>");
|
||||
},
|
||||
|
|
@ -222,7 +231,7 @@ Object.assign(frappe.utils, {
|
|||
if (tt && (tt.substr(0, 1)===">" || tt.substr(0, 4)===">")) {
|
||||
part.push(t);
|
||||
} else {
|
||||
out.concat(part);
|
||||
out = out.concat(part);
|
||||
out.push(t);
|
||||
part = [];
|
||||
}
|
||||
|
|
@ -1093,7 +1102,7 @@ Object.assign(frappe.utils, {
|
|||
seconds: round(seconds % 60)
|
||||
};
|
||||
|
||||
if (duration_options.hide_days) {
|
||||
if (duration_options && duration_options.hide_days) {
|
||||
total_duration.hours = round(seconds / 3600);
|
||||
total_duration.days = 0;
|
||||
}
|
||||
|
|
@ -1453,5 +1462,23 @@ Object.assign(frappe.utils, {
|
|||
console.log(error); // eslint-disable-line
|
||||
return Promise.resolve(name);
|
||||
}
|
||||
},
|
||||
|
||||
only_allow_num_decimal(input) {
|
||||
input.on('input', (e) => {
|
||||
let self = $(e.target);
|
||||
self.val(self.val().replace(/[^0-9.]/g, ''));
|
||||
if ((e.which != 46 || self.val().indexOf('.') != -1) && (e.which < 48 || e.which > 57)) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
string_to_boolean(string) {
|
||||
switch (string.toLowerCase().trim()) {
|
||||
case "t": case "true": case "y": case "yes": case "1": return true;
|
||||
case "f": case "false": case "n": case "no": case "0": case null: return false;
|
||||
default: return string;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,20 +10,21 @@ frappe.views.Factory = class Factory {
|
|||
}
|
||||
|
||||
show() {
|
||||
var page_name = frappe.get_route_str(),
|
||||
me = this;
|
||||
this.route = frappe.get_route();
|
||||
this.page_name = frappe.get_route_str();
|
||||
|
||||
if (frappe.pages[page_name]) {
|
||||
frappe.container.change_to(page_name);
|
||||
if(me.on_show) {
|
||||
me.on_show();
|
||||
if (this.before_show && this.before_show() === false) return;
|
||||
|
||||
if (frappe.pages[this.page_name]) {
|
||||
frappe.container.change_to(this.page_name);
|
||||
if (this.on_show) {
|
||||
this.on_show();
|
||||
}
|
||||
} else {
|
||||
var route = frappe.get_route();
|
||||
if(route[1]) {
|
||||
me.make(route);
|
||||
if (this.route[1]) {
|
||||
this.make(this.route);
|
||||
} else {
|
||||
frappe.show_not_found(route);
|
||||
frappe.show_not_found(this.route);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,15 +35,17 @@ frappe.views.Factory = class Factory {
|
|||
}
|
||||
|
||||
frappe.make_page = function(double_column, page_name) {
|
||||
if(!page_name) {
|
||||
var page_name = frappe.get_route_str();
|
||||
if (!page_name) {
|
||||
page_name = frappe.get_route_str();
|
||||
}
|
||||
var page = frappe.container.add_page(page_name);
|
||||
|
||||
const page = frappe.container.add_page(page_name);
|
||||
|
||||
frappe.ui.make_app_page({
|
||||
parent: page,
|
||||
single_column: !double_column
|
||||
});
|
||||
|
||||
frappe.container.change_to(page_name);
|
||||
return page;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,91 +1,106 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
<title>{{ title }}</title>
|
||||
<link href="{{ base_url }}/assets/frappe/css/bootstrap.css" rel="stylesheet">
|
||||
<link type="text/css" rel="stylesheet"
|
||||
href="{{ base_url }}/assets/frappe/css/font-awesome.css">
|
||||
<link rel="stylesheet" type="text/css" href="{{ base_url }}/assets/frappe/css/tree.css">
|
||||
<style>
|
||||
{{ print_css }}
|
||||
</style>
|
||||
<style>
|
||||
.tree.opened::before,
|
||||
.tree-node.opened::before,
|
||||
.tree:last-child::after,
|
||||
.tree-node:last-child::after {
|
||||
z-index: 1;
|
||||
border-left: 1px solid #d1d8dd;
|
||||
background: none;
|
||||
}
|
||||
.tree a,
|
||||
.tree-link {
|
||||
text-decoration: none;
|
||||
cursor: default;
|
||||
}
|
||||
.tree.opened > .tree-children > .tree-node > .tree-link::before,
|
||||
.tree-node.opened > .tree-children > .tree-node > .tree-link::before {
|
||||
border-top: 1px solid #d1d8dd;
|
||||
z-index: 1;
|
||||
background: none;
|
||||
}
|
||||
i.fa.fa-fw.fa-folder {
|
||||
z-index: 2;
|
||||
position: relative;
|
||||
}
|
||||
.tree:last-child::after, .tree-node:last-child::after {
|
||||
display: none;
|
||||
}
|
||||
.tree-node-toolbar {
|
||||
display: none;
|
||||
}
|
||||
i.octicon.octicon-primitive-dot.text-extra-muted {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 50%;
|
||||
background: #d1d8dd;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
ul.tree-children {
|
||||
padding-left: 20px;
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
<title>{{ title }}</title>
|
||||
<link href="{{ base_url }}/assets/frappe/css/bootstrap.css" rel="stylesheet">
|
||||
<link type="text/css" rel="stylesheet"
|
||||
href="{{ base_url }}/assets/frappe/css/font-awesome.css">
|
||||
<link rel="stylesheet" type="text/css" href="{{ base_url }}/assets/frappe/css/tree.css">
|
||||
<link rel="stylesheet" type="text/css" href="{{ base_url }}{{ print_format_css_path }}">
|
||||
<style>
|
||||
{{ print_css }}
|
||||
</style>
|
||||
<style>
|
||||
.tree.opened::before,
|
||||
.tree-node.opened::before,
|
||||
.tree:last-child::after,
|
||||
.tree-node:last-child::after {
|
||||
z-index: 1;
|
||||
border-left: 1px solid #d1d8dd;
|
||||
background: none;
|
||||
}
|
||||
.tree a,
|
||||
.tree-link {
|
||||
text-decoration: none;
|
||||
cursor: default;
|
||||
}
|
||||
.tree.opened > .tree-children > .tree-node > .tree-link::before,
|
||||
.tree-node.opened > .tree-children > .tree-node > .tree-link::before {
|
||||
border-top: 1px solid #d1d8dd;
|
||||
z-index: 1;
|
||||
background: none;
|
||||
}
|
||||
i.fa.fa-fw.fa-folder {
|
||||
z-index: 2;
|
||||
position: relative;
|
||||
}
|
||||
.tree:last-child::after, .tree-node:last-child::after {
|
||||
display: none;
|
||||
}
|
||||
.tree-node-toolbar {
|
||||
display: none;
|
||||
}
|
||||
i.octicon.octicon-primitive-dot.text-extra-muted {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 50%;
|
||||
background: #d1d8dd;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="print-format-gutter">
|
||||
{% if print_settings.repeat_header_footer %}
|
||||
<div id="footer-html" class="visible-pdf">
|
||||
{% if print_settings.letter_head && print_settings.letter_head.footer %}
|
||||
<div class="letter-head-footer">
|
||||
{{ print_settings.letter_head.footer }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<p class="text-center small page-number visible-pdf">
|
||||
{{ __("Page {0} of {1}", [`<span class="page"></span>`, `<span class="topage"></span>`]) }}
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="print-format {% if landscape %} landscape {% endif %}">
|
||||
{% if print_settings.letter_head %}
|
||||
<div {% if print_settings.repeat_header_footer %} id="header-html" class="hidden-pdf" {% endif %}>
|
||||
<div class="letter-head">{{ print_settings.letter_head.header }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="tree opened">
|
||||
{{ tree }}
|
||||
@media (max-width: 767px) {
|
||||
ul.tree-children {
|
||||
padding-left: 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<svg id="frappe-symbols" aria-hidden="true" style="position: absolute; width: 0; height: 0; overflow: hidden;" class="d-block" xmlns="http://www.w3.org/2000/svg">
|
||||
<symbol viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg" id="icon-primitive-dot">
|
||||
<path d="M9.5 6a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0z"></path>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" id="icon-folder-open">
|
||||
<path d="M8.024 6.5H3a.5.5 0 0 0-.5.5v8a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2V9.5A.5.5 0 0 0 17 9h-6.783a.5.5 0 0 1-.417-.224L8.441 6.724a.5.5 0 0 0-.417-.224z" stroke="var(--icon-stroke)" stroke-miterlimit="10" stroke-linecap="square"></path>
|
||||
<path d="M3.88 4.5v-1a.5.5 0 0 1 .5-.5h11.24a.5.5 0 0 1 .5.5V7" stroke="var(--icon-stroke)" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"></path>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" id="icon-folder-normal">
|
||||
<path d="M2.5 4v10a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2V6.5a1 1 0 0 0-1-1h-6.283a.5.5 0 0 1-.417-.224L8.441 3.224A.5.5 0 0 0 8.024 3H3.5a1 1 0 0 0-1 1z" stroke="var(--icon-stroke)" stroke-miterlimit="10" stroke-linecap="square"></path>
|
||||
</symbol>
|
||||
</svg>
|
||||
<div class="print-format-gutter">
|
||||
{% if print_settings.repeat_header_footer %}
|
||||
<div id="footer-html" class="visible-pdf">
|
||||
{% if print_settings.letter_head && print_settings.letter_head.footer %}
|
||||
<div class="letter-head-footer">
|
||||
{{ print_settings.letter_head.footer }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<p class="text-center small page-number visible-pdf">
|
||||
{{ __("Page {0} of {1}", [`<span class="page"></span>`, `<span class="topage"></span>`]) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
{% endif %}
|
||||
|
||||
<div class="print-format {% if landscape %} landscape {% endif %}">
|
||||
{% if print_settings.letter_head %}
|
||||
<div {% if print_settings.repeat_header_footer %} id="header-html" class="hidden-pdf" {% endif %}>
|
||||
<div class="letter-head">{{ print_settings.letter_head.header }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="tree opened">
|
||||
{{ tree }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -125,11 +125,12 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
|
|||
}
|
||||
|
||||
after_render() {
|
||||
if (this.report_doc) {
|
||||
this.set_dirty_state_for_custom_report();
|
||||
} else {
|
||||
if (!this.report_doc) {
|
||||
this.save_report_settings();
|
||||
} else if (!$.isEmptyObject(this.report_doc.json)) {
|
||||
this.set_dirty_state_for_custom_report();
|
||||
}
|
||||
|
||||
if (!this.group_by) {
|
||||
this.init_chart();
|
||||
}
|
||||
|
|
@ -1025,7 +1026,7 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
|
|||
}
|
||||
if (!docfield || docfield.report_hide) return;
|
||||
|
||||
let title = __(docfield ? docfield.label : toTitle(fieldname));
|
||||
let title = __(docfield.label);
|
||||
if (doctype !== this.doctype) {
|
||||
title += ` (${__(doctype)})`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ export default class WebFormList {
|
|||
if (this.table) {
|
||||
Array.from(this.table.tBodies).forEach(tbody => tbody.remove());
|
||||
let check = document.getElementById('select-all');
|
||||
check.checked = false;
|
||||
if (check)
|
||||
check.checked = false;
|
||||
}
|
||||
this.rows = [];
|
||||
this.page_length = 20;
|
||||
|
|
@ -131,9 +132,39 @@ export default class WebFormList {
|
|||
this.make_table_head();
|
||||
}
|
||||
|
||||
this.append_rows(this.data);
|
||||
if (this.data.length) {
|
||||
this.append_rows(this.data);
|
||||
this.wrapper.appendChild(this.table);
|
||||
} else {
|
||||
let new_button = "";
|
||||
let empty_state = document.createElement("div");
|
||||
empty_state.classList.add("no-result", "text-muted", "flex", "justify-center", "align-center");
|
||||
|
||||
this.wrapper.appendChild(this.table);
|
||||
frappe.has_permission(this.doctype, "", "create", () => {
|
||||
new_button = `
|
||||
<a
|
||||
class="btn btn-primary btn-sm btn-new-doc hidden-xs"
|
||||
href="${window.location.pathname}?new=1">
|
||||
${__("Create a new {0}", [__(this.doctype)])}
|
||||
</a>
|
||||
`;
|
||||
|
||||
empty_state.innerHTML = `
|
||||
<div class="text-center">
|
||||
<div>
|
||||
<img
|
||||
src="/assets/frappe/images/ui-states/list-empty-state.svg"
|
||||
alt="Generic Empty State"
|
||||
class="null-state">
|
||||
</div>
|
||||
<p class="small mb-2">${__("No {0} found", [__(this.doctype)])}</p>
|
||||
${new_button}
|
||||
</div>
|
||||
`;
|
||||
|
||||
this.wrapper.appendChild(empty_state);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
make_table_head() {
|
||||
|
|
@ -212,8 +243,7 @@ export default class WebFormList {
|
|||
"btn",
|
||||
"btn-secondary",
|
||||
"btn-sm",
|
||||
"ml-2",
|
||||
"text-white"
|
||||
"ml-2"
|
||||
);
|
||||
}
|
||||
else if (type == "danger") {
|
||||
|
|
|
|||
|
|
@ -89,6 +89,29 @@
|
|||
height: 34px;
|
||||
padding: 8px;
|
||||
max-height: 200px;
|
||||
|
||||
&.search {
|
||||
padding: 7px !important;
|
||||
|
||||
input {
|
||||
height: -webkit-fill-available;
|
||||
padding: 3px 7px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.row-check {
|
||||
height: 34px;
|
||||
padding: 8px 3px !important;
|
||||
text-align: center;
|
||||
|
||||
input {
|
||||
margin-right: 0 !important;
|
||||
}
|
||||
|
||||
&.search {
|
||||
padding: 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.grid-row-check {
|
||||
|
|
@ -124,7 +147,6 @@
|
|||
|
||||
.grid-row > .row {
|
||||
.col:last-child {
|
||||
margin-right: calc(-1 * var(--margin-sm));
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
|
|
@ -427,6 +449,7 @@
|
|||
}
|
||||
|
||||
.page-number {
|
||||
background-color: var(--fg-color);
|
||||
padding: 0 3px;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@
|
|||
top: var(--navbar-height);
|
||||
background: var(--bg-color);
|
||||
margin-bottom: 5px;
|
||||
transition: 0.5s top;
|
||||
.page-head-content {
|
||||
height: var(--page-head-height);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -311,3 +311,16 @@ h5.modal-title {
|
|||
.empty-list-icon {
|
||||
height: 70px;
|
||||
}
|
||||
|
||||
.null-state {
|
||||
height: 60px;
|
||||
width: auto;
|
||||
margin-bottom: var(--margin-md);
|
||||
img {
|
||||
fill: var(--fg-color);
|
||||
}
|
||||
}
|
||||
|
||||
.no-result {
|
||||
min-height: #{"calc(100vh - 284px)"};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from pypika.functions import *
|
||||
from pypika.terms import Function
|
||||
from pypika.terms import Function, CustomFunction, ArithmeticExpression, Arithmetic
|
||||
from frappe.query_builder.utils import ImportMapper, db_type_is
|
||||
from frappe.query_builder.custom import GROUP_CONCAT, STRING_AGG, MATCH, TO_TSVECTOR
|
||||
from frappe.database.query import Query
|
||||
|
|
@ -25,6 +25,24 @@ Match = ImportMapper(
|
|||
}
|
||||
)
|
||||
|
||||
class _PostgresTimestamp(ArithmeticExpression):
|
||||
def __init__(self, datepart, timepart, alias=None):
|
||||
if isinstance(datepart, str):
|
||||
datepart = Cast(datepart, "date")
|
||||
if isinstance(timepart, str):
|
||||
timepart = Cast(timepart, "time")
|
||||
|
||||
super().__init__(operator=Arithmetic.add,
|
||||
left=datepart, right=timepart, alias=alias)
|
||||
|
||||
|
||||
CombineDatetime = ImportMapper(
|
||||
{
|
||||
db_type_is.MARIADB: CustomFunction("TIMESTAMP", ["date", "time"]),
|
||||
db_type_is.POSTGRES: _PostgresTimestamp,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def _aggregate(function, dt, fieldname, filters, **kwargs):
|
||||
return (
|
||||
|
|
@ -46,4 +64,4 @@ def _avg(dt, fieldname, filters=None, **kwargs):
|
|||
return _aggregate(Avg, dt, fieldname, filters, **kwargs)
|
||||
|
||||
def _sum(dt, fieldname, filters=None, **kwargs):
|
||||
return _aggregate(Sum, dt, fieldname, filters, **kwargs)
|
||||
return _aggregate(Sum, dt, fieldname, filters, **kwargs)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
# License: MIT. See LICENSE
|
||||
|
||||
import frappe
|
||||
from frappe.utils.data import cstr
|
||||
import os
|
||||
import redis
|
||||
|
||||
|
|
@ -118,7 +119,7 @@ def get_user_info():
|
|||
}
|
||||
|
||||
def get_doc_room(doctype, docname):
|
||||
return ''.join([frappe.local.site, ':doc:', doctype, '/', docname])
|
||||
return ''.join([frappe.local.site, ':doc:', doctype, '/', cstr(docname)])
|
||||
|
||||
def get_user_room(user):
|
||||
return ''.join([frappe.local.site, ':user:', user])
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@
|
|||
<tr>
|
||||
<td valign="top">
|
||||
<p>{{ content }}</p>
|
||||
<p class="signature">{{ signature }}</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ class TestBaseDocument(unittest.TestCase):
|
|||
def test_docstatus(self):
|
||||
doc = BaseDocument({"docstatus": 0})
|
||||
self.assertTrue(doc.docstatus.is_draft())
|
||||
self.assertEquals(doc.docstatus, 0)
|
||||
self.assertEqual(doc.docstatus, 0)
|
||||
|
||||
doc.docstatus = 1
|
||||
self.assertTrue(doc.docstatus.is_submitted())
|
||||
self.assertEquals(doc.docstatus, 1)
|
||||
self.assertEqual(doc.docstatus, 1)
|
||||
|
||||
doc.docstatus = 2
|
||||
self.assertTrue(doc.docstatus.is_cancelled())
|
||||
self.assertEquals(doc.docstatus, 2)
|
||||
self.assertEqual(doc.docstatus, 2)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from frappe.database.database import Database
|
|||
from frappe.query_builder import Field
|
||||
from frappe.query_builder.functions import Concat_ws
|
||||
from frappe.tests.test_query_builder import db_type_is, run_only_if
|
||||
from frappe.utils import add_days, now, random_string
|
||||
from frappe.utils import add_days, now, random_string, cint
|
||||
from frappe.utils.testutils import clear_custom_fields
|
||||
|
||||
|
||||
|
|
@ -84,6 +84,27 @@ class TestDB(unittest.TestCase):
|
|||
),
|
||||
)
|
||||
|
||||
def test_get_value_limits(self):
|
||||
|
||||
# check both dict and list style filters
|
||||
filters = [{"enabled": 1}, [["enabled", "=", 1]]]
|
||||
for filter in filters:
|
||||
self.assertEqual(1, len(frappe.db.get_values("User", filters=filter, limit=1)))
|
||||
# count of last touched rows as per DB-API 2.0 https://peps.python.org/pep-0249/#rowcount
|
||||
self.assertGreaterEqual(1, cint(frappe.db._cursor.rowcount))
|
||||
self.assertEqual(2, len(frappe.db.get_values("User", filters=filter, limit=2)))
|
||||
self.assertGreaterEqual(2, cint(frappe.db._cursor.rowcount))
|
||||
|
||||
# without limits length == count
|
||||
self.assertEqual(len(frappe.db.get_values("User", filters=filter)),
|
||||
frappe.db.count("User", filter))
|
||||
|
||||
frappe.db.get_value("User", filters=filter)
|
||||
self.assertGreaterEqual(1, cint(frappe.db._cursor.rowcount))
|
||||
|
||||
frappe.db.exists("User", filter)
|
||||
self.assertGreaterEqual(1, cint(frappe.db._cursor.rowcount))
|
||||
|
||||
def test_escape(self):
|
||||
frappe.db.escape("香港濟生堂製藥有限公司 - IT".encode("utf-8"))
|
||||
|
||||
|
|
@ -301,6 +322,20 @@ class TestDB(unittest.TestCase):
|
|||
# recover transaction to continue other tests
|
||||
raise Exception
|
||||
|
||||
def test_exists(self):
|
||||
dt, dn = "User", "Administrator"
|
||||
self.assertEqual(frappe.db.exists(dt, dn, cache=True), dn)
|
||||
self.assertEqual(frappe.db.exists(dt, dn), dn)
|
||||
self.assertEqual(frappe.db.exists(dt, {"name": ("=", dn)}), dn)
|
||||
|
||||
filters = {"doctype": dt, "name": ("like", "Admin%")}
|
||||
self.assertEqual(frappe.db.exists(filters), dn)
|
||||
self.assertEqual(
|
||||
filters["doctype"], dt
|
||||
) # make sure that doctype was not removed from filters
|
||||
|
||||
self.assertEqual(frappe.db.exists(dt, [["name", "=", dn]]), dn)
|
||||
|
||||
|
||||
@run_only_if(db_type_is.MARIADB)
|
||||
class TestDDLCommandsMaria(unittest.TestCase):
|
||||
|
|
@ -357,7 +392,7 @@ class TestDDLCommandsMaria(unittest.TestCase):
|
|||
WHERE Key_name = '{index_name}';
|
||||
"""
|
||||
)
|
||||
self.assertEquals(len(indexs_in_table), 2)
|
||||
self.assertEqual(len(indexs_in_table), 2)
|
||||
|
||||
|
||||
class TestDBSetValue(unittest.TestCase):
|
||||
|
|
@ -561,4 +596,51 @@ class TestDDLCommandsPost(unittest.TestCase):
|
|||
AND indexname = '{index_name}' ;
|
||||
""",
|
||||
)
|
||||
self.assertEquals(len(indexs_in_table), 1)
|
||||
self.assertEqual(len(indexs_in_table), 1)
|
||||
|
||||
@run_only_if(db_type_is.POSTGRES)
|
||||
def test_modify_query(self):
|
||||
from frappe.database.postgres.database import modify_query
|
||||
|
||||
query = "select * from `tabtree b` where lft > 13 and rgt <= 16 and name =1.0 and parent = 4134qrsdc and isgroup = 1.00045"
|
||||
self.assertEqual(
|
||||
"select * from \"tabtree b\" where lft > \'13\' and rgt <= '16' and name = '1' and parent = 4134qrsdc and isgroup = 1.00045",
|
||||
modify_query(query)
|
||||
)
|
||||
|
||||
query = "select locate(\".io\", \"frappe.io\"), locate(\"3\", cast(3 as varchar)), locate(\"3\", 3::varchar)"
|
||||
self.assertEqual(
|
||||
"select strpos( \"frappe.io\", \".io\"), strpos( cast(3 as varchar), \"3\"), strpos( 3::varchar, \"3\")",
|
||||
modify_query(query)
|
||||
)
|
||||
|
||||
@run_only_if(db_type_is.POSTGRES)
|
||||
def test_modify_values(self):
|
||||
from frappe.database.postgres.database import modify_values
|
||||
|
||||
self.assertEqual(
|
||||
{"abcd": "23", "efgh": "23", "ijkl": 23.0345, "mnop": "wow"},
|
||||
modify_values({"abcd": 23, "efgh": 23.0, "ijkl": 23.0345, "mnop": "wow"})
|
||||
)
|
||||
self.assertEqual(
|
||||
["23", "23", 23.00004345, "wow"],
|
||||
modify_values((23, 23.0, 23.00004345, "wow"))
|
||||
)
|
||||
|
||||
def test_sequence_table_creation(self):
|
||||
from frappe.core.doctype.doctype.test_doctype import new_doctype
|
||||
|
||||
dt = new_doctype("autoinc_dt_seq_test", autoincremented=True).insert(ignore_permissions=True)
|
||||
|
||||
if frappe.db.db_type == "postgres":
|
||||
self.assertTrue(
|
||||
frappe.db.sql("""select sequence_name FROM information_schema.sequences
|
||||
where sequence_name ilike 'autoinc_dt_seq_test%'""")[0][0]
|
||||
)
|
||||
else:
|
||||
self.assertTrue(
|
||||
frappe.db.sql("""select data_type FROM information_schema.tables
|
||||
where table_type = 'SEQUENCE' and table_name like 'autoinc_dt_seq_test%'""")[0][0]
|
||||
)
|
||||
|
||||
dt.delete(ignore_permissions=True)
|
||||
|
|
|
|||
|
|
@ -494,6 +494,27 @@ class TestReportview(unittest.TestCase):
|
|||
response = execute_cmd("frappe.desk.reportview.get")
|
||||
self.assertListEqual(response["keys"], ["field_label", "field_name", "_aggregate_column", 'columns'])
|
||||
|
||||
def test_cast_name(self):
|
||||
from frappe.core.doctype.doctype.test_doctype import new_doctype
|
||||
|
||||
dt = new_doctype("autoinc_dt_test", autoincremented=True).insert(ignore_permissions=True)
|
||||
|
||||
query = DatabaseQuery("autoinc_dt_test").execute(
|
||||
fields=["locate('1', `tabautoinc_dt_test`.`name`)", "`tabautoinc_dt_test`.`name`"],
|
||||
filters={"name": 1},
|
||||
run=False
|
||||
)
|
||||
|
||||
if frappe.db.db_type == "postgres":
|
||||
self.assertTrue("strpos( cast( \"tabautoinc_dt_test\".\"name\" as varchar), \'1\')" in query)
|
||||
self.assertTrue("where cast(\"tabautoinc_dt_test\".name as varchar) = \'1\'" in query)
|
||||
else:
|
||||
self.assertTrue("locate(\'1\', `tabautoinc_dt_test`.`name`)" in query)
|
||||
self.assertTrue("where `tabautoinc_dt_test`.name = 1" in query)
|
||||
|
||||
dt.delete(ignore_permissions=True)
|
||||
|
||||
|
||||
def add_child_table_to_blog_post():
|
||||
child_table = frappe.get_doc({
|
||||
'doctype': 'DocType',
|
||||
|
|
|
|||
|
|
@ -260,15 +260,15 @@ class TestDocument(unittest.TestCase):
|
|||
'doctype': 'Test Formatted',
|
||||
'currency': 100000
|
||||
})
|
||||
self.assertEquals(d.get_formatted('currency', currency='INR', format="#,###.##"), '₹ 100,000.00')
|
||||
self.assertEqual(d.get_formatted('currency', currency='INR', format="#,###.##"), '₹ 100,000.00')
|
||||
|
||||
def test_limit_for_get(self):
|
||||
doc = frappe.get_doc("DocType", "DocType")
|
||||
# assuming DocType has more than 3 Data fields
|
||||
self.assertEquals(len(doc.get("fields", limit=3)), 3)
|
||||
self.assertEqual(len(doc.get("fields", limit=3)), 3)
|
||||
|
||||
# limit with filters
|
||||
self.assertEquals(len(doc.get("fields", filters={"fieldtype": "Data"}, limit=3)), 3)
|
||||
self.assertEqual(len(doc.get("fields", filters={"fieldtype": "Data"}, limit=3)), 3)
|
||||
|
||||
def test_virtual_fields(self):
|
||||
"""Virtual fields are accessible via API and Form views, whenever .as_dict is invoked
|
||||
|
|
|
|||
|
|
@ -168,8 +168,8 @@ class TestFormLoad(unittest.TestCase):
|
|||
"reference_name": note.name,
|
||||
}).insert()
|
||||
|
||||
|
||||
docinfo = get_docinfo(note)
|
||||
get_docinfo(note)
|
||||
docinfo = frappe.response["docinfo"]
|
||||
|
||||
self.assertEqual(len(docinfo.comments), 1)
|
||||
self.assertIn("test", docinfo.comments[0].content)
|
||||
|
|
|
|||
|
|
@ -245,6 +245,17 @@ class TestNaming(unittest.TestCase):
|
|||
})
|
||||
self.assertRaises(frappe.ValidationError, tag.insert)
|
||||
|
||||
def test_autoincremented_naming(self):
|
||||
from frappe.core.doctype.doctype.test_doctype import new_doctype
|
||||
|
||||
doctype = "autoinc_doctype" + frappe.generate_hash(length=5)
|
||||
dt = new_doctype(doctype, autoincremented=True).insert(ignore_permissions=True)
|
||||
|
||||
for i in range(1, 20):
|
||||
self.assertEqual(frappe.new_doc(doctype).save(ignore_permissions=True).name, i)
|
||||
|
||||
dt.delete(ignore_permissions=True)
|
||||
|
||||
|
||||
def make_invalid_todo():
|
||||
frappe.get_doc({
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import Callable
|
|||
|
||||
import frappe
|
||||
from frappe.query_builder.custom import ConstantColumn
|
||||
from frappe.query_builder.functions import Coalesce, GroupConcat, Match
|
||||
from frappe.query_builder.functions import Coalesce, GroupConcat, Match, CombineDatetime
|
||||
from frappe.query_builder.utils import db_type_is
|
||||
from frappe.query_builder import Case
|
||||
|
||||
|
|
@ -32,6 +32,27 @@ class TestCustomFunctionsMariaDB(unittest.TestCase):
|
|||
query.get_sql(), "SELECT `name`,'John' `User` FROM `tabDocType`"
|
||||
)
|
||||
|
||||
def test_timestamp(self):
|
||||
note = frappe.qb.DocType("Note")
|
||||
self.assertEqual("TIMESTAMP(posting_date,posting_time)", CombineDatetime(note.posting_date, note.posting_time).get_sql())
|
||||
self.assertEqual("TIMESTAMP('2021-01-01','00:00:21')", CombineDatetime("2021-01-01", "00:00:21").get_sql())
|
||||
|
||||
todo = frappe.qb.DocType("ToDo")
|
||||
select_query = (frappe.qb
|
||||
.from_(note)
|
||||
.join(todo).on(todo.refernce_name == note.name)
|
||||
.select(CombineDatetime(note.posting_date, note.posting_time)))
|
||||
self.assertIn("select timestamp(`tabnote`.`posting_date`,`tabnote`.`posting_time`)", str(select_query).lower())
|
||||
|
||||
select_query = select_query.orderby(CombineDatetime(note.posting_date, note.posting_time))
|
||||
self.assertIn("order by timestamp(`tabnote`.`posting_date`,`tabnote`.`posting_time`)", str(select_query).lower())
|
||||
|
||||
select_query = select_query.where(CombineDatetime(note.posting_date, note.posting_time) >= CombineDatetime("2021-01-01", "00:00:01"))
|
||||
self.assertIn("timestamp(`tabnote`.`posting_date`,`tabnote`.`posting_time`)>=timestamp('2021-01-01','00:00:01')", str(select_query).lower())
|
||||
|
||||
select_query = select_query.select(CombineDatetime(note.posting_date, note.posting_time, alias="timestamp"))
|
||||
self.assertIn("timestamp(`tabnote`.`posting_date`,`tabnote`.`posting_time`) `timestamp`", str(select_query).lower())
|
||||
|
||||
|
||||
@run_only_if(db_type_is.POSTGRES)
|
||||
class TestCustomFunctionsPostgres(unittest.TestCase):
|
||||
|
|
@ -52,6 +73,30 @@ class TestCustomFunctionsPostgres(unittest.TestCase):
|
|||
query.get_sql(), 'SELECT "name",\'John\' "User" FROM "tabDocType"'
|
||||
)
|
||||
|
||||
def test_timestamp(self):
|
||||
note = frappe.qb.DocType("Note")
|
||||
self.assertEqual("posting_date+posting_time", CombineDatetime(note.posting_date, note.posting_time).get_sql())
|
||||
self.assertEqual("CAST('2021-01-01' AS DATE)+CAST('00:00:21' AS TIME)", CombineDatetime("2021-01-01", "00:00:21").get_sql())
|
||||
|
||||
todo = frappe.qb.DocType("ToDo")
|
||||
select_query = (frappe.qb
|
||||
.from_(note)
|
||||
.join(todo).on(todo.refernce_name == note.name)
|
||||
.select(CombineDatetime(note.posting_date, note.posting_time)))
|
||||
self.assertIn('select "tabnote"."posting_date"+"tabnote"."posting_time"', str(select_query).lower())
|
||||
|
||||
select_query = select_query.orderby(CombineDatetime(note.posting_date, note.posting_time))
|
||||
self.assertIn('order by "tabnote"."posting_date"+"tabnote"."posting_time"', str(select_query).lower())
|
||||
|
||||
select_query = select_query.where(
|
||||
CombineDatetime(note.posting_date, note.posting_time) >= CombineDatetime('2021-01-01', '00:00:01')
|
||||
)
|
||||
self.assertIn("""where "tabnote"."posting_date"+"tabnote"."posting_time">=cast('2021-01-01' as date)+cast('00:00:01' as time)""",
|
||||
str(select_query).lower())
|
||||
|
||||
select_query = select_query.select(CombineDatetime(note.posting_date, note.posting_time, alias="timestamp"))
|
||||
self.assertIn('"tabnote"."posting_date"+"tabnote"."posting_time" "timestamp"', str(select_query).lower())
|
||||
|
||||
|
||||
class TestBuilderBase(object):
|
||||
def test_adding_tabs(self):
|
||||
|
|
|
|||
|
|
@ -12,37 +12,30 @@ class TestQueryReport(unittest.TestCase):
|
|||
def test_xlsx_data_with_multiple_datatypes(self):
|
||||
"""Test exporting report using rows with multiple datatypes (list, dict)"""
|
||||
|
||||
# Describe the columns
|
||||
columns = {
|
||||
0: {"label": "Column A", "fieldname": "column_a"},
|
||||
1: {"label": "Column B", "fieldname": "column_b"},
|
||||
2: {"label": "Column C", "fieldname": "column_c"}
|
||||
}
|
||||
|
||||
# Create mock data
|
||||
data = frappe._dict()
|
||||
data.columns = [
|
||||
{"label": "Column A", "fieldname": "column_a"},
|
||||
{"label": "Column B", "fieldname": "column_b", "width": 150},
|
||||
{"label": "Column C", "fieldname": "column_c", "width": 100}
|
||||
{"label": "Column A", "fieldname": "column_a", "fieldtype": "Float"},
|
||||
{"label": "Column B", "fieldname": "column_b", "width": 100, "fieldtype": "Float"},
|
||||
{"label": "Column C", "fieldname": "column_c", "width": 150, "fieldtype": "Duration"},
|
||||
]
|
||||
data.result = [
|
||||
[1.0, 3.0, 5.5],
|
||||
{"column_a": 22.1, "column_b": 21.8, "column_c": 30.2},
|
||||
{"column_b": 5.1, "column_c": 9.5, "column_a": 11.1},
|
||||
[3.0, 1.5, 7.5],
|
||||
[1.0, 3.0, 600],
|
||||
{"column_a": 22.1, "column_b": 21.8, "column_c": 86412},
|
||||
{"column_b": 5.1, "column_c": 53234, "column_a": 11.1},
|
||||
[3.0, 1.5, 333],
|
||||
]
|
||||
|
||||
# Define the visible rows
|
||||
visible_idx = [0, 2, 3]
|
||||
|
||||
# Build the result
|
||||
xlsx_data, column_widths = build_xlsx_data(columns, data, visible_idx, include_indentation=0)
|
||||
xlsx_data, column_widths = build_xlsx_data(data, visible_idx, include_indentation=0)
|
||||
|
||||
self.assertEqual(type(xlsx_data), list)
|
||||
self.assertEqual(len(xlsx_data), 4) # columns + data
|
||||
# column widths are divided by 10 to match the scale that is supported by openpyxl
|
||||
self.assertListEqual(column_widths, [0, 15, 10])
|
||||
self.assertListEqual(column_widths, [0, 10, 15])
|
||||
|
||||
for row in xlsx_data:
|
||||
self.assertEqual(type(row), list)
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue