Not return last currency purchase

Last issue9855 that return invoice method and payment term from last purchase, I see that not return last currency

  1. Purchases and currencies in our database:
select id, create_date, currency from purchase_purchase where party = 411 order by id desc;
 id |        create_date         | currency 
----+----------------------------+----------
 14 | 2022-09-21 10:51:57.055779 |      143
 13 | 2022-09-21 10:43:48.525552 |      143
 12 | 2022-09-21 10:40:17.945997 |      143
  8 | 2022-09-19 09:39:58.972665 |       44
  7 | 2022-09-19 09:28:06.622479 |       44
  6 | 2022-09-19 08:43:21.719179 |       44
  3 | 2022-09-19 08:15:50.225536 |       44

When on_change_party() and get last purchase [1], I get currency ID 44. Not ID 143 that is last currency in our purchases.

Debug:

(Pdb) cursor.execute(*subquery.select(subquery.currency,subquery.payment_term,subquery.invoice_method,group_by=[subquery.currency,subquery.payment_term,subquery.invoice_method,],order_by=Count(Literal(1)).desc))
(Pdb) row = cursor.fetchone()
(Pdb) row
(44, 8, 'shipment')

Why return ID 44 when last purchase, the currency is ID 143?

note:

All results from query:

SELECT a.currency, a.payment_term, a.invoice_method FROM (SELECT b.currency, b.payment_term, b.invoice_method FROM purchase_purchase AS b WHERE ((b.party = 411) AND (b.invoice_party IS NULL)) ORDER BY b.id LIMIT 10) AS a GROUP BY a.currency, a.payment_term, a.invoice_method ORDER BY COUNT(1) DESC;
 currency | payment_term | invoice_method 
----------+--------------+----------------
       44 |            8 | shipment
      143 |            8 | shipment

[1] purchase/purchase.py at 06149a1cd43f301940af3b795bc52610a056eb0b · tryton/purchase · GitHub

Currency is taken from the most used currency in the last 10 purchases: modules/purchase: 44c68ce98e8e purchase.py

So in your case, currency 44 is most used than currency 143.

Thanks maxx.

Last purchases != last purchase :slight_smile:

1 Like