Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Send Email after payment creted for invoice

Subscribe

Get notified when there's activity on this post

This question has been flagged
odoo 17
2 Replies
2543 Views
Avatar
jenan soliman

Hello, 

I want to send an email for the customer after the payment is created,

I tried to use this but not worked

class AccountPaymentRegisterInherit(models.TransientModel):
_inherit = 'account.payment.register'

def action_create_payments(self):

payment_records = super(AccountPaymentRegisterInherit, self).action_create_payments()

payments = self.env['account.payment'].search([('id', 'in', payment_records.ids)])

for payment in payments:
email_template = self.env.ref('plnx_membership.email_template_register_payment', raise_if_not_found=False)
if email_template:
email_template.send_mail(payment.id, force_send=True)

return payment_records
def write(self, vals):
result = super(AccountMove, self).write(vals)
for record in self:
if vals.get('payment_state') == 'paid' and record.payment_state == 'paid':


email_template = self.env.ref(
'plnx_membership.email_template_payment_registered')
if email_template:
email_template.send_mail(record.id, force_send=True)

return result
0
Avatar
Discard
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

Your code has a few issues:

  • In the account.payment.register inherit, action_create_payments() returns a recordset of account.payment (not a dict with ids), so payment_records.ids may fail if it's a single record—use payment_records directly.
  • The template 'plnx_membership.email_template_register_payment' may not exist or be configured for account.payment (ensure it's defined for the model and has partner_to_set for the customer).
  • In the AccountMove.write, the condition vals.get('payment_state') == 'paid' and record.payment_state == 'paid' is redundant and won't trigger reliably, as payment_state is a computed field (not stored) and only updates after the write completes. Use @api.depends or a post-write hook for reactivity.

Recommended Fix: Inherit account.payment and Override action_post() This triggers after the payment is posted (confirmed), which is when it's "created" and reconciles with the invoice, updating the invoice to 'paid'. Send the email to the invoice's partner (customer).

python

from odoo import models, api

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

    def action_post(self):
        res = super().action_post()
        for payment in self:
            # Get the reconciled invoice (assuming customer payment)
            reconciled_invoices = payment.reconciled_invoice_ids
            if reconciled_invoices:
                invoice = reconciled_invoices[0]  # Or loop if multiple
                email_template = self.env.ref('plnx_membership.email_template_payment_registered', raise_if_not_found=False)
                if email_template:
                    # Set context for customer email
                    email_template.with_context(default_partner_id=invoice.partner_id.id).send_mail(
                        invoice.id, force_send=True
                    )
        return res
  • Template Setup: Ensure email_template_payment_registered is for account.move (invoice model), with partner_to_set: object.partner_id in the template to email the customer.
  • Why action_post?: Payments are created as draft; posting confirms them and links to invoices.


Hope it helps

0
Avatar
Discard
Avatar
Akhilesh N S
Best Answer
class AccountPayment(models.Model):
_inherit = "account.payment"

def action_post(self):
res = super(AccountPayment, self).action_post()

for payment in self:

# Use email code here

return res


Hi, better to use model account.payment to send automated email instead of account.payment.register model

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Why Doesn't the Hamburger Menu Show for My Custom Group User Despite Adding ir_ui_menu Access Right?
odoo 17
Avatar
Avatar
1
May 25
2092
Como heredo de un modal en Odoo 17
odoo 17
Avatar
0
Jan 25
1554
Customise receipt customer odoo point of sale
pos odoo 17
Avatar
Avatar
1
Jun 25
1073
How to setup product that can be either a subscription or sold directly
Subscriptions odoo 17
Avatar
1
Jun 25
2273
Tasks menu disappeared from Project menu (odoo 17 CE) Solved
project odoo 17
Avatar
Avatar
2
Apr 25
1707
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now