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:
2025-06-26 09:16:59 +00:00
parent 506123803a
commit 2496b5c16e
2 changed files with 27 additions and 23 deletions

View File

@ -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),

View File

@ -86,7 +86,8 @@ 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]] = (
db.execute( # type: ignore[assignment]
select(Voucher, Inventory, Journal, SkuVersion) select(Voucher, Inventory, Journal, SkuVersion)
.select_from(Voucher) .select_from(Voucher)
.join(Voucher.journals) .join(Voucher.journals)
@ -108,7 +109,10 @@ def build_report(
Voucher.date_ <= finish_date, Voucher.date_ <= finish_date,
) )
.order_by(Voucher.date_, Voucher.last_edit_date) .order_by(Voucher.date_, Voucher.last_edit_date)
).all() )
.unique()
.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