Wrong digits for base amount of commission with currency conversion
(tested in 6.4 and develop)
- Configure the price decimals of the tryton to 6
- Install commissions module and its requirements
- Create the rates from US Dollar and Euro:
- Dollar: 1,084300
- Euro: 1,000000
- Create the parties:
- Party Customer
- Party Commission
- Create the products:
- Product (good) (units)
- Commission product (service)
- Create a commission plan (Commission/Configuration/Plans):
- Name: Commission Plan
- Commission Method: On payment
- Commission Product: Commission Product (created in point 5)
- Add one line with the formula "amount*0.5"
- Create a new commission agent (Commission/Agents):
- Party: Party Commission (created in point 4)
- Plan: Commission Plan (created in point 6)
- Currency: Euro
- Create a new customer invoice with the next data:
- Party: Party Customer (created in point 4)
- Currency: US Dollar
- Commission Agent: Commission Party (created in point 7)
- In the invoice from point 8, create a new line with the next data:
- Product: Product (created in point 5)
- Quantity: 350
- Unit Price: 1,8700
- If we try to post the invoice, a error appears: The number of digits in the value "Decimal('603.6152356358941252420916720')" for field "Base Amount" in "3" of "Commission" exceeds the limit of "2".
For me, here are two problems:
- We need to round the base_amount when we do the compute: https://foss.heptapod.net/tryton/tryton/-/blob/d5a5f27fad76174b62942f30a59635e45a9bd009/modules/commission/invoice.py#L181
with Transaction().set_context(date=self.invoice.currency_date):
base_amount = Currency.compute(self.invoice.currency,
self.amount, agent.currency, round=False) # <- Use round = True
- I think its incorrect to use the currency decimals here (https://foss.heptapod.net/tryton/tryton/-/blob/d5a5f27fad76174b62942f30a59635e45a9bd009/modules/commission/commission.py#L348):
base_amount = Monetary(
"Base Amount", currency='currency', digits='currency', # <- Use "price_digits" instead
states=_readonly_states)
It would be better use the "price_digits" like the ammount field (https://foss.heptapod.net/tryton/tryton/-/blob/d5a5f27fad76174b62942f30a59635e45a9bd009/modules/commission/commission.py#L351):
amount = Monetary(
"Amount", currency='currency', required=True, digits=price_digits,
domain=[('amount', '!=', 0)],
states=_readonly_states)
Edited by Cédric Krier