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

Enhance price list #656

Merged
merged 3 commits into from
Jun 7, 2023
Merged
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
4 changes: 2 additions & 2 deletions models/baseModels/PriceList/PriceList.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Doc } from 'fyo/model/doc';
import { ListViewSettings } from 'fyo/model/types';
import { ItemPrice } from '../ItemPrice/ItemPrice';
import { getPriceListStatusColumn } from 'models/helpers';
import { getPriceListEnabledColumn, getPriceListStatusColumn } from 'models/helpers';

export class PriceList extends Doc {
enabled?: boolean;
Expand All @@ -12,7 +12,7 @@ export class PriceList extends Doc {

static getListViewSettings(): ListViewSettings {
return {
columns: ['name', getPriceListStatusColumn()],
columns: ['name', getPriceListEnabledColumn(), getPriceListStatusColumn()],
};
}
}
37 changes: 30 additions & 7 deletions models/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,18 @@ export function getPriceListStatusColumn(): ColumnConfig {
fieldname: 'enabledFor',
fieldtype: 'Select',
render(doc) {
let status = 'None';
let status = t`None`;

if (doc.buying && !doc.selling) {
status = 'Buying';
status = t`Buying`;
}

if (doc.selling && !doc.buying) {
status = 'Selling';
status = t`Selling`;
}

if (doc.buying && doc.selling) {
status = 'Buying & Selling';
status = t`Buying & Selling`;
}

return {
Expand All @@ -354,6 +354,26 @@ export function getPriceListStatusColumn(): ColumnConfig {
};
}

export function getPriceListEnabledColumn(): ColumnConfig {
return {
label: t`Enabled`,
fieldname: 'enabled',
fieldtype: 'Data',
render(doc) {
let status = t`Unenabled`;
let color = 'orange';
if (doc.enabled) {
status = t`Enabled`;
color = 'green';
}

return {
template: `<Badge class="text-xs" color="${color}">${status}</Badge>`,
};
},
};
}

export async function getItemPrice(
doc: InvoiceItem | ItemPrice,
validFrom?: Date,
Expand All @@ -363,18 +383,21 @@ export async function getItemPrice(
return;
}

const isUomDependent = await doc.fyo.getValue(
const { isUomDependent, enabled, buying, selling } = await doc.fyo.doc.getDoc(
ModelNameEnum.PriceList,
doc.priceList,
'isUomDependent'
);

if(!enabled || doc.isSales && !selling || !doc.isSales && !buying){
return
}

const itemPriceQuery = Object.values(
await doc.fyo.db.getAll(ModelNameEnum.ItemPrice, {
filters: {
enabled: true,
item: doc.item,
...(doc.isSales ? { selling: true } : { buying: true }),
// ...(doc.isSales ? { selling: true } : { buying: true }),
...(doc.batch ? { batch: doc.batch as string } : { batch: null }),
},
fields: ['name', 'unit', 'party', 'batch', 'validFrom', 'validUpto'],
Expand Down