2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 19:09:01 +00:00

fix: allow account creation from tax

- prevent random strings when manual naming
- set naming
This commit is contained in:
18alantom 2022-09-15 14:23:13 +05:30
parent af6f953b11
commit 7023ce2171
12 changed files with 44 additions and 5 deletions

View File

@ -291,6 +291,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
this[field.fieldname] = defaultValue;
}
}
async remove(fieldname: string, idx: number) {
const childDocs = ((this[fieldname] ?? []) as Doc[]).filter(
(row, i) => row.idx !== idx || i !== idx
@ -318,8 +319,25 @@ export class Doc extends Observable<DocValue | Doc[]> {
this[fieldname] = childDocs;
}
_setChildDocsParent() {
for (const { fieldname } of this.tableFields) {
const value = this.get(fieldname);
if (!Array.isArray(value)) {
continue;
}
for (const childDoc of value) {
if (childDoc.parent) {
continue;
}
childDoc.parent = this.name;
}
}
}
_getChildDoc(docValueMap: Doc | DocValueMap, fieldname: string): Doc {
if (!this.name) {
if (!this.name && this.schema.naming !== 'manual') {
this.name = getRandomString();
}
@ -672,6 +690,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
async _preSync() {
this._setChildDocsIdx();
this._setChildDocsParent();
await this._applyFormula();
await this._validateSync();
await this.trigger('validate');

View File

@ -4,6 +4,7 @@ import {
DefaultMap,
FiltersMap,
ListViewSettings,
RequiredMap,
TreeViewSettings,
} from 'fyo/model/types';
import { QueryFilter } from 'utils/db/types';
@ -26,6 +27,16 @@ export class Account extends Doc {
return !this.isDebit;
}
required: RequiredMap = {
/**
* Added here cause rootAccounts don't have parents
* they are created during initialization. if this is
* added to the schema it will cause NOT NULL errors
*/
parentAccount: () => true,
};
static defaults: DefaultMap = {
/**
* NestedSet indices are actually not used

View File

@ -1,6 +1,7 @@
{
"name": "Account",
"label": "Account",
"naming": "manual",
"isSingle": false,
"isTree": true,
"fields": [
@ -37,14 +38,13 @@
"label": "Expense"
}
],
"readOnly": true
"required": true
},
{
"fieldname": "parentAccount",
"label": "Parent Account",
"fieldtype": "Link",
"target": "Account",
"readOnly": true
"target": "Account"
},
{
"fieldname": "accountType",
@ -140,7 +140,7 @@
"fieldname": "isGroup",
"label": "Is Group",
"fieldtype": "Check",
"readOnly": true
"default": false
}
],
"quickEditFields": [

View File

@ -1,6 +1,7 @@
{
"name": "Color",
"label": "Color",
"naming": "manual",
"fields": [
{
"fieldname": "name",

View File

@ -1,6 +1,7 @@
{
"name": "Currency",
"label": "Currency",
"naming": "manual",
"isSingle": false,
"fields": [
{

View File

@ -1,6 +1,7 @@
{
"label": "Journal Entry",
"name": "JournalEntry",
"naming": "numberSeries",
"isSubmittable": true,
"fields": [
{

View File

@ -1,6 +1,7 @@
{
"name": "NumberSeries",
"label": "Number Series",
"naming": "manual",
"isSingle": false,
"isChild": false,
"fields": [

View File

@ -1,6 +1,7 @@
{
"name": "Payment",
"label": "Payment",
"naming": "numberSeries",
"isSingle": false,
"isChild": false,
"isSubmittable": true,

View File

@ -1,6 +1,7 @@
{
"name": "PurchaseInvoice",
"label": "Purchase Invoice",
"naming": "numberSeries",
"isSingle": false,
"isChild": false,
"isSubmittable": true,

View File

@ -1,6 +1,7 @@
{
"name": "SalesInvoice",
"label": "Sales Invoice",
"naming": "numberSeries",
"isSingle": false,
"isChild": false,
"isSubmittable": true,

View File

@ -1,6 +1,7 @@
{
"name": "Tax",
"label": "Tax",
"naming": "manual",
"isSingle": false,
"isChild": false,
"fields": [

View File

@ -1,6 +1,7 @@
{
"name": "PatchRun",
"label": "Patch Run",
"naming": "manual",
"fields": [
{
"fieldname": "name",