Skip to Content
Menu
You need to be registered to interact with the community.
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
Opusti
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
Opusti
Avtor

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
Opusti
Avtor

Can you help me fix the error please

Try journal.total_usd = float(total)

Avtor 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
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
mar. 23
1532
1
avg. 21
3070
3
jan. 16
10775
0
jul. 25
188
0
sep. 23
1476