mirror of
https://github.com/frappe/books.git
synced 2024-12-22 19:09:01 +00:00
fix: apply pricing rule
This commit is contained in:
parent
e1f334113e
commit
ede6f3f69f
@ -275,9 +275,6 @@ import { SalesInvoiceItem } from 'models/baseModels/SalesInvoiceItem/SalesInvoic
|
||||
import { Money } from 'pesa';
|
||||
import { DiscountType } from '../types';
|
||||
import { validateSerialNumberCount } from 'src/utils/pos';
|
||||
import { getPricingRule } from 'models/helpers';
|
||||
import { SalesInvoice } from 'models/baseModels/SalesInvoice/SalesInvoice';
|
||||
import { ApplicablePricingRules } from 'models/baseModels/Invoice/types';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'SelectedItemRow',
|
||||
@ -285,7 +282,7 @@ export default defineComponent({
|
||||
props: {
|
||||
row: { type: SalesInvoiceItem, required: true },
|
||||
},
|
||||
emits: ['runSinvFormulas', 'setItemSerialNumbers', 'addItem'],
|
||||
emits: ['runSinvFormulas', 'applyPricingRule'],
|
||||
setup() {
|
||||
return {
|
||||
isDiscountingEnabled: inject('isDiscountingEnabled') as boolean,
|
||||
@ -363,7 +360,7 @@ export default defineComponent({
|
||||
this.row.set('quantity', quantity);
|
||||
|
||||
if (!this.row.isFreeItem) {
|
||||
await this.updatePricingRuleItem();
|
||||
this.$emit('applyPricingRule');
|
||||
this.$emit('runSinvFormulas');
|
||||
}
|
||||
},
|
||||
@ -371,22 +368,7 @@ export default defineComponent({
|
||||
this.row.parentdoc?.remove('items', row?.idx as number);
|
||||
|
||||
if (!row.isFreeItem) {
|
||||
await this.updatePricingRuleItem();
|
||||
}
|
||||
},
|
||||
async updatePricingRuleItem() {
|
||||
const pricingRule = (await getPricingRule(
|
||||
this.row.parentdoc as SalesInvoice
|
||||
)) as ApplicablePricingRules[];
|
||||
|
||||
let appliedPricingRuleCount =
|
||||
this.row.parentdoc?.pricingRuleDetail?.length;
|
||||
|
||||
if (appliedPricingRuleCount !== pricingRule?.length) {
|
||||
appliedPricingRuleCount = pricingRule?.length;
|
||||
|
||||
await this.row.parentdoc?.appendPricingRuleDetail(pricingRule);
|
||||
await this.row.parentdoc?.applyProductDiscount();
|
||||
this.$emit('applyPricingRule');
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@ -54,6 +54,7 @@
|
||||
<SelectedItemRow
|
||||
:row="(row as SalesInvoiceItem)"
|
||||
@run-sinv-formulas="runSinvFormulas"
|
||||
@apply-pricing-rule="$emit('applyPricingRule')"
|
||||
/>
|
||||
</Row>
|
||||
</div>
|
||||
@ -93,6 +94,7 @@ export default defineComponent({
|
||||
isExapanded: false,
|
||||
};
|
||||
},
|
||||
emits: ['applyPricingRule'],
|
||||
computed: {
|
||||
ratio() {
|
||||
return [0.1, 1, 0.8, 0.8, 0.8, 0.8, 0.2];
|
||||
|
@ -248,8 +248,6 @@ import { defineComponent } from 'vue';
|
||||
import { SalesInvoiceItem } from 'models/baseModels/SalesInvoiceItem/SalesInvoiceItem';
|
||||
import { Money } from 'pesa';
|
||||
import { validateSerialNumberCount } from 'src/utils/pos';
|
||||
import { updatePricingRuleItem } from 'models/helpers';
|
||||
import { SalesInvoice } from 'models/baseModels/SalesInvoice/SalesInvoice';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ModernPOSSelectedItemRow',
|
||||
@ -257,7 +255,7 @@ export default defineComponent({
|
||||
props: {
|
||||
row: { type: SalesInvoiceItem, required: true },
|
||||
},
|
||||
emits: ['toggleModal', 'runSinvFormulas', 'selectedRow'],
|
||||
emits: ['toggleModal', 'runSinvFormulas', 'selectedRow', 'applyPricingRule'],
|
||||
|
||||
setup() {
|
||||
return {
|
||||
@ -331,7 +329,7 @@ export default defineComponent({
|
||||
this.row.parentdoc?.remove('items', row?.idx as number);
|
||||
|
||||
if (!row.isFreeItem) {
|
||||
await updatePricingRuleItem(this.row.parentdoc as SalesInvoice);
|
||||
this.$emit('applyPricingRule');
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@ -82,7 +82,7 @@ export default defineComponent({
|
||||
isExapanded: false,
|
||||
};
|
||||
},
|
||||
emits: ['toggleModal', 'selectedRow'],
|
||||
emits: ['toggleModal', 'selectedRow', 'applyPricingRule'],
|
||||
computed: {
|
||||
ratio() {
|
||||
return [0.1, 0.8, 0.4, 0.8, 0.8, 0.3];
|
||||
@ -141,6 +141,9 @@ export default defineComponent({
|
||||
selectedItemRow(row: SalesInvoiceItem, field: string) {
|
||||
this.$emit('selectedRow', row, field);
|
||||
},
|
||||
emitApplyPricingRule() {
|
||||
this.$emit('applyPricingRule');
|
||||
},
|
||||
isNumeric,
|
||||
},
|
||||
});
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
<CouponCodeModal
|
||||
:open-modal="openCouponCodeModal"
|
||||
@apply-pricing-rule="emitEvent('applyPricingRule')"
|
||||
@toggle-modal="emitEvent('toggleModal', 'CouponCode')"
|
||||
@set-coupons-count="(count) => emitEvent('setCouponsCount', count)"
|
||||
/>
|
||||
@ -39,7 +40,6 @@
|
||||
@toggle-modal="emitEvent('toggleModal', 'Payment')"
|
||||
@set-cash-amount="(amount) => emitEvent('setCashAmount', amount)"
|
||||
@set-transfer-ref-no="(ref) => emitEvent('setTransferRefNo', ref)"
|
||||
@set-coupons-count="(count) => emitEvent('setCouponsCount', count)"
|
||||
@set-transfer-amount="(amount) => emitEvent('setTransferAmount', amount)"
|
||||
@set-transfer-clearance-date="
|
||||
(date) => emitEvent('setTransferClearanceDate', date)
|
||||
@ -153,7 +153,9 @@
|
||||
@change="(value:string) => $emit('setCustomer',value)"
|
||||
/>
|
||||
|
||||
<SelectedItemTable />
|
||||
<SelectedItemTable
|
||||
@apply-pricing-rule="emitEvent('applyPricingRule')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
@ -385,6 +387,7 @@ export default defineComponent({
|
||||
'routeToSinvList',
|
||||
'setTransferRefNo',
|
||||
'setLoyaltyPoints',
|
||||
'applyPricingRule',
|
||||
'saveInvoiceAction',
|
||||
'createTransaction',
|
||||
'setTransferAmount',
|
||||
|
@ -12,7 +12,7 @@
|
||||
:style="{ height: appliedCoupons.length >= 2 ? '11vh' : '8vh' }"
|
||||
>
|
||||
<Row
|
||||
v-for="(coupon,index) in appliedCoupons as any"
|
||||
v-for="(coupon,index) in appliedCoupons as AppliedCouponCodes[]"
|
||||
:key="index"
|
||||
:ratio="ratio"
|
||||
:border="true"
|
||||
@ -115,10 +115,11 @@ import { showToast } from 'src/utils/interactive';
|
||||
import { AppliedCouponCodes } from 'models/baseModels/AppliedCouponCodes/AppliedCouponCodes';
|
||||
import Link from 'src/components/Controls/Link.vue';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { updatePricingRule, validateCouponCode } from 'models/helpers';
|
||||
import { validateCouponCode } from 'models/helpers';
|
||||
import { Field } from 'schemas/types';
|
||||
import FormControl from 'src/components/Controls/FormControl.vue';
|
||||
import Row from 'src/components/Row.vue';
|
||||
import { InvoiceItem } from 'models/baseModels/InvoiceItem/InvoiceItem';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'CouponCodeModal',
|
||||
@ -129,7 +130,7 @@ export default defineComponent({
|
||||
FormControl,
|
||||
Row,
|
||||
},
|
||||
emits: ['setCouponsCount', 'toggleModal'],
|
||||
emits: ['setCouponsCount', 'toggleModal', 'applyPricingRule'],
|
||||
|
||||
setup() {
|
||||
return {
|
||||
@ -181,13 +182,11 @@ export default defineComponent({
|
||||
|
||||
await this.sinvDoc.append('coupons', { coupons: this.couponCode });
|
||||
|
||||
await updatePricingRule(this.sinvDoc);
|
||||
this.$emit('applyPricingRule');
|
||||
this.$emit('toggleModal', 'CouponCode');
|
||||
|
||||
this.couponCode = '';
|
||||
this.validationError = false;
|
||||
|
||||
this.$emit('setCouponsCount', this.sinvDoc.coupons?.length);
|
||||
} catch (error) {
|
||||
this.validationError = true;
|
||||
|
||||
@ -198,12 +197,16 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
async removeAppliedCoupon(coupon: AppliedCouponCodes) {
|
||||
this.sinvDoc.coupons = this.sinvDoc.coupons?.filter(
|
||||
(coup) => coup.coupons !== coupon?.coupons
|
||||
);
|
||||
this.sinvDoc?.items?.map((item: InvoiceItem) => {
|
||||
item.itemDiscountAmount = this.fyo.pesa(0);
|
||||
item.itemDiscountPercent = 0;
|
||||
item.setItemDiscountAmount = false;
|
||||
});
|
||||
|
||||
await updatePricingRule(this.sinvDoc);
|
||||
this.$emit('setCouponsCount', this.sinvDoc.coupons?.length);
|
||||
await coupon?.parentdoc?.remove('coupons', coupon.idx as number);
|
||||
|
||||
this.$emit('applyPricingRule');
|
||||
this.$emit('setCouponsCount', this.coupons?.length);
|
||||
},
|
||||
cancelApplyCouponCode() {
|
||||
this.couponCode = '';
|
||||
|
@ -316,7 +316,6 @@ import { defineComponent, inject } from 'vue';
|
||||
import Button from 'src/components/Button.vue';
|
||||
import Float from 'src/components/Controls/Float.vue';
|
||||
import Currency from 'src/components/Controls/Currency.vue';
|
||||
import { updatePricingRuleItem } from 'models/helpers';
|
||||
import { SalesInvoice } from 'models/baseModels/SalesInvoice/SalesInvoice';
|
||||
import { SalesInvoiceItem } from 'models/baseModels/SalesInvoiceItem/SalesInvoiceItem';
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
@ -338,7 +337,7 @@ export default defineComponent({
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
emits: ['toggleModal'],
|
||||
emits: ['toggleModal', 'applyPricingRule'],
|
||||
setup() {
|
||||
return {
|
||||
sinvDoc: inject('sinvDoc') as SalesInvoice,
|
||||
@ -460,7 +459,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
if (this.selectedItemField === 'quantity') {
|
||||
await updatePricingRuleItem(this.sinvDoc);
|
||||
this.$emit('applyPricingRule');
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,6 +470,10 @@ export default defineComponent({
|
||||
type: 'error',
|
||||
message: this.t`${error as string}`,
|
||||
});
|
||||
|
||||
if (this.selectedItemField === 'quantity') {
|
||||
this.$emit('applyPricingRule');
|
||||
}
|
||||
}
|
||||
},
|
||||
async deleteLast() {
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
<CouponCodeModal
|
||||
:open-modal="openCouponCodeModal"
|
||||
@apply-pricing-rule="emitEvent('applyPricingRule')"
|
||||
@toggle-modal="emitEvent('toggleModal', 'CouponCode')"
|
||||
@set-coupons-count="(count) => emitEvent('setCouponsCount', count)"
|
||||
/>
|
||||
@ -39,7 +40,6 @@
|
||||
@toggle-modal="emitEvent('toggleModal', 'Payment')"
|
||||
@set-cash-amount="(amount) => emitEvent('setCashAmount', amount)"
|
||||
@set-transfer-ref-no="(ref) => emitEvent('setTransferRefNo', ref)"
|
||||
@set-coupons-count="(count) => emitEvent('setCouponsCount', count)"
|
||||
@set-transfer-amount="(amount) => emitEvent('setTransferAmount', amount)"
|
||||
@set-transfer-clearance-date="
|
||||
(date) => emitEvent('setTransferClearanceDate', date)
|
||||
@ -61,6 +61,7 @@
|
||||
:selected-item-field="selectedItemField"
|
||||
:selected-item-row="(selectedItemRow as SalesInvoiceItem)"
|
||||
@toggle-modal="emitEvent('toggleModal', 'Keyboard')"
|
||||
@apply-pricing-rule="emitEvent('applyPricingRule')"
|
||||
/>
|
||||
|
||||
<div class="bg-gray-25 dark:bg-gray-875 grid grid-cols-9 gap-3 p-4">
|
||||
@ -91,6 +92,7 @@
|
||||
|
||||
<ModernPOSSelectedItemTable
|
||||
@selected-row="selectedRow"
|
||||
@apply-pricing-rule="emitEvent('applyPricingRule')"
|
||||
@toggle-modal="emitEvent('toggleModal', 'Keyboard')"
|
||||
/>
|
||||
</div>
|
||||
@ -397,6 +399,7 @@ export default defineComponent({
|
||||
'routeToSinvList',
|
||||
'setLoyaltyPoints',
|
||||
'setTransferRefNo',
|
||||
'applyPricingRule',
|
||||
'saveInvoiceAction',
|
||||
'createTransaction',
|
||||
'setTransferAmount',
|
||||
|
@ -43,6 +43,7 @@
|
||||
@route-to-sinv-list="routeToSinvList"
|
||||
@set-loyalty-points="setLoyaltyPoints"
|
||||
@set-transfer-ref-no="setTransferRefNo"
|
||||
@apply-pricing-rule="applyPricingRule"
|
||||
@create-transaction="createTransaction"
|
||||
@save-invoice-action="saveInvoiceAction"
|
||||
@set-transfer-amount="setTransferAmount"
|
||||
@ -81,6 +82,7 @@
|
||||
@set-cash-amount="setCashAmount"
|
||||
@set-coupons-count="setCouponsCount"
|
||||
@route-to-sinv-list="routeToSinvList"
|
||||
@apply-pricing-rule="applyPricingRule"
|
||||
@set-loyalty-points="setLoyaltyPoints"
|
||||
@set-transfer-ref-no="setTransferRefNo"
|
||||
@create-transaction="createTransaction"
|
||||
@ -215,6 +217,10 @@ export default defineComponent({
|
||||
watch: {
|
||||
sinvDoc: {
|
||||
handler() {
|
||||
if (this.sinvDoc.coupons?.length) {
|
||||
this.setCouponsCount(this.sinvDoc.coupons?.length);
|
||||
}
|
||||
|
||||
this.updateValues();
|
||||
},
|
||||
deep: true,
|
||||
@ -617,26 +623,12 @@ export default defineComponent({
|
||||
this.sinvDoc.isPricingRuleApplied = false;
|
||||
removeFreeItems(this.sinvDoc as SalesInvoice);
|
||||
|
||||
await this.sinvDoc.applyProductDiscount();
|
||||
return;
|
||||
}
|
||||
|
||||
const appliedPricingRuleCount = this.sinvDoc?.items?.filter(
|
||||
(val) => val.isFreeItem
|
||||
).length;
|
||||
|
||||
const recursivePricingRules = hasPricingRules?.filter(
|
||||
(val) => val.pricingRule.isRecursive
|
||||
);
|
||||
|
||||
setTimeout(async () => {
|
||||
if (
|
||||
appliedPricingRuleCount !== hasPricingRules?.length ||
|
||||
recursivePricingRules
|
||||
) {
|
||||
await this.sinvDoc.appendPricingRuleDetail(hasPricingRules);
|
||||
await this.sinvDoc.applyProductDiscount();
|
||||
}
|
||||
}, 1);
|
||||
},
|
||||
async routeToSinvList() {
|
||||
if (!this.sinvDoc.items?.length) {
|
||||
|
@ -224,7 +224,6 @@ export default defineComponent({
|
||||
'setTransferClearanceDate',
|
||||
'setTransferRefNo',
|
||||
'toggleModal',
|
||||
'setCouponsCount',
|
||||
],
|
||||
setup() {
|
||||
return {
|
||||
@ -323,7 +322,6 @@ export default defineComponent({
|
||||
},
|
||||
submitTransaction() {
|
||||
this.$emit('createTransaction');
|
||||
this.$emit('setCouponsCount', 0);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user