fix: improve payment validation and apply minor fixes

This commit is contained in:
suhailanzar
2025-06-05 12:36:36 +05:30
parent 81333cd487
commit 40166d011e
4 changed files with 27 additions and 9 deletions
+16 -7
View File
@@ -42,6 +42,7 @@ export class Payment extends Transactional {
referenceType?: ModelNameEnum.SalesInvoice | ModelNameEnum.PurchaseInvoice;
for?: PaymentFor[];
_accountsMap?: AccountTypeMap;
initialAmount?: Money;
async paymentMethodDoc() {
return (await this.loadAndGetLink('paymentMethod')) as PaymentMethod;
@@ -703,17 +704,25 @@ export class Payment extends Transactional {
return;
}
const amount = (this.getSum('for', 'amount', false) as Money).abs();
if (!this.initialAmount) {
this.initialAmount = this.amount as Money;
}
if ((value as Money).gt(amount)) {
const moneyValue = value as Money;
if (moneyValue.gt(this.initialAmount)) {
throw new ValidationError(
this.fyo.t`Payment amount cannot
exceed ${this.fyo.format(amount, 'Currency')}.`
this.fyo.t`Payment amount cannot exceed ${this.fyo.format(
this.initialAmount,
'Currency'
)}.`
);
} else if ((value as Money).isZero()) {
} else if (moneyValue.isZero()) {
throw new ValidationError(
this.fyo.t`Payment amount cannot
be ${this.fyo.format(value, 'Currency')}.`
this.fyo.t`Payment amount cannot be ${this.fyo.format(
moneyValue,
'Currency'
)}.`
);
}
},
+2 -1
View File
@@ -141,7 +141,8 @@ export class PricingRule extends Doc {
hidden: HiddenMap = {
location: () => !this.fyo.singles.AccountingSettings?.enableInventory,
isCouponCodeBased: () =>
!this.fyo.singles.AccountingSettings?.enableCouponCode,
priceDiscountType: () => !this.isDiscountTypeIsPriceDiscount,
discountRate: () =>
!this.isDiscountTypeIsPriceDiscount || this.priceDiscountType !== 'rate',
+2 -1
View File
@@ -289,7 +289,8 @@ export function getMakeReturnDocAction(fyo: Fyo): Action {
!doc.isReturn &&
(!!fyo.singles.AccountingSettings?.enableInvoiceReturns ||
!!fyo.singles.InventorySettings?.enableStockReturns) &&
doc.isSubmitted,
doc.isSubmitted &&
!doc.isReturn,
action: async (doc: Doc) => {
let returnDoc: Invoice | StockTransfer | undefined;
+7
View File
@@ -42,6 +42,13 @@
"required": true,
"section": "Default"
},
{
"fieldname": "terms",
"label": "Notes",
"placeholder": "Add quote terms",
"fieldtype": "Text",
"section": "References"
},
{
"fieldname": "items",
"label": "Items",