2
0
mirror of https://github.com/frappe/books.git synced 2025-02-02 12:08:27 +00:00

fix: address issue, create filters

This commit is contained in:
18alantom 2022-05-18 22:25:24 +05:30
parent 37dc3e911f
commit ce87ff6802
13 changed files with 46 additions and 21 deletions

View File

@ -799,6 +799,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
static lists: ListsMap = {}; static lists: ListsMap = {};
static filters: FiltersMap = {}; static filters: FiltersMap = {};
static createFilters: FiltersMap = {}; // Used by the *Create* dropdown option
static defaults: DefaultMap = {}; static defaults: DefaultMap = {};
static emptyMessages: EmptyMessageMap = {}; static emptyMessages: EmptyMessageMap = {};

View File

@ -229,4 +229,10 @@ export abstract class Invoice extends Transactional {
}), }),
numberSeries: (doc: Doc) => ({ referenceType: doc.schemaName }), numberSeries: (doc: Doc) => ({ referenceType: doc.schemaName }),
}; };
static createFilters: FiltersMap = {
party: (doc: Doc) => ({
role: doc.isSales ? 'Customer' : 'Supplier',
}),
};
} }

View File

@ -115,4 +115,9 @@ export abstract class InvoiceItem extends Doc {
}; };
}, },
}; };
static createFilters: FiltersMap = {
item: (doc: Doc) => {
return { for: doc.isSales ? 'Sales' : 'Purchases' };
},
};
} }

View File

@ -89,19 +89,6 @@ export class Party extends Doc {
currency: { currency: {
formula: async () => this.fyo.singles.SystemSettings!.currency as string, formula: async () => this.fyo.singles.SystemSettings!.currency as string,
}, },
address: {
formula: async () => {
const address = this.address as string | undefined;
if (address) {
return (await this.fyo.getValue(
'Address',
address,
'addressDisplay'
)) as string;
}
return '';
},
},
}; };
validations: ValidationMap = { validations: ValidationMap = {

View File

@ -24,6 +24,7 @@
"label": "Party", "label": "Party",
"fieldtype": "Link", "fieldtype": "Link",
"target": "Party", "target": "Party",
"create": true,
"required": true "required": true
}, },
{ {
@ -31,6 +32,7 @@
"label": "Account", "label": "Account",
"fieldtype": "Link", "fieldtype": "Link",
"target": "Account", "target": "Account",
"create": true,
"required": true "required": true
}, },
{ {
@ -101,6 +103,7 @@
"label": "Number Series", "label": "Number Series",
"fieldtype": "Link", "fieldtype": "Link",
"target": "NumberSeries", "target": "NumberSeries",
"create": true,
"required": true, "required": true,
"default": "PINV-" "default": "PINV-"
} }

View File

@ -8,6 +8,7 @@
"label": "Item", "label": "Item",
"fieldtype": "Link", "fieldtype": "Link",
"target": "Item", "target": "Item",
"create": true,
"required": true "required": true
}, },
{ {
@ -40,6 +41,7 @@
"label": "Account", "label": "Account",
"fieldtype": "Link", "fieldtype": "Link",
"target": "Account", "target": "Account",
"create": true,
"required": true, "required": true,
"readOnly": true "readOnly": true
}, },
@ -47,6 +49,7 @@
"fieldname": "tax", "fieldname": "tax",
"label": "Tax", "label": "Tax",
"fieldtype": "Link", "fieldtype": "Link",
"create": true,
"target": "Tax" "target": "Tax"
}, },
{ {

View File

@ -23,6 +23,7 @@
"label": "Party", "label": "Party",
"fieldtype": "Link", "fieldtype": "Link",
"target": "Party", "target": "Party",
"create": true,
"required": true "required": true
}, },
{ {
@ -30,6 +31,7 @@
"label": "Account", "label": "Account",
"fieldtype": "Link", "fieldtype": "Link",
"target": "Account", "target": "Account",
"create": true,
"required": true "required": true
}, },
{ {
@ -100,6 +102,7 @@
"label": "Number Series", "label": "Number Series",
"fieldtype": "Link", "fieldtype": "Link",
"target": "NumberSeries", "target": "NumberSeries",
"create": true,
"required": true, "required": true,
"default": "SINV-" "default": "SINV-"
} }

View File

