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:
parent
37dc3e911f
commit
ce87ff6802
@ -799,6 +799,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
|
||||
|
||||
static lists: ListsMap = {};
|
||||
static filters: FiltersMap = {};
|
||||
static createFilters: FiltersMap = {}; // Used by the *Create* dropdown option
|
||||
static defaults: DefaultMap = {};
|
||||
static emptyMessages: EmptyMessageMap = {};
|
||||
|
||||
|
@ -229,4 +229,10 @@ export abstract class Invoice extends Transactional {
|
||||
}),
|
||||
numberSeries: (doc: Doc) => ({ referenceType: doc.schemaName }),
|
||||
};
|
||||
|
||||
static createFilters: FiltersMap = {
|
||||
party: (doc: Doc) => ({
|
||||
role: doc.isSales ? 'Customer' : 'Supplier',
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
@ -115,4 +115,9 @@ export abstract class InvoiceItem extends Doc {
|
||||
};
|
||||
},
|
||||
};
|
||||
static createFilters: FiltersMap = {
|
||||
item: (doc: Doc) => {
|
||||
return { for: doc.isSales ? 'Sales' : 'Purchases' };
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -89,19 +89,6 @@ export class Party extends Doc {
|
||||
currency: {
|
||||
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 = {
|
||||
|
@ -24,6 +24,7 @@
|
||||
"label": "Party",
|
||||
"fieldtype": "Link",
|
||||
"target": "Party",
|
||||
"create": true,
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
@ -31,6 +32,7 @@
|
||||
"label": "Account",
|
||||
"fieldtype": "Link",
|
||||
"target": "Account",
|
||||
"create": true,
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
@ -101,6 +103,7 @@
|
||||
"label": "Number Series",
|
||||
"fieldtype": "Link",
|
||||
"target": "NumberSeries",
|
||||
"create": true,
|
||||
"required": true,
|
||||
"default": "PINV-"
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
"label": "Item",
|
||||
"fieldtype": "Link",
|
||||
"target": "Item",
|
||||
"create": true,
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
@ -40,6 +41,7 @@
|
||||
"label": "Account",
|
||||
"fieldtype": "Link",
|
||||
"target": "Account",
|
||||
"create": true,
|
||||
"required": true,
|
||||
"readOnly": true
|
||||
},
|
||||
@ -47,6 +49,7 @@
|
||||
"fieldname": "tax",
|
||||
"label": "Tax",
|
||||
"fieldtype": "Link",
|
||||
"create": true,
|
||||
"target": "Tax"
|
||||
},
|
||||
{
|
||||
|
@ -23,6 +23,7 @@
|
||||
"label": "Party",
|
||||
"fieldtype": "Link",
|
||||
"target": "Party",
|
||||
"create": true,
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
@ -30,6 +31,7 @@
|
||||
"label": "Account",
|
||||
"fieldtype": "Link",
|
||||
"target": "Account",
|
||||
"create": true,
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
@ -100,6 +102,7 @@
|
||||
"label": "Number Series",
|
||||
"fieldtype": "Link",
|
||||
"target": "NumberSeries",
|
||||
"create": true,
|
||||
"required": true,
|
||||
"default": "SINV-"
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
"label": "Item",
|
||||
"fieldtype": "Link",
|
||||
"target": "Item",
|
||||
"create": true,
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
@ -41,6 +42,7 @@
|
||||
"hidden": true,
|
||||
"fieldtype": "Link",
|
||||
"target": "Account",
|
||||
"create": true,
|
||||
"required": true,
|
||||
"readOnly": true
|
||||
},
|
||||
@ -48,6 +50,7 @@
|
||||
"fieldname": "tax",
|
||||
"label": "Tax",
|
||||
"fieldtype": "Link",
|
||||
"create": true,
|
||||
"target": "Tax"
|
||||
},
|
||||
{
|
||||
|
@ -9,6 +9,7 @@
|
||||
"label": "Tax Account",
|
||||
"fieldtype": "Link",
|
||||
"target": "Account",
|
||||
"create": true,
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
|
@ -41,6 +41,7 @@
|
||||
"fieldname": "defaultAccount",
|
||||
"label": "Default Account",
|
||||
"fieldtype": "Link",
|
||||
"create": true,
|
||||
"target": "Account"
|
||||
},
|
||||
{
|
||||
|
@ -49,6 +49,7 @@ export interface OptionField extends BaseField {
|
||||
export interface TargetField extends BaseField {
|
||||
fieldtype: FieldTypeEnum.Table | FieldTypeEnum.Link;
|
||||
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 {
|
||||
|
@ -77,7 +77,7 @@ export default {
|
||||
.map(({ item }) => item);
|
||||
}
|
||||
|
||||
if (this.doc) {
|
||||
if (this.doc && this.df.create) {
|
||||
options = options.concat(this.getCreateNewOption());
|
||||
}
|
||||
|
||||
@ -119,7 +119,9 @@ export default {
|
||||
async openNewDoc() {
|
||||
const schemaName = this.df.target;
|
||||
const doc = await fyo.doc.getNewDoc(schemaName);
|
||||
const filters = await this.getFilters();
|
||||
|
||||
const filters = await this.getCreateFilters();
|
||||
|
||||
const { openQuickEdit } = await import('src/utils/ui');
|
||||
|
||||
openQuickEdit({
|
||||
@ -135,6 +137,17 @@ export default {
|
||||
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() {
|
||||
const { schemaName, fieldname } = this.df;
|
||||
const getFilters = fyo.models[schemaName]?.filters?.[fieldname];
|
||||
|
@ -36,7 +36,7 @@
|
||||
<Button
|
||||
type="primary"
|
||||
class="w-1/2 text-white"
|
||||
@click="saveInlineEditDoc"
|
||||
@click="saveInlineEditDoc(df)"
|
||||
>
|
||||
{{ t`Save` }}
|
||||
</Button>
|
||||
@ -237,9 +237,6 @@ export default {
|
||||
this.inlineEditField = df;
|
||||
if (!this.doc[df.fieldname]) {
|
||||
this.inlineEditDoc = await fyo.doc.getNewDoc(df.target);
|
||||
this.inlineEditDoc.once('afterSync', async () => {
|
||||
await this.onChangeCommon(df, this.inlineEditDoc.name);
|
||||
});
|
||||
} else {
|
||||
this.inlineEditDoc = this.doc.getLink(df.fieldname);
|
||||
}
|
||||
@ -251,12 +248,13 @@ export default {
|
||||
fyo.getField(df.target, fieldname)
|
||||
);
|
||||
},
|
||||
async saveInlineEditDoc() {
|
||||
async saveInlineEditDoc(df) {
|
||||
if (!this.inlineEditDoc) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.$refs.inlineEditForm[0].sync();
|
||||
await this.inlineEditDoc.sync();
|
||||
await this.onChangeCommon(df, this.inlineEditDoc.name);
|
||||
await this.doc.loadLinks();
|
||||
|
||||
if (this.emitChange) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user