mirror of
https://github.com/frappe/books.git
synced 2026-08-24 10:04:45 -05:00
fix: improve payment validation and apply minor fixes
This commit is contained in:
@@ -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'
|
||||
)}.`
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
|
||||
@@ -42,6 +42,13 @@
|
||||
"required": true,
|
||||
"section": "Default"
|
||||
},
|
||||
{
|
||||
"fieldname": "terms",
|
||||
"label": "Notes",
|
||||
"placeholder": "Add quote terms",
|
||||
"fieldtype": "Text",
|
||||
"section": "References"
|
||||
},
|
||||
{
|
||||
"fieldname": "items",
|
||||
"label": "Items",
|
||||
|
||||
Reference in New Issue
Block a user