# How to sum of them separate from currencies?

By
Rick
on 11/2/16, 12:14 PM 894 views

Hi,guys

we have a difficult question

On same sale order need to show multi currencies,but how to sum of separate from them?

E.g:

Total:

USD 500.00

EUR 200.00

CNY 100

Any good idea?

Currency comes from price list. you can only select one currency for a price list..then how you are going to set this three currencies in same SO?

in which currency you want the sum??

fasluca
on 11/3/16, 12:05 AM

Tks for your reply.There is only one currency on the same sales order that does not meet my requirements.I need multi currencies on same sales order.

Rick
on 11/3/16, 12:30 AM

So you may have customized SO line to set different currency in each line..

You have to enable multi currency and one of them should be Base..

you haven't said which one is your base currency? ie in which currency you wan the sum)

fasluca
on 11/3/16, 12:45 AM

My base currency is CNY, Now I can sum the base currency. In addition I need to sum these foreign currency lines

Rick
on 11/3/16, 12:51 AM

if you have currency field in SO line...then you can calculate total easily

for line in self.order_line:

if line.currency_id.name == USD:

usd_total += line.subtotal

if line.currency_id.name == EUR:

eur_total += line.subtotal

if line.currency_id.name == CYN:

cyn_total += line.subtotal

like this

fasluca
on 11/3/16, 2:02 AM

super！I'll try it! Thanks

Rick
on 11/3/16, 3:36 AM

Make it as answer if you succeed

fasluca
on 11/3/16, 4:16 AM

okay.

Rick
on 11/3/16, 8:12 AM
Artem
On 11/2/16, 2:47 PM

It is really hard to show or I know nothing about Odoo.

`@api.onedef _compute_amount_each_currency(self):    sums=dict([(l.currency_id.name,0) for l in self.expense_ticket_line_ids])    for line in self.expense_ticket_line_ids:        sums[line.currency_id.name]+=line.amount_currency    self.amount_each_currency=json.dumps(sums)amount_each_currency = fields.Text(compute='_compute_amount_each_currency')`

So we have got the field with the sums for each currency. This is the easiest part.

And now show time!

I'm still upset that <templetes> is available only in a kanban view. Am I right?

So in a form view I see only two ways. The first is to add another text field with appropriate text like 'Totals EUR: xxx, CYN: xxx, USD: xxx' in one line and add this field to the view. Baldly but I can't find another way.

A report is more flexible and here we can make it nice looking.  Create a model with the render_html function

`class ReportSometing(models.AbstractModel):    @api.one    def render_html(self, data=None):    [...]    if objects[0]:        sums=json.loads(objects[0].amount_each_currency)        sums=[[key,value] for key,value in sums.items()]    else:        sums=[]    docargs = {        'sums': sums,    }    [...]`

and convert the field with each currency totals into the list of lists of a currency name and its amount.

Insert into the report something like the following and get the profit.

`<t t-foreach="sums" t-as="i">     <p><t t-esc="i[0]"/><t t-esc="i[1]"/></p></t>`

Season with any decoration.

Well.. the second way is to create a separate table with sums for each currency like the class AccountInvoiceLine(models.Model). The code is in brief. I did not test the whole idea.

`class ExpenseTicket(models.Model):    expense_ticket_currency_ids = fields.One2many('expense.ticket.currency', 'expenseticket_id')class ExpenseTicketCurrency(models.Model):    _name = "expense.ticket.currency"    expenseticket_id = fields.Many2one('expense.ticket', string='', ondelete='cascade', index=True)    currency_id = fields.Many2one('res.currency',string='Currency')    amount_currency=fields.Monetary(string='Amount', currency_field='currency_id')`

In a view we can use 'tree'

`<field name="expense_ticket_currency_ids"> <tree string=""> <field name="currency_id"/> <field name="amount_currency"/> </tree></field>`

The last part is to write functions to store data into ExpenseTicketCurrency.

Rick
On 11/2/16, 8:40 PM

Question again

There are some products(services type) on the sales order line of the same sales order, which are in different currencies.

How to sum them group by different currencies and show on sale order form?

E.g:

Ocean Freight USD 10.00

Truck charge USD 5.00

Documents Fee EUR 50.00

Discharge Fee CNY 100

Total : USD xx.xx

EUR xx.xx

CNY xx.xx

Any good idea?

The answer is below. I do not know your format of invoice lines but referring to invoice lines of the standard accounting module the code should be changed and added to '_compute_amount(self)' of the AccountInvoice.

amount_untaxed_sums=dict([(l.currency_id.name,0) for l in self.invoice_line_ids])

for line in self.invoice_line_ids:

amount_untaxed_sums[line.currency_id.name]+=line.price_subtotal

I did not test the code in Odoo but it should work.

Artem
on 11/5/16, 4:26 AM

Rick
on 11/5/16, 8:59 AM

The code sums up perfectly, but I have problems with the show part.

Artem
on 11/5/16, 10:52 AM

Artem
on 11/5/16, 4:09 PM

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

### Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

1 follower(s)

### Stats

 Asked: 11/2/16, 12:14 PM Seen: 894 times Last updated: 9/3/17, 8:58 PM