Commit graph

144 commits

Author SHA1 Message Date
Ritwik Puri
2e2c8316c6
fix: use sentinel value for checking existence of key in doc while parsing naming series (#20994) 2023-05-15 14:58:14 +05:30
Ritwik Puri
4bd32bcf04
fix: naming part should be empty if field is empty (#20978) 2023-05-14 00:41:12 +05:30
Ankush Menat
5348dd1f29 fix: Migration fails while inserting docfield
When migrating base doctypes we need to insert docfield which triggers
 document naming rule code and document naming rule doesn't yet exists
 cause that's what we are trying to migrate.

Fix: skip naming rule on bootstrapped doctypes.
2023-02-03 13:28:59 +05:30
Anand Baburajan
6554919f1e
fix: improve invalid naming series message (#19711)
* fix: show the invalid naming series in special chars error msg

* chore: translations

[skip ci]
2023-01-23 15:00:04 +05:30
Ankush Menat
f34f7030a3 refactor: remove txt param from generate_hash use 2022-11-10 11:56:48 +05:30
Daizy
78d30905ac refactor: get_doctype_map() using single query and use generator for caching 2022-11-02 09:58:34 +00:00
Daizy
28a124ca47 perf: cache document naming rule to avoid multiple db call 2022-11-02 09:58:34 +00:00
Ankush Menat
8cca50bf26
refactor: remove naming case feature (#18672)
This has never worked since 2016... which can mean two things:
- No one really uses this.
- If I fix this now suddenly people will find different behaviour in
  naming because `name_case` is selected in some doctypes (but never
  tested)
2022-10-31 11:23:49 +05:30
Anand Baburajan
feb198a019
docs: fix make_autoname example (#18354) 2022-10-10 21:04:35 +05:30
Ritwik Puri
66a31917f7
refactor(minor): reorder and remove unnecessary branches in set_new_name (#18243) 2022-09-29 16:23:55 +05:30
Ankush Menat
95f67b8de8
fix: ignore empty part in naming series (#17508)
on v13 doc.get("") returns entire doc dictionary, this gets strigified
and becomes a problem for naming.
2022-07-14 13:14:58 +05:30
Ankush Menat
111060224b fix: naming series tool doesn't load if missing numbers 2022-07-07 17:38:52 +05:30
Ankush Menat
60c4819373
refactor: safer binding of outer scope in closures (#17389) 2022-07-04 13:39:56 +05:30
Ankush Menat
81b37cb7d2
refactor: clean up code to py310 supported features (#17367)
refactor: clean up code to py39+ supported syntax

- f-strings instead of format
- latest typing support instead of pre 3.9 TitleCase
- remove UTF-8 declarations.
- many more changes

Powered by https://github.com/asottile/pyupgrade/ + manual cleanups
2022-07-01 11:51:05 +05:30
vishdha
27f2cdf016 chore: remove unused code 2022-06-17 13:59:21 +05:30
vishdha
ea18460cc2 fix: date_field not able to fetch in _format_naming autoname 2022-06-17 13:59:21 +05:30
Gavin D'souza
b696fa6da5 perf: Pre-compile and re-use regexp pattern
Converted all possible usages of re.* that weren't compiling the regex
separately and re-using it. Separated out the compiled patterns as
global variables. Repetitive patterns could be made DRY-er.

Would be nicer to have all regexes in a single module so that we could
re-use better, keep track of outdated, and keep checks for possible
reDos' etc
2022-06-08 14:07:38 +05:30
Ankush Menat
462aa20386
fix: naming using doc fields (#17040) 2022-05-31 19:55:34 +05:30
Ankush Menat
45604a7f3f refactor: move all naming series related logic 2022-05-31 14:48:14 +05:30
Ankush Menat
b7a032e7e8 refactor: generate naming series preview without DB calls 2022-05-31 12:59:49 +05:30
Ankush Menat
5590cb0be8 feat: NamingSeries class
Single class to group together everything required related to naming
series
2022-05-31 11:53:58 +05:30
Ankush Menat
5c35aae876 fix: accurate prefix parsing
Previous version of prefix parsing relied on partial reimplemntation of
naming series logic which was outdated and often incorrect.
2022-05-31 11:53:58 +05:30
Ankush Menat
15dbcacd56 refactor: split transaction and prefix functions
refactor: fetching transaction list

refactor: get default naming series

refactor: simplify naming series option scrubbing

fix: remove dead code related to insert series

This code is dead in many ways
- Creates map but it's never evaluated, so it doesn't actually run :D
- Just randomly splits naming series parts to create prefix... makes no
  sense.

fix: deduplicate prefix list
2022-05-31 11:53:40 +05:30
Ritwik Puri
b41379c78b
fix: misc fixes (integer primary keys) (#16307)
* fix: misc fixes

local.x gets resetted on every request so switched to a simple dict

simplified is_val_used in set_next_val function for sequences

* chore: use multisql for sequence methods

* fix: fields not updating on form

* minor(base_input): removed unnecessary branching in update_input

* chore: remove prints and rename autoincremented_status_map

* chore: added proper type hint + comment + formatting

* fix: added searching in cast_name rather than handling it manually

* fix: share condition query + test_build_match_conditions

* fix: add cast_name to more places

* test: test for sequence

* fix: sequence functions

* fix: inherit frappetestcase

* minor: attach sequence methods to db context local

* chore: update sequence function names in Database

use frappe.db for sequences in naming.py

* fix: convert filename to str (for autoincremented doctypes)

* chore: better regex for modifying values for postgres

* minor: allow changing name column type (if no data is present in the doctype)

* refactor: validate_autoname

converted it to a simple function
enabled changing autoincrement autoname from customize form

* fix: use sql_ddl for change_column_type in postgres

* fix: use not null constraint in postgres when changing name type

* fix(test): updated test_autoincremented_doctype_transition with transitioning when no data is present

* fix(test): updated test_cast_name

probably messed up during rebase

* fix(test): used rollback upon error in transaction for postgres

* chore: use frappe.db.x methods for sequences

* minor: use temporary sequences in test

* minor: use generate_hash for sequence naming in sequence tests

* chore: replace sequence imports with frappe.db.x

* chore: move out casting name fields to a separate method

* refactor: cast_name

more explicit cases for casts and added docstring

* fix: added space in test_cast_name

* chore: fix linter

* chore: better naming for can_change_name_column_type

* chore: add comment for autoincremented_site_status_map

* chore: update/add docstrings
2022-04-29 15:06:03 +05:30
Rushabh Mehta
fca6c3d305 fix(minor): circular imports? 2022-04-18 17:29:03 +05:30
Gavin D'souza
03d542edce fix!: Allow child table naming 2022-04-13 17:32:58 +05:30
Suraj Shetty
c0c5b2ebdd
style: format all python files using black (#16453)
Co-authored-by: Frappe Bot <developers@frappe.io>
2022-04-12 10:59:25 +05:30
phot0n
f21f526ae6 fix: sider 2022-03-15 16:49:33 +05:30
phot0n
86c9791813 fix: use next sequence number for ammended doc
* chore: use meta
2022-03-15 16:07:08 +05:30
phot0n
15ae019b12 fix: set_next_val function for sequences
postgres uses t & f, mariadb uses 0 & 1 for is_value_used
2022-03-11 23:46:01 +05:30
phot0n
93fbace331 fix: set next val of sequence when name is of int type in validate_name 2022-03-11 23:46:01 +05:30
phot0n
b876520ef0 fix: logic for is_autoincremented 2022-03-11 23:46:00 +05:30
phot0n
bebc8058b6 feat: integer primary keys 2022-03-11 23:46:00 +05:30
Gavin D'souza
953560af35 chore: Add type hints for rename_doc module
* Easier debugging ffs :crie:
2022-02-18 17:56:42 +05:30
Mohammad Hasnain Mohsin Rajan
4ff86e1d63
revert: "refactor: set amended docname to original docname" (#15867)
* Revert: "refactor: set amended docname to original docname"

80d111baf2.

* test: test if amended doc has different name
2022-02-04 17:22:18 +05:30
Daniel Gerhardt
16dca0b1c1 feat: add consecutive calendar week (WW) for naming series
The calendar week is based on ISO 8601 but behaves slightly different
for the first and last days of a year to ensure consecutiveness:

* If the first days of a year would be in week 53 then 00 is used
  instead.
* if the last days of a year would be in week 01 then 53 is used
  instead.

Closes #14413
2021-11-18 17:52:36 +01:00
Gavin D'souza
e989bfa41d style: Indents & file headers 2021-11-03 16:12:27 +05:30
Aradhya-Tripathi
cd9e0ffa84 refactor: converted queries in nameing and nestedset 2021-10-26 22:20:03 +05:30
Rushabh Mehta
20dea90670 feat(minor): Packages! also cleanup of DocField and other minor fixes 2021-09-05 22:01:55 +05:30
Gavin D'souza
3446026555 chore: Update header: license.txt => LICENSE
The license.txt file has been replaced with LICENSE for quite a while
now. INAL but it didn't seem accurate to say "hey, checkout license.txt
although there's no such file". Apart from this, there were
inconsistencies in the headers altogether...this change brings
consistency.
2021-09-03 12:02:59 +05:30
leela
80d111baf2 refactor: set amended docname to original docname
Currently, whenever a document is amended it's name is set
to name-X(X is a counter) when amended again and so on. In this PR,
we have postfixed all cancelled document names with '-CAN' and new
cancelled documents gets a name as original_name-CANC-X.
so that amended docs can use the original name instead of name-X.
2021-08-09 14:59:07 +05:30
leela
b719e1481d Revert "refactor: set amended docname to original docname"
This reverts commit d459847ae3.
2021-07-28 17:00:12 +05:30
leela
d459847ae3 refactor: set amended docname to original docname
Currently, whenever a document is amended it's name is set
to name-X(X is a counter) when amended again and so on. In this PR,
we have changed all cancelled doc patterns to name-CAN-X,
so that amended docs can use the original name instead of name-X.
2021-07-21 10:51:32 +05:30
leela
f31d01a2a6 Revert "Merge pull request #13244 from prssanna/amended-doc-naming"
This reverts commit 58b95662c2, reversing
changes made to c553b7e23a.
2021-07-02 17:43:16 +05:30
Leela vadlamudi
4800ee8725
Merge branch 'develop' into amended-doc-naming 2021-07-02 10:47:47 +05:30
Gavin D'souza
e407b78506 chore: Drop dead and deprecated code
* Remove six for PY2 compatability since our dependencies are not, PY2
  is legacy.
* Removed usages of utils from future/past libraries since they are
  deprecated. This includes 'from __future__ ...' and 'from past...'
  statements.
* Removed compatibility imports for PY2, switched from six imports to
  standard library imports.
* Removed utils code blocks that handle operations depending on PY2/3
  versions.
* Removed 'from __future__ ...' lines from templates/code generators
* Used PY3 syntaxes in place of PY2 compatible blocks. eg: metaclass
2021-05-26 15:31:29 +05:30
prssanna
304a771ba2 fix: check if doc has attribute amended_from 2021-05-17 17:13:48 +05:30
prssanna
1c4e1bc1df refactor: set amended docname to original docname 2021-05-17 17:12:28 +05:30
Joseph Marie Alba
c795a70897
Python 3 issue in re
Python 3 interprets string literals as Unicode strings, and therefore \d is treated as an escaped Unicode character.

Declare RegEx pattern as a raw string instead by prepending r or double escape \d
2021-05-16 05:52:05 +08:00
shariquerik
9919ddff2a fix: sider fix 2021-05-10 12:56:15 +05:30