Yassine Haoufadi
Yassine Haoufadi

Reputation: 11

Error when create new payment method in Odoo 15

I want to create new method payment but it gives me this error in Odoo V15.

` File "/cityvape/cityvape-server/addons/account/models/account_payment_method.py", line 28, in create if information.get('mode') == 'multi': Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/cityvape/cityvape-server/odoo/http.py", line 643, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/cityvape/cityvape-server/odoo/http.py", line 301, in _handle_exception raise exception.with_traceback(None) from new_cause AttributeError: 'NoneType' object has no attribute 'get'`

This is the code

@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

I installed third party module but it gave me same error.

Upvotes: 1

Views: 542

Answers (2)

Pegasus
Pegasus

Reputation: 849

I had this error in Odoo 16 and I solved it extending _get_payment_method_information() and adding the codes.

First I created the payment methods in an XML datafile:

<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>

Then I added the codes to _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

Upvotes: 1

Sidharth Panda
Sidharth Panda

Reputation: 716

information = methods_info.get(method.code) this line has error... It is returning None Value because it seems either methods_info.get(method.code) is returning an empty dictionary or information.get('mode') sometimes returns an empty dictionary.

Use Logger info to trace the value of both or use print function to print the value in terminal to check whether the correct value is passed or not

Upvotes: 0

Related Questions