Skip to Content
Menu
This question has been flagged

I am trying to add the total for each journal in the kanban view of the journals in the accounting dashboard, and this is my python file:


from odoo import fields, models, api

class AccountJournal(models.Model):
_inherit = 'account.journal'
 
total_usd = fields.Float(string='Total in USD', compute='_compute_total_usd', readonly=True)

def _compute_total_usd(self):
for journal in self:
total = journal.currency_id._convert(float(journal.default_account_id.current_balance), 'USD', journal.company_id, fields.Date.today())
journal.total_usd = total


and this is the view file:



" rel="ugc">ir.ui.view">
account.journal.kanban.inherit
account.journal


















I am getting this error now when trying to access accounting app: 

AttributeError: 'str' object has no attribute 'round'

Can somebody help please

Avatar
Discard
Best Answer

Check your second parameter in _convert
It should be record instead of str, try this


to_currency = self.env.ref('base.USD')
...
total = journal.currency_id._convert(
float(journal.default_account_id.current_balance),
to_currency,
journal.company_id,
fields.Date.today())
Avatar
Discard
Author

Okay thanks, now I don't have this error but the field is not displayed in the journals, here is my view file:

<?xml version="1.0" encoding="UTF-8"?>

<odoo>
<data>
<record id="view_account_journal_kanban_inherit" model="ir.ui.view">
<field name="name">account.journal.kanban.inherit</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.account_journal_dashboard_kanban_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@class='col overflow-hidden text-left']" position="inside">
<field name="total_usd" widget="monetary" options="{'currency_field': 'company_currency_id', 'display_currency': 'USD'}"/>
</xpath>
</field>
</record>
</data>
</odoo>

Best Answer

Hi, you should try printing the type of all values to check if they are the Required type, in this case float. odoo has functionality of rounding that can be done on float type values. Here an argument of string type is trying to be rounded, that’s why this error is occurring. 

Avatar
Discard
Author

Can you help me fix the error please

Try journal.total_usd = float(total)

Author Best Answer

No it did not work.


kindly check:


from odoo import fields, models, api

class AccountJournal(models.Model):
_inherit = 'account.journal'
 
total_usd = fields.Float(string='Total in USD', compute='_compute_total_usd', readonly=True)

def _compute_total_usd(self):
for journal in self:
total = journal.currency_id._convert(float(journal.default_account_id.current_balance), 'USD', journal.company_id, fields.Date.today())
journal.total_usd = float(total)






" rel="ugc">ir.ui.view">
account.journal.kanban.inherit
account.journal









Avatar
Discard
Related Posts Replies Views Activity
1
Mar 23
655
1
Aug 21
2154
3
Jan 16
9789
0
Sep 23
572
1
Feb 23
2084