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():
|
||||
list_.append(
|
||||
ProductSku(
|
||||
id_=item.id,
|
||||
id_=item.product_id,
|
||||
name=item.name,
|
||||
fraction_units=item.fraction_units,
|
||||
cost_price=Decimal(0),
|
||||
|
||||
@ -86,29 +86,33 @@ def build_report(
|
||||
SkuVersion.valid_till >= Voucher.date_,
|
||||
),
|
||||
)
|
||||
query: list[tuple[Voucher, Inventory, Journal, SkuVersion]] = db.execute( # type: ignore[assignment]
|
||||
select(Voucher, Inventory, Journal, SkuVersion)
|
||||
.select_from(Voucher)
|
||||
.join(Voucher.journals)
|
||||
.join(Journal.account)
|
||||
.join(Journal.cost_centre)
|
||||
.join(Voucher.inventories)
|
||||
.join(Inventory.batch)
|
||||
.join(Batch.sku)
|
||||
.join(SkuVersion, onclause=sku_version_onclause)
|
||||
.join(StockKeepingUnit.product)
|
||||
.options(
|
||||
contains_eager(Voucher.journals).contains_eager(Journal.account),
|
||||
contains_eager(Voucher.journals).contains_eager(Journal.cost_centre),
|
||||
query: list[tuple[Voucher, Inventory, Journal, SkuVersion]] = (
|
||||
db.execute( # type: ignore[assignment]
|
||||
select(Voucher, Inventory, Journal, SkuVersion)
|
||||
.select_from(Voucher)
|
||||
.join(Voucher.journals)
|
||||
.join(Journal.account)
|
||||
.join(Journal.cost_centre)
|
||||
.join(Voucher.inventories)
|
||||
.join(Inventory.batch)
|
||||
.join(Batch.sku)
|
||||
.join(SkuVersion, onclause=sku_version_onclause)
|
||||
.join(StockKeepingUnit.product)
|
||||
.options(
|
||||
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(
|
||||
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)
|
||||
).all()
|
||||
.unique()
|
||||
.all()
|
||||
)
|
||||
|
||||
for voucher, inventory, journal, stockKeepingUnit in query:
|
||||
journal_debit = journal.debit * -1
|
||||
|
||||
Reference in New Issue
Block a user