mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
feat: pricing rule models
This commit is contained in:
parent
6f3152187a
commit
3346a733f3
96
models/baseModels/PricingRule/PricingRule.ts
Normal file
96
models/baseModels/PricingRule/PricingRule.ts
Normal file
@ -0,0 +1,96 @@
|
||||
import { Doc } from 'fyo/model/doc';
|
||||
import { Money } from 'pesa';
|
||||
import { PricingRuleItem } from '../PricingRuleItem/PricingRuleItem';
|
||||
import { getIsDocEnabledColumn } from 'models/helpers';
|
||||
import {
|
||||
FiltersMap,
|
||||
FormulaMap,
|
||||
HiddenMap,
|
||||
ListViewSettings,
|
||||
RequiredMap,
|
||||
ValidationMap,
|
||||
} from 'fyo/model/types';
|
||||
|
||||
export class PricingRule extends Doc {
|
||||
isEnabled?: boolean;
|
||||
title?: string;
|
||||
appliedItems?: PricingRuleItem[];
|
||||
discountType?: 'Price Discount' | 'Product Discount';
|
||||
|
||||
priceDiscountType?: 'rate' | 'percentage' | 'amount';
|
||||
discountRate?: Money;
|
||||
discountPercentage?: number;
|
||||
discountAmount?: Money;
|
||||
|
||||
forPriceList?: string;
|
||||
|
||||
freeItem?: string;
|
||||
freeItemQuantity?: number;
|
||||
freeItemUnit?: string;
|
||||
freeItemRate?: Money;
|
||||
roundFreeItemQty?: number;
|
||||
roundingMethod?: string;
|
||||
|
||||
isRecursive?: boolean;
|
||||
recurseEvery?: number;
|
||||
recurseOver?: number;
|
||||
|
||||
minQuantity?: number;
|
||||
maxQuantity?: number;
|
||||
|
||||
minAmount?: Money;
|
||||
maxAmount?: Money;
|
||||
|
||||
validFrom?: Date;
|
||||
validTo?: Date;
|
||||
|
||||
thresholdForSuggestion?: number;
|
||||
priority?: number;
|
||||
|
||||
get isDiscountTypeIsPriceDiscount() {
|
||||
return this.discountType === 'Price Discount';
|
||||
}
|
||||
|
||||
formulas: FormulaMap = {};
|
||||
|
||||
validations: ValidationMap = {};
|
||||
|
||||
required: RequiredMap = {
|
||||
priceDiscountType: () => this.isDiscountTypeIsPriceDiscount,
|
||||
};
|
||||
|
||||
static getListViewSettings(): ListViewSettings {
|
||||
return {
|
||||
columns: ['name', 'title', getIsDocEnabledColumn(), 'discountType'],
|
||||
};
|
||||
}
|
||||
|
||||
hidden: HiddenMap = {
|
||||
location: () => !this.fyo.singles.AccountingSettings?.enableInventory,
|
||||
|
||||
priceDiscountType: () => !this.isDiscountTypeIsPriceDiscount,
|
||||
discountRate: () =>
|
||||
!this.isDiscountTypeIsPriceDiscount || this.priceDiscountType !== 'rate',
|
||||
discountPercentage: () =>
|
||||
!this.isDiscountTypeIsPriceDiscount ||
|
||||
this.priceDiscountType !== 'percentage',
|
||||
discountAmount: () =>
|
||||
!this.isDiscountTypeIsPriceDiscount ||
|
||||
this.priceDiscountType !== 'amount',
|
||||
forPriceList: () =>
|
||||
!this.isDiscountTypeIsPriceDiscount || this.priceDiscountType === 'rate',
|
||||
|
||||
freeItem: () => this.isDiscountTypeIsPriceDiscount,
|
||||
freeItemQuantity: () => this.isDiscountTypeIsPriceDiscount,
|
||||
freeItemUnit: () => this.isDiscountTypeIsPriceDiscount,
|
||||
freeItemRate: () => this.isDiscountTypeIsPriceDiscount,
|
||||
roundFreeItemQty: () => this.isDiscountTypeIsPriceDiscount,
|
||||
roundingMethod: () =>
|
||||
this.isDiscountTypeIsPriceDiscount || !this.roundFreeItemQty,
|
||||
isRecursive: () => this.isDiscountTypeIsPriceDiscount,
|
||||
recurseEvery: () => this.isDiscountTypeIsPriceDiscount || !this.isRecursive,
|
||||
recurseOver: () => this.isDiscountTypeIsPriceDiscount || !this.isRecursive,
|
||||
};
|
||||
|
||||
static filters: FiltersMap = {};
|
||||
}
|
5
models/baseModels/PricingRuleDetail/PricingRuleDetail.ts
Normal file
5
models/baseModels/PricingRuleDetail/PricingRuleDetail.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { Doc } from 'fyo/model/doc';
|
||||
|
||||
export class PricingRuleDetail extends Doc {
|
||||
referenceName?: string;
|
||||
}
|
19
models/baseModels/PricingRuleItem/PricingRuleItem.ts
Normal file
19
models/baseModels/PricingRuleItem/PricingRuleItem.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Doc } from 'fyo/model/doc';
|
||||
import { FormulaMap } from 'fyo/model/types';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
|
||||
export class PricingRuleItem extends Doc {
|
||||
item?: string;
|
||||
unit?: string;
|
||||
|
||||
formulas: FormulaMap = {
|
||||
unit: {
|
||||
formula: () => {
|
||||
if (!this.item) {
|
||||
return;
|
||||
}
|
||||
return this.fyo.getValue(ModelNameEnum.Item, this.item, 'unit');
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user