mirror of
https://github.com/frappe/books.git
synced 2025-03-31 23:41:32 +00:00
fix: Print View sync issue
- hide multi currency fields cause widget is sufficient - exchange rate update issue
This commit is contained in:
parent
a8e8225ad6
commit
2007e4339d
@ -20,6 +20,7 @@ import { isPesa } from '../utils/index';
|
|||||||
import { getDbSyncError } from './errorHelpers';
|
import { getDbSyncError } from './errorHelpers';
|
||||||
import {
|
import {
|
||||||
areDocValuesEqual,
|
areDocValuesEqual,
|
||||||
|
getFormulaSequence,
|
||||||
getMissingMandatoryMessage,
|
getMissingMandatoryMessage,
|
||||||
getPreDefaultValues,
|
getPreDefaultValues,
|
||||||
setChildDocIdx,
|
setChildDocIdx,
|
||||||
@ -815,9 +816,9 @@ export class Doc extends Observable<DocValue | Doc[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _applyFormulaForFields(doc: Doc, fieldname?: string) {
|
async _applyFormulaForFields(doc: Doc, fieldname?: string) {
|
||||||
const formulaFields = this.schema.fields.filter(
|
const formulaFields = getFormulaSequence(this.formulas)
|
||||||
({ fieldname }) => this.formulas?.[fieldname]
|
.map((f) => this.fyo.getField(this.schemaName, f))
|
||||||
);
|
.filter(Boolean);
|
||||||
|
|
||||||
let changed = false;
|
let changed = false;
|
||||||
for (const field of formulaFields) {
|
for (const field of formulaFields) {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { Fyo } from 'fyo';
|
import { Fyo } from 'fyo';
|
||||||
import { DocValue } from 'fyo/core/types';
|
import { DocValue } from 'fyo/core/types';
|
||||||
import { isPesa } from 'fyo/utils';
|
import { isPesa } from 'fyo/utils';
|
||||||
import { isEqual } from 'lodash';
|
import { cloneDeep, isEqual } from 'lodash';
|
||||||
import { Money } from 'pesa';
|
|
||||||
import { Field, FieldType, FieldTypeEnum } from 'schemas/types';
|
import { Field, FieldType, FieldTypeEnum } from 'schemas/types';
|
||||||
import { getIsNullOrUndef } from 'utils';
|
import { getIsNullOrUndef } from 'utils';
|
||||||
import { Doc } from './doc';
|
import { Doc } from './doc';
|
||||||
|
import { FormulaMap } from './types';
|
||||||
|
|
||||||
export function areDocValuesEqual(
|
export function areDocValuesEqual(
|
||||||
dvOne: DocValue | Doc[],
|
dvOne: DocValue | Doc[],
|
||||||
@ -149,3 +149,42 @@ export function setChildDocIdx(childDocs: Doc[]) {
|
|||||||
childDocs[idx].idx = +idx;
|
childDocs[idx].idx = +idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getFormulaSequence(formulas: FormulaMap) {
|
||||||
|
const depMap = Object.keys(formulas).reduce((acc, k) => {
|
||||||
|
acc[k] = formulas[k]?.dependsOn;
|
||||||
|
return acc;
|
||||||
|
}, {} as Record<string, string[] | undefined>);
|
||||||
|
return sequenceDependencies(cloneDeep(depMap));
|
||||||
|
}
|
||||||
|
|
||||||
|
function sequenceDependencies(
|
||||||
|
depMap: Record<string, string[] | undefined>
|
||||||
|
): string[] {
|
||||||
|
/**
|
||||||
|
* Sufficiently okay algo to sequence dependents after
|
||||||
|
* their dependencies
|
||||||
|
*/
|
||||||
|
const keys = Object.keys(depMap);
|
||||||
|
|
||||||
|
const independent = keys.filter((k) => !depMap[k]?.length);
|
||||||
|
const dependent = keys.filter((k) => depMap[k]?.length);
|
||||||
|
|
||||||
|
const keyset = new Set(independent);
|
||||||
|
|
||||||
|
for (const k of dependent) {
|
||||||
|
const deps = depMap[k] ?? [];
|
||||||
|
deps.push(k);
|
||||||
|
|
||||||
|
while (deps.length) {
|
||||||
|
const d = deps.shift()!;
|
||||||
|
if (keyset.has(d)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyset.add(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(keyset).filter((k) => k in depMap);
|
||||||
|
}
|
||||||
|
@ -384,6 +384,7 @@ export abstract class Invoice extends Transactional {
|
|||||||
|
|
||||||
return await this.getExchangeRate();
|
return await this.getExchangeRate();
|
||||||
},
|
},
|
||||||
|
dependsOn: ['party', 'currency'],
|
||||||
},
|
},
|
||||||
netTotal: { formula: async () => this.getSum('items', 'amount', false) },
|
netTotal: { formula: async () => this.getSum('items', 'amount', false) },
|
||||||
taxes: { formula: async () => await this.getTaxSummary() },
|
taxes: { formula: async () => await this.getTaxSummary() },
|
||||||
@ -391,6 +392,7 @@ export abstract class Invoice extends Transactional {
|
|||||||
baseGrandTotal: {
|
baseGrandTotal: {
|
||||||
formula: async () =>
|
formula: async () =>
|
||||||
(this.grandTotal as Money).mul(this.exchangeRate! ?? 1),
|
(this.grandTotal as Money).mul(this.exchangeRate! ?? 1),
|
||||||
|
dependsOn: ['grandTotal', 'exchangeRate'],
|
||||||
},
|
},
|
||||||
outstandingAmount: {
|
outstandingAmount: {
|
||||||
formula: async () => {
|
formula: async () => {
|
||||||
@ -471,9 +473,6 @@ export abstract class Invoice extends Transactional {
|
|||||||
baseGrandTotal: () =>
|
baseGrandTotal: () =>
|
||||||
this.exchangeRate === 1 || this.baseGrandTotal!.isZero(),
|
this.exchangeRate === 1 || this.baseGrandTotal!.isZero(),
|
||||||
grandTotal: () => !this.taxes?.length,
|
grandTotal: () => !this.taxes?.length,
|
||||||
entryCurrency: () => !this.isMultiCurrency,
|
|
||||||
currency: () => !this.isMultiCurrency,
|
|
||||||
exchangeRate: () => !this.isMultiCurrency,
|
|
||||||
stockNotTransferred: () => !this.stockNotTransferred,
|
stockNotTransferred: () => !this.stockNotTransferred,
|
||||||
outstandingAmount: () =>
|
outstandingAmount: () =>
|
||||||
!!this.outstandingAmount?.isZero() || !this.isSubmitted,
|
!!this.outstandingAmount?.isZero() || !this.isSubmitted,
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"target": "Currency",
|
"target": "Currency",
|
||||||
"readOnly": true,
|
"readOnly": true,
|
||||||
"tab": "Settings"
|
"hidden": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "exchangeRate",
|
"fieldname": "exchangeRate",
|
||||||
@ -129,7 +129,7 @@
|
|||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"default": 1,
|
"default": 1,
|
||||||
"readOnly": true,
|
"readOnly": true,
|
||||||
"tab": "Settings"
|
"hidden": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "discountAfterTax",
|
"fieldname": "discountAfterTax",
|
||||||
|
@ -91,21 +91,20 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
this.doc = await fyo.doc.getDoc(this.schemaName, this.name);
|
await this.initialize();
|
||||||
await this.setTemplateList();
|
|
||||||
if (fyo.store.isDevelopment) {
|
if (fyo.store.isDevelopment) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.pv = this;
|
window.pv = this;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
await this.setTemplateFromDefault();
|
async activated() {
|
||||||
if (!this.templateDoc && this.templateList.length) {
|
await this.initialize();
|
||||||
await this.onTemplateNameChange(this.templateList[0]);
|
},
|
||||||
}
|
unmounted() {
|
||||||
|
this.reset();
|
||||||
if (this.doc) {
|
},
|
||||||
this.values = await getPrintTemplatePropValues(this.doc as Doc);
|
deactivated() {
|
||||||
}
|
this.reset();
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
helperMessage() {
|
helperMessage() {
|
||||||
@ -191,6 +190,24 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async initialize() {
|
||||||
|
this.doc = await fyo.doc.getDoc(this.schemaName, this.name);
|
||||||
|
await this.setTemplateList();
|
||||||
|
await this.setTemplateFromDefault();
|
||||||
|
if (!this.templateDoc && this.templateList.length) {
|
||||||
|
await this.onTemplateNameChange(this.templateList[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.doc) {
|
||||||
|
this.values = await getPrintTemplatePropValues(this.doc as Doc);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
reset() {
|
||||||
|
this.doc = null;
|
||||||
|
this.values = null;
|
||||||
|
this.templateList = [];
|
||||||
|
this.templateDoc = null;
|
||||||
|
},
|
||||||
async onTemplateNameChange(value: string | null): Promise<void> {
|
async onTemplateNameChange(value: string | null): Promise<void> {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
this.templateDoc = null;
|
this.templateDoc = null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user