İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
2401 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç
Üretici

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>

En İyi Yanıt

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
Vazgeç
Üretici

Can you help me fix the error please

Try journal.total_usd = float(total)

Üretici En İyi Yanıt

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Mar 23
1761
1
Ağu 21
3350
3
Oca 16
11102
0
Tem 25
765
0
Eyl 23
1671