mirror of
https://github.com/frappe/books.git
synced 2024-11-14 01:14:03 +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 { Doc } from 'fyo/model/doc';
|
||||||
import { ListViewSettings } from 'fyo/model/types';
|
import { ListViewSettings } from 'fyo/model/types';
|
||||||
import { ItemPrice } from '../ItemPrice/ItemPrice';
|
import { PriceListItem } from './PriceListItem';
|
||||||
import { getPriceListEnabledColumn, getPriceListStatusColumn } from 'models/helpers';
|
import { getPriceListEnabledColumn, getPriceListStatusColumn } from 'models/helpers';
|
||||||
|
|
||||||
export class PriceList extends Doc {
|
export class PriceList extends Doc {
|
||||||
enabled?: boolean;
|
isEnabled?: boolean;
|
||||||
buying?: boolean;
|
isSales?: boolean;
|
||||||
selling?: boolean;
|
isPurchase?: boolean;
|
||||||
isUomDependent?: boolean;
|
priceListItem?: PriceListItem[];
|
||||||
priceListItem?: ItemPrice[];
|
|
||||||
|
|
||||||
static getListViewSettings(): ListViewSettings {
|
static getListViewSettings(): ListViewSettings {
|
||||||
return {
|
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 { Payment } from './baseModels/Payment/Payment';
|
||||||
import { PaymentFor } from './baseModels/PaymentFor/PaymentFor';
|
import { PaymentFor } from './baseModels/PaymentFor/PaymentFor';
|
||||||
import { PriceList } from './baseModels/PriceList/PriceList';
|
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 { PrintSettings } from './baseModels/PrintSettings/PrintSettings';
|
||||||
import { PurchaseInvoice } from './baseModels/PurchaseInvoice/PurchaseInvoice';
|
import { PurchaseInvoice } from './baseModels/PurchaseInvoice/PurchaseInvoice';
|
||||||
import { PurchaseInvoiceItem } from './baseModels/PurchaseInvoiceItem/PurchaseInvoiceItem';
|
import { PurchaseInvoiceItem } from './baseModels/PurchaseInvoiceItem/PurchaseInvoiceItem';
|
||||||
@ -21,11 +21,11 @@ import { SetupWizard } from './baseModels/SetupWizard/SetupWizard';
|
|||||||
import { Tax } from './baseModels/Tax/Tax';
|
import { Tax } from './baseModels/Tax/Tax';
|
||||||
import { TaxSummary } from './baseModels/TaxSummary/TaxSummary';
|
import { TaxSummary } from './baseModels/TaxSummary/TaxSummary';
|
||||||
import { Batch } from './inventory/Batch';
|
import { Batch } from './inventory/Batch';
|
||||||
import { SerialNumber } from './inventory/SerialNumber';
|
|
||||||
import { InventorySettings } from './inventory/InventorySettings';
|
import { InventorySettings } from './inventory/InventorySettings';
|
||||||
import { Location } from './inventory/Location';
|
import { Location } from './inventory/Location';
|
||||||
import { PurchaseReceipt } from './inventory/PurchaseReceipt';
|
import { PurchaseReceipt } from './inventory/PurchaseReceipt';
|
||||||
import { PurchaseReceiptItem } from './inventory/PurchaseReceiptItem';
|
import { PurchaseReceiptItem } from './inventory/PurchaseReceiptItem';
|
||||||
|
import { SerialNumber } from './inventory/SerialNumber';
|
||||||
import { Shipment } from './inventory/Shipment';
|
import { Shipment } from './inventory/Shipment';
|
||||||
import { ShipmentItem } from './inventory/ShipmentItem';
|
import { ShipmentItem } from './inventory/ShipmentItem';
|
||||||
import { StockLedgerEntry } from './inventory/StockLedgerEntry';
|
import { StockLedgerEntry } from './inventory/StockLedgerEntry';
|
||||||
@ -48,7 +48,7 @@ export const models = {
|
|||||||
PaymentFor,
|
PaymentFor,
|
||||||
PrintSettings,
|
PrintSettings,
|
||||||
PriceList,
|
PriceList,
|
||||||
ItemPrice,
|
PriceListItem,
|
||||||
PurchaseInvoice,
|
PurchaseInvoice,
|
||||||
PurchaseInvoiceItem,
|
PurchaseInvoiceItem,
|
||||||
SalesInvoice,
|
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
|
"required": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "enabled",
|
"fieldname": "isEnabled",
|
||||||
"label": "Enabled",
|
"label": "Is Price List Enabled",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "buying",
|
"fieldname": "isSales",
|
||||||
"label": "Buying",
|
"label": "For Sales",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"default": true,
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "isPurchase",
|
||||||
|
"label": "For Purchase",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"default": false,
|
"default": false,
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "selling",
|
"fieldname": "priceListItem",
|
||||||
"label": "Selling",
|
|
||||||
"fieldtype": "Check",
|
|
||||||
"default": false,
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "isUomDependent",
|
|
||||||
"label": "Is Price UOM Dependent",
|
|
||||||
"fieldtype": "Check",
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "itemPrice",
|
|
||||||
"label": "Item Prices",
|
"label": "Item Prices",
|
||||||
"fieldtype": "Table",
|
"fieldtype": "Table",
|
||||||
"target": "ItemPrice",
|
"target": "PriceListItem",
|
||||||
"edit": true,
|
"edit": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"section": "Item Prices"
|
"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 InventorySettings from './app/inventory/InventorySettings.json';
|
||||||
import Location from './app/inventory/Location.json';
|
import Location from './app/inventory/Location.json';
|
||||||
import PriceList from './app/PriceList.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 PurchaseReceipt from './app/inventory/PurchaseReceipt.json';
|
||||||
import PurchaseReceiptItem from './app/inventory/PurchaseReceiptItem.json';
|
import PurchaseReceiptItem from './app/inventory/PurchaseReceiptItem.json';
|
||||||
import SerialNumber from './app/inventory/SerialNumber.json';
|
import SerialNumber from './app/inventory/SerialNumber.json';
|
||||||
@ -103,7 +103,7 @@ export const appSchemas: Schema[] | SchemaStub[] = [
|
|||||||
PurchaseInvoiceItem as SchemaStub,
|
PurchaseInvoiceItem as SchemaStub,
|
||||||
|
|
||||||
PriceList as Schema,
|
PriceList as Schema,
|
||||||
ItemPrice as SchemaStub,
|
PriceListItem as SchemaStub,
|
||||||
|
|
||||||
Tax as Schema,
|
Tax as Schema,
|
||||||
TaxDetail as Schema,
|
TaxDetail as Schema,
|
||||||
|
Loading…
Reference in New Issue
Block a user