Numbers 金额为文字Odoo qweb采购申请报告

Numbers 金额为文字Odoo qweb采购申请报告,numbers,report,odoo,words,qweb,Numbers,Report,Odoo,Words,Qweb,我试图在奥多10中达到文字的数量。我正在覆盖请购单模板。我将共享我的.py和.xml文件。请检查我做错了什么。提前谢谢 步骤1:使用scaffold命令创建模块 步骤2:model.py # -*- coding: utf-8 -*- from odoo import models, fields, api from openerp import models, api _ from openerp.tools import amount_to_text_en from openerp impo

我试图在奥多10中达到文字的数量。我正在覆盖请购单模板。我将共享我的.py和.xml文件。请检查我做错了什么。提前谢谢

步骤1:使用scaffold命令创建模块

步骤2:model.py

# -*- coding: utf-8 -*-
from odoo import models, fields, api
from openerp import models, api _
from openerp.tools import amount_to_text_en
from openerp import tools
from openerp.tools.amount_to_text import amount_to_text

 class purchase_agreement_updates(models.Model):
     _name = 'purchase_agreement_updates.purchase_agreement_updates'
     _inherit = 'self.header'

     @api.multi
     def amount_to_text(self, amount, currency='Euro'):
         return amount_to_text(amount, currency)
purchase_agreement_updates()
class purchase_requisition(models.Model):
    _inherit = 'purchase.requisition'

     @api.multi
     def amount_to_text(self, amount, currency='Euro'):
         return amount_to_text(amount, currency)
templates.xml:

        <t t-name="purchase_requisition.report_purchaserequisitions">
            <t t-call="report.html_container">
                <t t-foreach="docs" t-as="o">
                    <!--<t t-call="report.external_layout">-->
                        <div class="header">


                              <div style="float:left;width:100px;"></div>
                              <div style="margin:0 auto;width:100%;">
                                  <h3 style="text-align:center;text-decoration: underline;margin-top:50px;">PURCHASE REQUISITION</h3></div>
                              <div style="float:right;width:100px;">
                                  <img t-if="res_company.logo" t-att-src="'data:image/png;base64,%s' %res_company.logo" height="120px" width="100px"/></div>

                            <!--<t t-esc="o.name"/>-->
                        </div>
.
.
.
.
.
.
               <tr t-foreach="o.line_ids" t-as="line_ids">
                                    <t t-set="total_value" t-value="total_value+line_ids.product_qty * line_ids.price_unit"/>
                                    <td style="border:1px solid #000;padding-left:5px;height:25px;"><span t-esc="line_ids_index+1"/> </td>
                                    <td style="border:1px solid #000;padding-left:5px;height:25px;"><span t-field="line_ids.product_id.name"/></td>
                                    <td style="border:1px solid #000;padding-left:5px;height:25px;"><span t-field="line_ids.product_qty"/> </td>
                                    <td style="border:1px solid #000;padding-left:5px;height:25px;"><span t-field="line_ids.price_unit"/> </td>
                                    <td style="border:1px solid #000;padding-left:5px;height:25px;"><span t-esc="line_ids.product_qty * line_ids.price_unit"/> </td></tr>

                                <tr><td style="border:1px solid #000;padding-left:5px;height:25px;"> </td>
                                    <td style="border:1px solid #000;padding-left:5px;height:25px;"> </td>
                                    <td style="border:1px solid #000;padding-left:5px;height:25px;"> </td>
                                    <td style="border:1px solid #000;padding-left:5px;height:25px;">Total </td>
                                    <td style="border:1px solid #000;padding-left:5px;height:25px;"> <t t-esc="total_value"/></td></tr>


                                <tr><td style="border:1px solid #000;padding-left:5px;height:25px;" colspan="5"><span style="font-weight:bold;">TOTAL PURCHASE:</span> <t t-esc="total_value"/> </td></tr>
                                <tr><td style="border:1px solid #000;padding-left:5px;height:25px;" colspan="5"><span style="font-weight:bold;">TOTAL PURCHASE IN WORDS:</span> <span t-esc="o.amount_to_text(total_value, 'Aed')"/>
                                        <!--<span t-esc="o.amount_to_text('2000', o.currency_id)"/>-->  </td></tr>

