Ir al contenido
Menú
Se marcó esta pregunta

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
Descartar
Mejor respuesta

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
Descartar
Autor

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>

Mejor respuesta

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
Descartar
Autor

Can you help me fix the error please

Try journal.total_usd = float(total)

Autor Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
mar 23
1526
1
ago 21
3066
3
ene 16
10765
0
jul 25
100
0
sept 23
1468