mirror of
https://github.com/frappe/books.git
synced 2025-01-22 22:58:28 +00:00
fix(ux): allow setting of Stock Transfer backref
This commit is contained in:
parent
7e2305b855
commit
0ce9507a4a
@ -3,6 +3,7 @@ import { Attachment } from 'fyo/core/types';
|
|||||||
import { Doc } from 'fyo/model/doc';
|
import { Doc } from 'fyo/model/doc';
|
||||||
import {
|
import {
|
||||||
Action,
|
Action,
|
||||||
|
ChangeArg,
|
||||||
DefaultMap,
|
DefaultMap,
|
||||||
FiltersMap,
|
FiltersMap,
|
||||||
FormulaMap,
|
FormulaMap,
|
||||||
@ -15,6 +16,7 @@ import { addItem, getLedgerLinkAction, getNumberSeries } from 'models/helpers';
|
|||||||
import { LedgerPosting } from 'models/Transactional/LedgerPosting';
|
import { LedgerPosting } from 'models/Transactional/LedgerPosting';
|
||||||
import { ModelNameEnum } from 'models/types';
|
import { ModelNameEnum } from 'models/types';
|
||||||
import { Money } from 'pesa';
|
import { Money } from 'pesa';
|
||||||
|
import { TargetField } from 'schemas/types';
|
||||||
import { validateBatch } from './helpers';
|
import { validateBatch } from './helpers';
|
||||||
import { StockTransferItem } from './StockTransferItem';
|
import { StockTransferItem } from './StockTransferItem';
|
||||||
import { Transfer } from './Transfer';
|
import { Transfer } from './Transfer';
|
||||||
@ -66,6 +68,11 @@ export abstract class StockTransfer extends Transfer {
|
|||||||
role: ['in', [doc.isSales ? 'Customer' : 'Supplier', 'Both']],
|
role: ['in', [doc.isSales ? 'Customer' : 'Supplier', 'Both']],
|
||||||
}),
|
}),
|
||||||
numberSeries: (doc: Doc) => ({ referenceType: doc.schemaName }),
|
numberSeries: (doc: Doc) => ({ referenceType: doc.schemaName }),
|
||||||
|
backReference: () => ({
|
||||||
|
stockNotTransferred: true,
|
||||||
|
submitted: true,
|
||||||
|
cancelled: false,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
override _getTransferDetails() {
|
override _getTransferDetails() {
|
||||||
@ -257,4 +264,37 @@ export abstract class StockTransfer extends Transfer {
|
|||||||
async addItem(name: string) {
|
async addItem(name: string) {
|
||||||
return await addItem(name, this);
|
return await addItem(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override async change({ doc, changed }: ChangeArg): Promise<void> {
|
||||||
|
if (doc.name === this.name && changed === 'backReference') {
|
||||||
|
await this.setFieldsFromBackReference();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async setFieldsFromBackReference() {
|
||||||
|
const backReference = this.backReference;
|
||||||
|
const { target } = this.fyo.getField(
|
||||||
|
this.schemaName,
|
||||||
|
'backReference'
|
||||||
|
) as TargetField;
|
||||||
|
|
||||||
|
if (!backReference || !target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const brDoc = await this.fyo.doc.getDoc(target, backReference);
|
||||||
|
if (!(brDoc instanceof Invoice)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const stDoc = await brDoc.getStockTransfer();
|
||||||
|
if (!stDoc) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.set('party', stDoc.party);
|
||||||
|
await this.set('terms', stDoc.terms);
|
||||||
|
await this.set('date', stDoc.date);
|
||||||
|
await this.set('items', stDoc.items);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
"label": "Back Reference",
|
"label": "Back Reference",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"target": "PurchaseInvoice",
|
"target": "PurchaseInvoice",
|
||||||
"readOnly": true,
|
|
||||||
"section": "References"
|
"section": "References"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
"label": "Back Reference",
|
"label": "Back Reference",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"target": "SalesInvoice",
|
"target": "SalesInvoice",
|
||||||
"readOnly": true,
|
|
||||||
"section": "References"
|
"section": "References"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user