Fix: Purchase was still not getting the Rate Contract information.
This commit is contained in:
@ -340,7 +340,7 @@ async def show_term_sku(
|
|||||||
|
|
||||||
for item in db.execute(query_).unique().scalars().all():
|
for item in db.execute(query_).unique().scalars().all():
|
||||||
for sku in [sku.versions[0] for sku in item.product.skus]:
|
for sku in [sku.versions[0] for sku in item.product.skus]:
|
||||||
rc_price = get_rc_price(item.id, date_, v, db)
|
rc_price = get_rc_price(sku.sku_id, date_, v, db)
|
||||||
list_.append(
|
list_.append(
|
||||||
ProductSku(
|
ProductSku(
|
||||||
id_=sku.sku_id,
|
id_=sku.sku_id,
|
||||||
|
|||||||
@ -117,7 +117,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
account: FormControl<string | Account | null>;
|
account: FormControl<string | Account | null>;
|
||||||
amount: FormControl<number>;
|
amount: FormControl<number>;
|
||||||
addRow: FormGroup<{
|
addRow: FormGroup<{
|
||||||
product: FormControl<string | null>;
|
product: FormControl<string | ProductSku | null>;
|
||||||
quantity: FormControl<string>;
|
quantity: FormControl<string>;
|
||||||
price: FormControl<string>;
|
price: FormControl<string>;
|
||||||
tax: FormControl<string>;
|
tax: FormControl<string>;
|
||||||
@ -128,7 +128,6 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
}>;
|
}>;
|
||||||
|
|
||||||
voucher: Voucher = new Voucher();
|
voucher: Voucher = new Voucher();
|
||||||
product: ProductSku | null = null;
|
|
||||||
accBal: AccountBalance | null = null;
|
accBal: AccountBalance | null = null;
|
||||||
|
|
||||||
displayedColumns = ['product', 'quantity', 'rate', 'tax', 'discount', 'amount', 'action'];
|
displayedColumns = ['product', 'quantity', 'rate', 'tax', 'discount', 'amount', 'action'];
|
||||||
@ -143,7 +142,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
account: new FormControl<string | Account | null>(null),
|
account: new FormControl<string | Account | null>(null),
|
||||||
amount: new FormControl({ value: 0, disabled: true }, { nonNullable: true }),
|
amount: new FormControl({ value: 0, disabled: true }, { nonNullable: true }),
|
||||||
addRow: new FormGroup({
|
addRow: new FormGroup({
|
||||||
product: new FormControl(''),
|
product: new FormControl<string | ProductSku | null>(null),
|
||||||
quantity: new FormControl('', { nonNullable: true }),
|
quantity: new FormControl('', { nonNullable: true }),
|
||||||
price: new FormControl('', { nonNullable: true }),
|
price: new FormControl('', { nonNullable: true }),
|
||||||
tax: new FormControl('', { nonNullable: true }),
|
tax: new FormControl('', { nonNullable: true }),
|
||||||
@ -172,10 +171,11 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
switchMap((x) => {
|
switchMap((x) => {
|
||||||
const account = this.form.value.account;
|
const account = this.form.value.account;
|
||||||
const vendorId = account && typeof account === 'object' ? account.id : undefined;
|
const vendorId = account && typeof account === 'object' ? account.id : undefined;
|
||||||
return x === null
|
const query = typeof x !== 'string' ? '' : x;
|
||||||
|
return query === null || query === ''
|
||||||
? observableOf([])
|
? observableOf([])
|
||||||
: this.productSer.autocompleteSku(
|
: this.productSer.autocompleteSku(
|
||||||
x,
|
query,
|
||||||
true,
|
true,
|
||||||
moment(this.form.value.date).format('DD-MMM-YYYY'),
|
moment(this.form.value.date).format('DD-MMM-YYYY'),
|
||||||
vendorId,
|
vendorId,
|
||||||
@ -224,22 +224,23 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
|
|
||||||
addRow() {
|
addRow() {
|
||||||
const formValue = this.form.value.addRow;
|
const formValue = this.form.value.addRow;
|
||||||
if (formValue === undefined) {
|
if (formValue === undefined || !formValue.product || typeof formValue.product === 'string') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const product = formValue.product as ProductSku;
|
||||||
const quantity = this.math.parseAmount(formValue.quantity, 2);
|
const quantity = this.math.parseAmount(formValue.quantity, 2);
|
||||||
if (this.product === null || quantity <= 0) {
|
if (quantity <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const price = this.product.isRateContracted
|
const price = product.isRateContracted
|
||||||
? (this.product.costPrice as number)
|
? (product.costPrice as number)
|
||||||
: this.math.parseAmount(formValue.price, 2);
|
: this.math.parseAmount(formValue.price, 2);
|
||||||
const tax = this.product.isRateContracted ? 0 : this.math.parseAmount(formValue.tax, 5);
|
const tax = product.isRateContracted ? 0 : this.math.parseAmount(formValue.tax, 5);
|
||||||
const discount = this.product.isRateContracted ? 0 : this.math.parseAmount(formValue.discount, 5);
|
const discount = product.isRateContracted ? 0 : this.math.parseAmount(formValue.discount, 5);
|
||||||
if ((price as number) <= 0 || (tax as number) < 0 || (discount as number) < 0) {
|
if ((price as number) <= 0 || (tax as number) < 0 || (discount as number) < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const oldFiltered = this.voucher.inventories.filter((x) => x.batch?.sku.id === (this.product as ProductSku).id);
|
const oldFiltered = this.voucher.inventories.filter((x) => x.batch?.sku.id === product.id);
|
||||||
if (oldFiltered.length) {
|
if (oldFiltered.length) {
|
||||||
this.snackBar.open('Product already added', 'Danger');
|
this.snackBar.open('Product already added', 'Danger');
|
||||||
return;
|
return;
|
||||||
@ -251,7 +252,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
tax,
|
tax,
|
||||||
discount,
|
discount,
|
||||||
amount: round(quantity * (price as number) * (1 + tax) * (1 - discount), 2),
|
amount: round(quantity * (price as number) * (1 + tax) * (1 - discount), 2),
|
||||||
batch: new Batch({ sku: this.product }),
|
batch: new Batch({ sku: product }),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
this.resetAddRow();
|
this.resetAddRow();
|
||||||
@ -260,7 +261,6 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
|
|
||||||
resetAddRow() {
|
resetAddRow() {
|
||||||
this.form.controls.addRow.reset();
|
this.form.controls.addRow.reset();
|
||||||
this.product = null;
|
|
||||||
this.form.controls.addRow.controls.price.enable();
|
this.form.controls.addRow.controls.price.enable();
|
||||||
this.form.controls.addRow.controls.tax.enable();
|
this.form.controls.addRow.controls.tax.enable();
|
||||||
this.form.controls.addRow.controls.discount.enable();
|
this.form.controls.addRow.controls.discount.enable();
|
||||||
@ -394,7 +394,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
|
|||||||
productSelected(event: MatAutocompleteSelectedEvent): void {
|
productSelected(event: MatAutocompleteSelectedEvent): void {
|
||||||
const product: ProductSku = event.option.value;
|
const product: ProductSku = event.option.value;
|
||||||
const addRowForm = this.form.controls.addRow;
|
const addRowForm = this.form.controls.addRow;
|
||||||
this.product = product;
|
addRowForm.controls.product.setValue(product);
|
||||||
addRowForm.controls.price.setValue(`${product.costPrice}`);
|
addRowForm.controls.price.setValue(`${product.costPrice}`);
|
||||||
if (product.isRateContracted) {
|
if (product.isRateContracted) {
|
||||||
addRowForm.controls.price.disable();
|
addRowForm.controls.price.disable();
|
||||||
|
|||||||
Reference in New Issue
Block a user