Skip to Content
Menu
This question has been flagged
1 Reply
985 Views

I want to transform account_total's value into chinese. For example, if account_total value is 265415.00 , transform to chinese is 贰拾陆萬伍仟肆佰壹拾伍圆.

So I costomized a function, and this function work well in the test.

But when I add this function into sale.py to make this transform automatically. 

It didnt work.

I dont know what account_total's python type. Maybe is float? I am not sure.

So I guess maybe the type of parameter passed to my function is wrong. 

Another possibility is that I'm calling the function the wrong way. 

I am wonder how can i make it work?

Thanks for any help in advance!

Here's my code.

class SaleOrder(models.Model):
_name = "sale.order"
_inherit = ['portal.mixin', 'mail.thread', 'mail.activity.mixin', 'utm.mixin']
...
def num2chn(total):
numchar = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
pr = ['圆', '拾', '佰', '仟', '萬', '拾']
total = int(total)
length = len(str(total))
chn = ''
for i in str(total):
length -= 1
chn = chn + ('%s%s' % (numchar[int(i)], pr[length]))
return chn
...
amount_chn = fields.Text(string='大写金额', readonly=True)
...
@api.model
def create(self, vals):
vals['account_chn']=self.num2chn(self.amount_total)
...
result = super(SaleOrder, self).create(vals)
return result

( In the Technical/Databasee structure/Models/Sales Order/Fields, I can find my customized Field( amount_chn ) . And then i edit Technical/Reporting/Reports/Quotation Order/Qweb views/report_saleorder_document, i add amount_chn into this views, no error, but when i print report , amount_chn is blank without any chinese word! And meantime account_total's value is not blank. )

Avatar
Discard
Best Answer

Problem is below code-

vals['account_chn']=self.num2chn(self.amount_total)
amount_total you are accessing with self but self in create method just a object not any recordset. You can write as below-
def create(self, vals):
result = super(SaleOrder, self).create(vals)
        result.account_chn = result.num2chn(result.amount_total)
return result
Avatar
Discard