Fix: Product query was giving the version id and not product id.
The product ledger query needs to be uniqued.
This commit is contained in:
@ -511,7 +511,7 @@ async def show_term_product(
|
|||||||
for item in db.execute(query_).unique().scalars().all():
|
for item in db.execute(query_).unique().scalars().all():
|
||||||
list_.append(
|
list_.append(
|
||||||
ProductSku(
|
ProductSku(
|
||||||
id_=item.id,
|
id_=item.product_id,
|
||||||
name=item.name,
|
name=item.name,
|
||||||
fraction_units=item.fraction_units,
|
fraction_units=item.fraction_units,
|
||||||
cost_price=Decimal(0),
|
cost_price=Decimal(0),
|
||||||
|
|||||||
@ -86,29 +86,33 @@ def build_report(
|
|||||||
SkuVersion.valid_till >= Voucher.date_,
|
SkuVersion.valid_till >= Voucher.date_,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
query: list[tuple[Voucher, Inventory, Journal, SkuVersion]] = db.execute( # type: ignore[assignment]
|
query: list[tuple[Voucher, Inventory, Journal, SkuVersion]] = (
|
||||||
select(Voucher, Inventory, Journal, SkuVersion)
|
db.execute( # type: ignore[assignment]
|
||||||
.select_from(Voucher)
|
select(Voucher, Inventory, Journal, SkuVersion)
|
||||||
.join(Voucher.journals)
|
.select_from(Voucher)
|
||||||
.join(Journal.account)
|
.join(Voucher.journals)
|
||||||
.join(Journal.cost_centre)
|
.join(Journal.account)
|
||||||
.join(Voucher.inventories)
|
.join(Journal.cost_centre)
|
||||||
.join(Inventory.batch)
|
.join(Voucher.inventories)
|
||||||
.join(Batch.sku)
|
.join(Inventory.batch)
|
||||||
.join(SkuVersion, onclause=sku_version_onclause)
|
.join(Batch.sku)
|
||||||
.join(StockKeepingUnit.product)
|
.join(SkuVersion, onclause=sku_version_onclause)
|
||||||
.options(
|
.join(StockKeepingUnit.product)
|
||||||
contains_eager(Voucher.journals).contains_eager(Journal.account),
|
.options(
|
||||||
contains_eager(Voucher.journals).contains_eager(Journal.cost_centre),
|
contains_eager(Voucher.journals).contains_eager(Journal.account),
|
||||||
|
contains_eager(Voucher.journals).contains_eager(Journal.cost_centre),
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
StockKeepingUnit.product_id == product_id,
|
||||||
|
Journal.cost_centre_id != CostCentre.cost_centre_purchase(),
|
||||||
|
Voucher.date_ >= start_date,
|
||||||
|
Voucher.date_ <= finish_date,
|
||||||
|
)
|
||||||
|
.order_by(Voucher.date_, Voucher.last_edit_date)
|
||||||
)
|
)
|
||||||
.where(
|
.unique()
|
||||||
StockKeepingUnit.product_id == product_id,
|
.all()
|
||||||
Journal.cost_centre_id != CostCentre.cost_centre_purchase(),
|
)
|
||||||
Voucher.date_ >= start_date,
|
|
||||||
Voucher.date_ <= finish_date,
|
|
||||||
)
|
|
||||||
.order_by(Voucher.date_, Voucher.last_edit_date)
|
|
||||||
).all()
|
|
||||||
|
|
||||||
for voucher, inventory, journal, stockKeepingUnit in query:
|
for voucher, inventory, journal, stockKeepingUnit in query:
|
||||||
journal_debit = journal.debit * -1
|
journal_debit = journal.debit * -1
|
||||||
|
|||||||
Reference in New Issue
Block a user