SDD Payment via Automated Action (Odoo v13)

349 views Asked by At

Unfortunately Odoo has removed the automatic SSD payment from v12 to v13, which is crucial for me. Therefore I try to reproduce the behavior via an automated action and came quite far I guess.

I created an Automated Action that watches all invoices in draft and runs a python code if the invoice is set from draft to not draft. But unfortunately I get an error as soon as I try to post an invoice:

"Database fetch misses ids (('10',)) and has extra ids ((10,)), may be caused by a type incoherence in a previous request"

As far as I know this is related to type transformation, but as I am new to python & odoo, I am not sure how to transform the odoo datatypes correctly. Does anyone have a hint?

Here's the python code that should be executed:

payment = env['account.payment'].create({
     'payment_method_id' : '6',
     'partner_id': record.partner_id.id,
     'journal_id' :     '10',
     'amount' : record.amount_residual
})

The ids are double checked and link to the correct entries:

  • payment_method_id '6' = my bank account
  • journal_id '10' = SDD Payment

Below please find the current domain applied to the Automated Action. Any hints or help is much appreciated!

Many thanks. Best regards, Christian

Automated Action - Domain

2

There are 2 answers

0
Dipen Shah On BEST ANSWER

CBfac

On the many2one field you have to assign the ID.

Code Correction:

payment = env['account.payment'].create({
     'payment_method_id' : 6,
     'partner_id': record.partner_id.id,
     'journal_id' : 10,
     'amount' : record.amount_residual
})
0
CBfac On

For everyone who needs automatic SDD payments in Odoo v13, here's the Automated Action that works for me (one more, thanks @Dipen Sah for your assistance):

Modell: account.move Trigger: on update Action: Execute python code

Domain (before update):

["&","&","&","&",["sdd_paying_mandate_id","=",False],["partner_id.sdd_mandate_ids","!=",False],["type","=","out_invoice"],["invoice_payment_state","=","not_paid"],["state","=","draft"]]

Domain (after update):

["&","&","&","&",["sdd_paying_mandate_id","=",False],["partner_id.sdd_mandate_ids","!=",False],["type","=","out_invoice"],["invoice_payment_state","=","not_paid"],["state","!=","draft"]]

Python code to execute:

payment = env['account.payment'].create({
     #'name' : env['ir.sequence'].next_by_code('account.payment.customer.invoice'),
     #'payment_type': 'inbound',
     #'partner_type' : 'customer',
     'payment_method_id' : 6,
     'partner_id': record.partner_id.id,
     'journal_id' :     10,
     'amount' : record.amount_residual}).post()

You have to upate the journal and payment_method ids within the python code to match your IDs in order to get the action running properly.

Any improvements and/or feedback are welcome.

Best regards, Christian