【问题标题】:Amount to words Odoo qweb report for Purchase Requisition数量为 Odoo qweb 报告的采购申请
【发布时间】:2018-04-22 13:19:33
【问题描述】:

我正在尝试在 odoo 10 中达到单词数量。我正在覆盖采购申请模板。我将分享我的 .py 和 .xml 文件,请检查我做错了什么。提前致谢!

Step1:使用脚手架命令创建模块。

第二步: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)

模板.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.requisition”对象没有属性“amount_to_text” 模板:844 路径:/templates/t/t/t/t/div[2]/table[2]/tr[5]/td/span[2] 节点:

【问题讨论】:

  • 你能显示报告动作吗?

标签: numbers report odoo words qweb


【解决方案1】:

您不需要进行任何类型的覆盖。每个货币记录都内置了此功能。如果您有多币种设置,那么purchase.requisition 或公司或用户的 order_id 应该有对货币的参考。决定你想使用哪种货币 或者你可以在 qweb 中获取默认货币 id 并致电currency_id.amount_to_text(o.amount_total)。这里currency_id 是对货币对象的引用。

【讨论】:

    【解决方案2】:

    我认为问题在于理解你的 line_ids 代表什么模型。

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

    t-foreach="docs" t-as="o"
    

    报告现在正忙于根据您的 xml 为对象“o”呈现,然后遍历对象“o”中找到的每个 line_id。

    t-foreach="o.line_ids" t-as="line_ids"
    

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

    def amount_to_text()
    

    我怀疑你的函数不在正确的模型中,如果你想执行这个函数,你必须将它移动到正确的模型中。

    【讨论】:

      【解决方案3】:

      尊敬的菲利普,非常感谢您的详细回复。

      对我有用的解决方案是这样的,正如我在问题中提到的,我正在使用 odoo 10。

      模型.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)
      

      模板.xml:

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

      【讨论】:

        【解决方案4】:
        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"/>
        

        【讨论】:

          【解决方案5】:

          @api.multi def amount_to_text(self, amount, currency='INR'): amount_in_words = amount_to_text_en.amount_to_text(amount, lang='en', currency=currency) 如果货币 == 'INR': amount_in_words = str(amount_in_words).replace('INR', '卢比') amount_in_words = str(amount_in_words).replace('Cents', 'paise') amount_in_words = str(amount_in_words).replace('Cent', 'paise') amount_in_words += '\tonly' 返回数量_in_words

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

          和 xml -

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多