Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie

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

Awatar
Odrzuć
Najlepsza odpowiedź

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())
Awatar
Odrzuć
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>

Najlepsza odpowiedź

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. 

Awatar
Odrzuć
Autor

Can you help me fix the error please

Try journal.total_usd = float(total)

Autor Najlepsza odpowiedź

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









Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
mar 23
1702
1
sie 21
3284
3
sty 16
11011
0
lip 25
688
0
wrz 23
1647