python Odoo 15中创建新支付方式时出错

j5fpnvbx  于 2023-04-28  发布在  Python
关注(0)|答案(2)|浏览(220)

我想创建新的付款方式,但它给了我这个错误在Odoo V15。
` File“/cityvape/cityvape-server/addons/account/models/account_payment_method.py”,第28行。get('mode ')== ' multi':例外
上述异常是以下异常的直接原因:
追溯(最近一次调用):文件“/cityvape/cityvape-server/odoo/ www.example.com ”,第643行,in _handle_exception返回super(JsonRequest,self)。_handle_exception(exception)文件“/cityvape/cityvape-server/odoo/http.py”,第301行,in _handle_exception引发异常。with_traceback(None)from new_cause AttributeError:“NoneType”对象没有属性“get”
这是密码

@api.model_create_multi
    def create(self, vals_list):
        payment_methods = super().create(vals_list)
        methods_info = self._get_payment_method_information()
        for method in payment_methods:
            information = methods_info.get(method.code)

            if information.get('mode') == 'multi':
                method_domain = method._get_payment_method_domain()

                journals = self.env['account.journal'].search(method_domain)

                self.env['account.payment.method.line'].create([{
                    'name': method.name,
                    'payment_method_id': method.id,
                    'journal_id': journal.id
                } for journal in journals])
        return payment_methods

我安装了第三方模块,但它给了我同样的错误。

lc8prwob

lc8prwob1#

information = methods_info.get(method.code)这一行有错误。..它返回None Value,因为似乎methods_info.get(method.code)返回一个空字典,或者information.get('mode')有时返回一个空字典。
使用Logger info跟踪两者的值,或使用print function在终端中打印值,以检查是否传递了正确的值

wfypjpf4

wfypjpf42#

我在Odoo 16中遇到了这个错误,我解决了它,扩展了_get_payment_method_information()并添加了代码。
首先,我在一个XML数据文件中创建了付款方式:

<data noupdate="0">
    <record id="account_payment_method_check_out" model="account.payment.method">
        <field name="name">Check</field>
        <field name="code">check</field>
        <field name="payment_type">outbound</field>
    </record>

    <record id="account_payment_method_transfer_in" model="account.payment.method">
        <field name="name">Transfer</field>
        <field name="code">transfer</field>
        <field name="payment_type">inbound</field>
    </record>
    <record id="account_payment_method_transfer_out" model="account.payment.method">
        <field name="name">Transfer</field>
        <field name="code">transfer</field>
        <field name="payment_type">outbound</field>
    </record>
</data>

然后我把代码添加到_get_payment_method_information()中:

class AccountPaymentMethod(models.Model):
_inherit = 'account.payment.method'

    @api.model
    def _get_payment_method_information(self):
        res = super()._get_payment_method_information()
        res['transfer'] = {'mode': 'multi', 'domain': [('type', '=', 'bank')]}
        res['check'] = {'mode': 'multi', 'domain': [('type', '=', 'bank')]}
        return res

相关问题