@ -8,6 +8,7 @@
"label": "Item", "label": "Item",
"fieldtype": "Link", "fieldtype": "Link",
"target": "Item", "target": "Item",
"create": true,
"required": true "required": true
}, },
{ {
@ -41,6 +42,7 @@
"hidden": true, "hidden": true,
"fieldtype": "Link", "fieldtype": "Link",
"target": "Account", "target": "Account",
"create": true,
"required": true, "required": true,
"readOnly": true "readOnly": true
}, },
@ -48,6 +50,7 @@
"fieldname": "tax", "fieldname": "tax",
"label": "Tax", "label": "Tax",
"fieldtype": "Link", "fieldtype": "Link",
"create": true,
"target": "Tax" "target": "Tax"
}, },
{ {

View File

@ -9,6 +9,7 @@
"label": "Tax Account", "label": "Tax Account",
"fieldtype": "Link", "fieldtype": "Link",
"target": "Account", "target": "Account",
"create": true,
"required": true "required": true
}, },
{ {

View File

@ -41,6 +41,7 @@
"fieldname": "defaultAccount", "fieldname": "defaultAccount",
"label": "Default Account", "label": "Default Account",
"fieldtype": "Link", "fieldtype": "Link",
"create": true,
"target": "Account" "target": "Account"
}, },
{ {

View File

@ -49,6 +49,7 @@ export interface OptionField extends BaseField {
export interface TargetField extends BaseField { export interface TargetField extends BaseField {
fieldtype: FieldTypeEnum.Table | FieldTypeEnum.Link; fieldtype: FieldTypeEnum.Table | FieldTypeEnum.Link;
target: string; // Name of the table or group of tables to fetch values target: string; // Name of the table or group of tables to fetch values
create?: boolean; // Whether to show Create in the dropdown
} }
export interface DynamicLinkField extends BaseField { export interface DynamicLinkField extends BaseField {

View File

@ -77,7 +77,7 @@ export default {
.map(({ item }) => item); .map(({ item }) => item);
} }
if (this.doc) { if (this.doc && this.df.create) {
options = options.concat(this.getCreateNewOption()); options = options.concat(this.getCreateNewOption());
} }
@ -119,7 +119,9 @@ export default {
async openNewDoc() { async openNewDoc() {
const schemaName = this.df.target; const schemaName = this.df.target;
const doc = await fyo.doc.getNewDoc(schemaName); const doc = await fyo.doc.getNewDoc(schemaName);
const filters = await this.getFilters();
const filters = await this.getCreateFilters();
const { openQuickEdit } = await import('src/utils/ui'); const { openQuickEdit } = await import('src/utils/ui');
openQuickEdit({ openQuickEdit({
@ -135,6 +137,17 @@ export default {
this.$router.back(); this.$router.back();
}); });
}, },
async getCreateFilters() {
const { schemaName, fieldname } = this.df;
const getFilters = fyo.models[schemaName]?.createFilters?.[fieldname];
const filters = await getFilters?.(this.doc);
if (filters === undefined) {
return await this.getFilters();
}
return filters;
},
async getFilters() { async getFilters() {
const { schemaName, fieldname } = this.df; const { schemaName, fieldname } = this.df;
const getFilters = fyo.models[schemaName]?.filters?.[fieldname]; const getFilters = fyo.models[schemaName]?.filters?.[fieldname];

View File

@ -36,7 +36,7 @@
<Button <Button
type="primary" type="primary"
class="w-1/2 text-white" class="w-1/2 text-white"
@click="saveInlineEditDoc" @click="saveInlineEditDoc(df)"
> >
{{ t`Save` }} {{ t`Save` }}
</Button> </Button>
@ -237,9 +237,6 @@ export default {
this.inlineEditField = df; this.inlineEditField = df;
if (!this.doc[df.fieldname]) { if (!this.doc[df.fieldname]) {
this.inlineEditDoc = await fyo.doc.getNewDoc(df.target); this.inlineEditDoc = await fyo.doc.getNewDoc(df.target);
this.inlineEditDoc.once('afterSync', async () => {
await this.onChangeCommon(df, this.inlineEditDoc.name);
});
} else { } else {
this.inlineEditDoc = this.doc.getLink(df.fieldname); this.inlineEditDoc = this.doc.getLink(df.fieldname);
} }
@ -251,12 +248,13 @@ export default {
fyo.getField(df.target, fieldname) fyo.getField(df.target, fieldname)
); );
}, },
async saveInlineEditDoc() { async saveInlineEditDoc(df) {
if (!this.inlineEditDoc) { if (!this.inlineEditDoc) {
return; return;
} }
await this.$refs.inlineEditForm[0].sync(); await this.inlineEditDoc.sync();
await this.onChangeCommon(df, this.inlineEditDoc.name);
await this.doc.loadLinks(); await this.doc.loadLinks();
if (this.emitChange) { if (this.emitChange) {