Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display discount amounts in shipment doc #1143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions models/inventory/StockTransferItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Money } from 'pesa';
import { safeParseFloat } from 'utils/index';
import { StockTransfer } from './StockTransfer';
import { TransferItem } from './TransferItem';
import { SalesInvoice } from 'models/baseModels/SalesInvoice/SalesInvoice';

export class StockTransferItem extends TransferItem {
item?: string;
Expand Down Expand Up @@ -42,6 +43,32 @@ export class StockTransferItem extends TransferItem {
return !!this.parentdoc?.isReturn;
}

async getItemDiscountAmount(): Promise<Money | undefined> {
const sinvDoc = (await this.fyo.doc.getDoc(
ModelNameEnum.SalesInvoice,
this.parentdoc?.backReference
)) as SalesInvoice;

const discountAmount = sinvDoc?.items?.find(
(val) => val.item === this.item
)?.itemDiscountAmount;

return discountAmount;
}

async getItemDiscountPercent() {
const sinvDoc = (await this.fyo.doc.getDoc(
ModelNameEnum.SalesInvoice,
this.parentdoc?.backReference
)) as SalesInvoice;

const discountPercent = sinvDoc?.items?.find(
(val) => val.item === this.item
)?.itemDiscountPercent;

return discountPercent;
}

formulas: FormulaMap = {
description: {
formula: async () =>
Expand Down Expand Up @@ -158,6 +185,16 @@ export class StockTransferItem extends TransferItem {
},
dependsOn: ['rate', 'quantity'],
},
itemDiscountAmount: {
formula: async () => {
return await this.getItemDiscountAmount();
},
dependsOn: ['items'],
},
itemDiscountPercent: {
formula: () => this.getItemDiscountPercent(),
dependsOn: ['items'],
},
rate: {
formula: async () => {
const rate = (await this.fyo.getValue(
Expand Down
16 changes: 15 additions & 1 deletion schemas/app/inventory/StockTransferItem.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
"fieldtype": "Currency",
"readOnly": true
},
{
"fieldname": "itemDiscountAmount",
"label": "Discount Amount",
"fieldtype": "Currency",
"readOnly": false
},
{
"fieldname": "itemDiscountPercent",
"label": "Discount Percent",
"fieldtype": "Float",
"readOnly": false
},
{
"fieldname": "description",
"label": "Description",
Expand Down Expand Up @@ -107,6 +119,8 @@
"hsnCode",
"location",
"rate",
"amount"
"amount",
"itemDiscountAmount",
"itemDiscountPercent"
]
}
2 changes: 1 addition & 1 deletion src/pages/POS/PaymentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export default defineComponent({
}

if (amount) {
this.$emit('setPaidAmount', this.sinvDoc.outstandingAmount?.float);
this.$emit('setPaidAmount', this.sinvDoc.grandTotal?.float);
}
},
async setPaymentMethods() {
Expand Down