Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

fields function python

By
B.hind
on 7/26/16, 6:30 AM 264 views

hi ,

i want to add field.function 'amount_total_text ' to class  account.move because i want this field in report created by pentaho

i had done this but it isn't worked


class AccountMove(models.Model):

_name = 'account.move'

_inherit = 'account.move'

amount_total_text:fields.Function(amount_to_text_fr,methode="True",string="total",type="string")

@api.multi

def amount_to_text_fr(self, amount, currency='Dirhams'):

return amount_to_text_fr(amount,currency)

@api.depends('control_amount_total')

def _compute_control_amount_total_text(self):

for record in self:

if record.control_amount_total :

amount = record.control_amount_total

list = str(amount).split('.')

start_word = amount_to_text_fr(abs(int(list[0])), 'Dirhams').split('Dirhams')[0]

end_word = amount_to_text_fr(int(list[1]), 'Centimes').split('Centimes')[0]

record.control_amount_total_text = start_word + ' Dirhams et ' + end_word + ' Centimes'

#self.control_amount_total_text = amount_to_text(self.control_amount_total,'fr','Dirhams')

this is my code that contains function and new field but it isnt working

thanks to help me


0
ayman mohammed adam
On 7/26/16, 9:48 AM

Dear B.hind,

replace this line

amount_total_text:fields.Function(amount_to_text_fr,methode="True",string="total",type="string")

by

@api.depends('control_amount_total')

def _compute_control_amount_total_text(self):

for record in self:

if record.control_amount_total :

amount = record.control_amount_total

list = str(amount).split('.')

start_word = amount_to_text_fr(abs(int(list[0])), 'Dirhams').split('Dirhams')[0]

end_word = amount_to_text_fr(int(list[1]), 'Centimes').split('Centimes')[0]

record.amount_total_text = start_word + ' Dirhams et ' + end_word + ' Centimes'

#self.control_amount_total_text = amount_to_text(self.control_amount_total,'fr','Dirhams')

amount_total_text:fields.Char(compute='_compute_control_amount_total_text', method="True", string="total")


try it

I hope I will help you


0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 7/26/16, 9:28 AM

Hello,

In the new api we defines the functional field as:

total = fields.Float(compute='_compute_total')

as in the documentaion,  and if you paste some of the error message it'll be helpful ....

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/26/16, 6:30 AM
Seen: 264 times
Last updated: 7/26/16, 9:48 AM