请购单
.
.
.
.
.
.
全部的
购买总额:
购买总额(大写):
错误: 在编译AST时出现错误 AttributeError:“purchase.requision”对象没有“amount\u to\u text”属性 模版:844 路径:/templates/t/t/t/div[2]/table[2]/tr[5]/td/span[2]
Node:

我认为问题在于理解行ID代表的模型

您的报表将捕获它表示为参数“docs”中每个对象的对象“o”,该参数传递给报表呈现函数

t-foreach="docs" t-as="o"
报告现在正忙于按照对象“o”的xml进行呈现,然后在对象“o”中找到的每个行ID上进行迭代

我没有看到每个“line_id”对应的模型,但是该模型必须具有该功能

def amount_to_text()

我怀疑您的函数不是正确的模型,如果您想执行该函数,必须将其移动到正确的模型。

亲爱的Phillip非常感谢您的详细回复

我的解决方案是这样的,正如我在问题中提到的,我使用的是奥多10

Models.py:

# -*- coding: utf-8 -*-

from odoo import models, fields, api
import num2words

class purchase_requisition(models.Model):
    _inherit = 'purchase.requisition'

    def conv(self, val):
        return num2words.num2words(val)
templates.xml:

<span t-esc="o.conv(total_value)" style="text-transform:uppercase;"/>

您不需要进行任何类型的覆盖。每个货币记录都内置了此功能。如果您有多币种设置,则
purchase.requision
的订单id或公司或用户应具有对币种的引用。决定要使用哪种货币,或者您可以在qweb中获取默认货币id,然后调用
货币id.amount\u to\u text(o.amount\u total)
。此处
currency\u id
是对currency对象的引用

从odoo.tools导入数量到文本
from odoo.tools import amount_to_text_en

    amt_in_words = fields.Char(compute='set_amt_in_words')

    def set_amt_in_words(self):
            for each in self:
                amount, currency = each.amount_total, each.currency_id.name
                amount_in_words = amount_to_text_en.amount_to_text(amount, lang='en', currency=currency)
                if currency == 'INR':
                    amount_in_words = str(amount_in_words).replace('INR', 'rupees')
                    amount_in_words = str(amount_in_words).replace('Cents', 'paise')
                    amount_in_words = str(amount_in_words).replace('Cent', 'paise')
                amount_in_words += '\tonly'
                each.amt_in_words = amount_in_words.title()

XML :
<span t-esc="o.amt_in_words"/>
amt\u in\u words=fields.Char(compute='set\u amt\u in\u words') def设置金额(大写): 对于每个人自己: 金额,货币=每个。金额\总计,每个。货币\ id。名称 金额(大写)=金额到文字(大写)【金额到文字】。金额到文字(金额,lang='en',币种=币种) 如果货币=‘印度卢比’: 大写金额=str(大写金额)。替换为('INR','卢比') 大写金额=str(大写金额)。替换('Cents','paise') 大写金额=str(大写金额)。替换('Cent','paise') 金额(大写)+='\tonly' each.amt\u in\u words=amount\u in\u words.title() XML:
@api.multi 定义金额到文本(自身、金额、币种='INR'): 金额(大写)=金额到文字(大写)【金额到文字】。金额到文字(金额,lang='en',币种=币种) 如果货币=‘印度卢比’: 大写金额=str(大写金额)。替换为('INR','卢比') 大写金额=str(大写金额)。替换('Cents','paise') 大写金额=str(大写金额)。替换('Cent','paise') 金额(大写)+='\tonly' 退货金额(大写)

def get_amount_in_words(self, amount):
    amount_in_words = self.amount_to_text(amount)
    return amount_in_words

xml-

可以显示报告操作吗?
def get_amount_in_words(self, amount):
    amount_in_words = self.amount_to_text(amount)
    return amount_in_words