mirror of
https://github.com/frappe/books.git
synced 2024-11-09 15:20:56 +00:00
fix: ItemPrice -> PriceListItem
- update and remove fields
This commit is contained in:
parent
bed66cb67a
commit
7d10951316
@ -1,60 +0,0 @@
|
||||
import { t } from 'fyo';
|
||||
import { DocValue } from 'fyo/core/types';
|
||||
import { Doc } from 'fyo/model/doc';
|
||||
import { ValidationMap } from 'fyo/model/types';
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
import { getItemPrice } from 'models/helpers';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { Money } from 'pesa';
|
||||
|
||||
export class ItemPrice extends Doc {
|
||||
item?: string;
|
||||
rate?: Money;
|
||||
validFrom?: Date;
|
||||
validUpto?: Date;
|
||||
|
||||
get isBuying() {
|
||||
return !!this.parentdoc?.buying;
|
||||
}
|
||||
|
||||
get isSelling() {
|
||||
return !!this.parentdoc?.selling;
|
||||
}
|
||||
|
||||
get priceList() {
|
||||
return this.parentdoc?.name;
|
||||
}
|
||||
|
||||
validations: ValidationMap = {
|
||||
validUpto: async (value: DocValue) => {
|
||||
if (!value || !this.validFrom) {
|
||||
return;
|
||||
}
|
||||
if (value < this.validFrom) {
|
||||
throw new ValidationError(
|
||||
t`Valid From date can not be greater than Valid To date.`
|
||||
);
|
||||
}
|
||||
|
||||
const itemPrice = await getItemPrice(
|
||||
this,
|
||||
this.validFrom,
|
||||
this.validUpto
|
||||
);
|
||||
|
||||
if (!itemPrice) {
|
||||
return;
|
||||
}
|
||||
|
||||
const priceList = (await this.fyo.getValue(
|
||||
ModelNameEnum.ItemPrice,
|
||||
itemPrice,
|
||||
'parent'
|
||||
)) as string;
|
||||
|
||||
throw new ValidationError(
|
||||
t`an Item Price already exists for the given date in Price List ${priceList}`
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
@ -1,14 +1,13 @@
|
||||
import { Doc } from 'fyo/model/doc';
|
||||
import { ListViewSettings } from 'fyo/model/types';
|
||||
import { ItemPrice } from '../ItemPrice/ItemPrice';
|
||||
import { PriceListItem } from './PriceListItem';
|
||||
import { getPriceListEnabledColumn, getPriceListStatusColumn } from 'models/helpers';
|
||||
|
||||
export class PriceList extends Doc {
|
||||
enabled?: boolean;
|
||||
buying?: boolean;
|
||||
selling?: boolean;
|
||||
isUomDependent?: boolean;
|
||||
priceListItem?: ItemPrice[];
|
||||
isEnabled?: boolean;
|
||||
isSales?: boolean;
|
||||
isPurchase?: boolean;
|
||||
priceListItem?: PriceListItem[];
|
||||
|
||||
static getListViewSettings(): ListViewSettings {
|
||||
return {
|
||||
|
37
models/baseModels/PriceList/PriceListItem.ts
Normal file
37
models/baseModels/PriceList/PriceListItem.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { Doc } from 'fyo/model/doc';
|
||||
import { FormulaMap } from 'fyo/model/types';
|
||||
import { Money } from 'pesa';
|
||||
import type { PriceList } from './PriceList';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
|
||||
export class PriceListItem extends Doc {
|
||||
item?: string;
|
||||
unit?: string;
|
||||
rate?: Money;
|
||||
parentdoc?: PriceList;
|
||||
|
||||
get isBuying() {
|
||||
return !!this.parentdoc?.buying;
|
||||
}
|
||||
|
||||
get isSelling() {
|
||||
return !!this.parentdoc?.selling;
|
||||
}
|
||||
|
||||
get priceList() {
|
||||
return this.parentdoc?.name;
|
||||
}
|
||||
|
||||
formulas: FormulaMap = {
|
||||
unit: {
|
||||
formula: async () => {
|
||||
if (!this.item) {
|
||||
return;
|
||||
}
|
||||
|
||||
return await this.fyo.getValue(ModelNameEnum.Item, this.item, 'unit');
|
||||
},
|
||||
dependsOn: ['item'],
|
||||
},
|
||||
};
|
||||
}
|
@ -11,7 +11,7 @@ import { Party } from './baseModels/Party/Party';
|
||||
import { Payment } from './baseModels/Payment/Payment';
|
||||
import { PaymentFor } from './baseModels/PaymentFor/PaymentFor';
|
||||
import { PriceList } from './baseModels/PriceList/PriceList';
|
||||
import { ItemPrice } from './baseModels/ItemPrice/ItemPrice';
|
||||
import { PriceListItem } from './baseModels/PriceList/PriceListItem';
|
||||
import { PrintSettings } from './baseModels/PrintSettings/PrintSettings';
|
||||
import { PurchaseInvoice } from './baseModels/PurchaseInvoice/PurchaseInvoice';
|
||||
import { PurchaseInvoiceItem } from './baseModels/PurchaseInvoiceItem/PurchaseInvoiceItem';
|
||||
@ -21,11 +21,11 @@ import { SetupWizard } from './baseModels/SetupWizard/SetupWizard';
|
||||
import { Tax } from './baseModels/Tax/Tax';
|
||||
import { TaxSummary } from './baseModels/TaxSummary/TaxSummary';
|
||||
import { Batch } from './inventory/Batch';
|
||||
import { SerialNumber } from './inventory/SerialNumber';
|
||||
import { InventorySettings } from './inventory/InventorySettings';
|
||||
import { Location } from './inventory/Location';
|
||||
import { PurchaseReceipt } from './inventory/PurchaseReceipt';
|
||||
import { PurchaseReceiptItem } from './inventory/PurchaseReceiptItem';
|
||||
import { SerialNumber } from './inventory/SerialNumber';
|
||||
import { Shipment } from './inventory/Shipment';
|
||||
import { ShipmentItem } from './inventory/ShipmentItem';
|
||||
import { StockLedgerEntry } from './inventory/StockLedgerEntry';
|
||||
@ -48,7 +48,7 @@ export const models = {
|
||||
PaymentFor,
|
||||
PrintSettings,
|
||||
PriceList,
|
||||
ItemPrice,
|
||||
PriceListItem,
|
||||
PurchaseInvoice,
|
||||
PurchaseInvoiceItem,
|
||||
SalesInvoice,
|
||||
|
@ -1,98 +0,0 @@
|
||||
{
|
||||
"name": "ItemPrice",
|
||||
"label": "Item Price",
|
||||
"isChild": true,
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "enabled",
|
||||
"label": "Enabled",
|
||||
"fieldtype": "Check",
|
||||
"default": true,
|
||||
"section": "Price List"
|
||||
},
|
||||
{
|
||||
"fieldname": "buying",
|
||||
"label": "Buying",
|
||||
"fieldtype": "Check",
|
||||
"placeholder": "Buying",
|
||||
"default": false,
|
||||
"section": "Price List"
|
||||
},
|
||||
{
|
||||
"fieldname": "selling",
|
||||
"label": "Selling",
|
||||
"fieldtype": "Check",
|
||||
"placeholder": "Selling",
|
||||
"default": false,
|
||||
"section": "Price List"
|
||||
},
|
||||
{
|
||||
"fieldname": "party",
|
||||
"label": "Party",
|
||||
"placeholder": "Party",
|
||||
"fieldtype": "Link",
|
||||
"target": "Party",
|
||||
"create": true,
|
||||
"section": "Price List"
|
||||
},
|
||||
{
|
||||
"fieldname": "item",
|
||||
"label": "Item",
|
||||
"fieldtype": "Link",
|
||||
"target": "Item",
|
||||
"required": true,
|
||||
"create": true,
|
||||
"section": "Item"
|
||||
},
|
||||
{
|
||||
"fieldname": "unit",
|
||||
"label": "Unit Type",
|
||||
"fieldtype": "Link",
|
||||
"target": "UOM",
|
||||
"default": "Unit",
|
||||
"section": "Item"
|
||||
},
|
||||
{
|
||||
"fieldname": "rate",
|
||||
"label": "Rate",
|
||||
"fieldtype": "Currency",
|
||||
"required": true,
|
||||
"section": "Item"
|
||||
},
|
||||
{
|
||||
"fieldname": "batch",
|
||||
"label": "Batch",
|
||||
"fieldtype": "Link",
|
||||
"target": "Batch",
|
||||
"create": true,
|
||||
"section": "Item"
|
||||
},
|
||||
{
|
||||
"fieldname": "validFrom",
|
||||
"label": "Valid From",
|
||||
"fieldtype": "Date",
|
||||
"placeholder": "Valid From",
|
||||
"section": "Validity"
|
||||
},
|
||||
{
|
||||
"fieldname": "validUpto",
|
||||
"label": "Valid Upto",
|
||||
"fieldtype": "Date",
|
||||
"placeholder": "Valid Upto",
|
||||
"section": "Validity"
|
||||
}
|
||||
],
|
||||
"tableFields": ["item", "rate", "enabled"],
|
||||
"quickEditFields": [
|
||||
"enabled",
|
||||
"buying",
|
||||
"selling",
|
||||
"party",
|
||||
"item",
|
||||
"unit",
|
||||
"rate",
|
||||
"batch",
|
||||
"validFrom",
|
||||
"validUpto"
|
||||
]
|
||||
}
|
@ -10,36 +10,30 @@
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"fieldname": "enabled",
|
||||
"label": "Enabled",
|
||||
"fieldname": "isEnabled",
|
||||
"label": "Is Price List Enabled",
|
||||
"fieldtype": "Check",
|
||||
"default": true
|
||||
},
|
||||
{
|
||||
"fieldname": "buying",
|
||||
"label": "Buying",
|
||||
"fieldname": "isSales",
|
||||
"label": "For Sales",
|
||||
"fieldtype": "Check",
|
||||
"default": true,
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"fieldname": "isPurchase",
|
||||
"label": "For Purchase",
|
||||
"fieldtype": "Check",
|
||||
"default": false,
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"fieldname": "selling",
|
||||
"label": "Selling",
|
||||
"fieldtype": "Check",
|
||||
"default": false,
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"fieldname": "isUomDependent",
|
||||
"label": "Is Price UOM Dependent",
|
||||
"fieldtype": "Check",
|
||||
"default": false
|
||||
},
|
||||
{
|
||||
"fieldname": "itemPrice",
|
||||
"fieldname": "priceListItem",
|
||||
"label": "Item Prices",
|
||||
"fieldtype": "Table",
|
||||
"target": "ItemPrice",
|
||||
"target": "PriceListItem",
|
||||
"edit": true,
|
||||
"required": true,
|
||||
"section": "Item Prices"
|
||||
|
31
schemas/app/PriceListItem.json
Normal file
31
schemas/app/PriceListItem.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "PriceListItem",
|
||||
"label": "Price List Item",
|
||||
"isChild": true,
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "item",
|
||||
"label": "Item",
|
||||
"fieldtype": "Link",
|
||||
"target": "Item",
|
||||
"required": true,
|
||||
"create": true,
|
||||
"section": "Item"
|
||||
},
|
||||
{
|
||||
"fieldname": "unit",
|
||||
"label": "Unit Type",
|
||||
"fieldtype": "Link",
|
||||
"target": "UOM",
|
||||
"section": "Item"
|
||||
},
|
||||
{
|
||||
"fieldname": "rate",
|
||||
"label": "Rate",
|
||||
"fieldtype": "Currency",
|
||||
"required": true,
|
||||
"section": "Item"
|
||||
}
|
||||
],
|
||||
"quickEditFields": ["item", "unit", "rate"]
|
||||
}
|
@ -10,7 +10,7 @@ import GetStarted from './app/GetStarted.json';
|
||||
import InventorySettings from './app/inventory/InventorySettings.json';
|
||||
import Location from './app/inventory/Location.json';
|
||||
import PriceList from './app/PriceList.json';
|
||||
import ItemPrice from './app/ItemPrice.json';
|
||||
import PriceListItem from './app/PriceListItem.json';
|
||||
import PurchaseReceipt from './app/inventory/PurchaseReceipt.json';
|
||||
import PurchaseReceiptItem from './app/inventory/PurchaseReceiptItem.json';
|
||||
import SerialNumber from './app/inventory/SerialNumber.json';
|
||||
@ -103,7 +103,7 @@ export const appSchemas: Schema[] | SchemaStub[] = [
|
||||
PurchaseInvoiceItem as SchemaStub,
|
||||
|
||||
PriceList as Schema,
|
||||
ItemPrice as SchemaStub,
|
||||
PriceListItem as SchemaStub,
|
||||
|
||||
Tax as Schema,
|
||||
TaxDetail as Schema,
|
||||
|
Loading…
Reference in New Issue
Block a user