Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

Check if invoice has paid and change state on other module

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
invoiceinvoice_statestatepaidv14
2 Replies
9547 Tampilan
Avatar
Tri Nanda

I use Odoo14 community version,

I have a custom module that can create an invoice for student course registration, here is the code to create student invoice:

def create_invoice(self):
invoice = self.env['account.move'].create({
'move_type': 'out_invoice',
'partner_id': self.student_id.partner_id.id,
'invoice_line_ids': (
{
'product_id': self.course_id.product_id,
'quantity': 1,
'price_unit': self.course_id.product_id.lst_price,
'tax_ids': False
},
{
'product_id': self.subject_ids.product_id,
'quantity': 1,
'price_unit': self.subject_ids.product_id.lst_price,
'tax_ids': False
}
)
})
and I also have state for the student status, here is the code:
state = fields.Selection(string="Student Status", selection=[
('waiting', 'Waiting List'),
('has_been_contacted', 'Has been Contacted'),
('payment_process', 'Payment Process'),
('registered_student', 'Registered'),
('active_student', 'Active Student'),
('unactive_student', 'Unactive Student'),
], default='waiting')
when we triggered the create_invoice method on a button, the state will move to payment_process.


Now, I want if the created invoice payment state is paid, wether my user is access the invoice from my custom module or directly from Invoice/Accounting module, I want the state on my module is move automatically to registered_student.


My question are, how to do that?

Any help, source or tutorial how to do that will be very appreciated,


Edit:


I also create a field to save the registration ID on my models:

class AqurStudentCourse(models.Model):
    _name = "aqur.student.course"
    registration_invoice_id = fields.Integer(string='Registration Invoice ID')

Then I insert value on the registration_invoice_id when I create invoice:


def create_invoice(self):
invoice = self.env['account.move'].create({
'move_type': 'out_invoice',
'partner_id': self.student_id.partner_id.id,
# 'invoice_date': date_invoice,
'invoice_line_ids': (
{
'product_id': self.course_id.product_id,
'quantity': 1,
'price_unit': self.course_id.product_id.lst_price,
'tax_ids': False
},
{
'product_id': self.subject_ids.product_id,
'quantity': 1,
'price_unit': self.subject_ids.product_id.lst_price,
'tax_ids': False
}
)
})
self.registration_invoice_id = invoice.id

Here is the screenshot how I create the invoice from button:

When I create the Registration Fee button, it will create an invoice, then the state will move to Payment Process. And here is the created invoice:

Now , I want if the field invoice_payment_state from the  account.move  model if the  status  has been paid:


I want the state from my custom module automatically change to registered_student:



I try to apply the overide function code that suggest by @Niyas, here is the code:


def write(self, vals):
invoice_payment_state = self.env['account.move'].search(
[('partner_id.id', '=', self.student_id.partner_id.id), ('id', '=', self.registration_invoice_id),
('payment_state', '=', 'paid')])
if 'state' in vals and vals['state']:
if invoice_payment_state.payment_state:
self.state = 'registered_student'
return super(AqurStudentCourse, self).write(vals)
I call the above function from my AqurStudentCourse model, and I got the result from  the    invoice_payment_state.


But, when I test the function how  it  works, nothings is happen on my student course state when I try to Register Payment on the  Invoice and get the Invoice status to Paid.


Even, I got this error message when I try to change the state manually:

Traceback (most recent call last):
  File "/opt/odoo/odoo14/odoo/http.py", line 640, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo14/odoo/http.py", line 316, in _handle_exception
    raise exception.with_traceback(None) from new_cause
RecursionError: maximum recursion depth exceeded while calling a Python object
So, what is wrong with my overide method?

Please, any help would be very appreciated.


Thank you,

Tri Nanda


EDIT 2:


I try to override the AccountMove models now with this code:


class AccountMove(models.Model):
_inherit = "account.move"

def write(self, vals):
student_course_registration_id = self.env['aqur.student.course'].search(
[('registration_invoice_id', '=', self.id)])

course_registration_status = self.env['account.move'].search(
[('id', '=', student_course_registration_id.registration_invoice_id)])

if course_registration_status.payment_state == 'paid':
self.env['aqur.student.course'].search(
[('registration_invoice_id', '=', course_registration_status.id)]).write(
{'state': 'registered_student'})

return super(AccountMove, self).write(vals)
but, nothing is happen when the invoice has paid, the student course state still not update anythings, is there anothers solutions?


Thanks,

Tri Nanda

0
Avatar
Buang
Tri Nanda
Penulis

Yes @Niyas, I try that logic, but doesnt affect anything, may you sugges me other way with other example code?, or source or tutorial how to do that?, thank you Niyas

Avatar
Tri Nanda
Penulis Jawaban Terbai

Finaly I solved this by this following code:

class AccountMove(models.Model):
_inherit = "account.move"

def write(self, vals):
# student_course_registration_id = self.env['aqur.student.course'].search(
# [('registration_invoice_id', '=', self.id) or ('tuition_fee_id', '=', self.id)])

invoice_course = self.env['account.move'].search(
[('name', '=', self.ref)])

if invoice_course.payment_state == 'paid' and self.env['aqur.student.course'].search(
[('registration_invoice_id', '=', invoice_course.id)]):
self.env['aqur.student.course'].search(
[('registration_invoice_id', '=', invoice_course.id)]).write(
{'state': 'registered_student'})

if invoice_course.payment_state == 'paid' and self.env['aqur.student.course'].search(
[('tuition_fee_id', '=', invoice_course.id)]):
self.env['aqur.student.course'].search(
[('tuition_fee_id', '=', invoice_course.id)]).write(
{'state': 'active_student'})

return super(AccountMove, self).write(vals)
Thank you @Niyas and who have help me, the Niyas answer in this thread really help and give  my  insight  to  face  this .


0
Avatar
Buang
Avatar
Niyas Raphy (Walnut Software Solutions)
Jawaban Terbai

Hi,
if you have kept some relation with your model and invoice it will be easy, you can override the write method of invoice, then check the status, whether it going to paid state, if yes, you can update the original source record to the required state.

Sample Code:

def write(self, vals):
if 'state' in vals and vals['state']:
if vals['state'] == 'paid':
if self.source_field:
#assuming source field is a many2one field
self.source_field.state = 'new_state'
return super(AccountMove, self).write()

Thanks

0
Avatar
Buang
Tri Nanda
Penulis

Hi Niyas, thank you for the respon,

I got this error Niyas:
`NameError: name 'AccountMove' is not defined`

then I add `@api.model` on the above of function, but getting the new error:
`TypeError: write() takes 2 positional arguments but 3 were given`

may you give suggestion how to handle the error Niyas?

Thanks,
Tri Nanda

Niyas Raphy (Walnut Software Solutions)

`NameError: name 'AccountMove' is not defined`, for this instead of AccountMove you have to specify your classname.

then return super(AccountMove, self).write()
to return super(AccountMove, self).write(vals)

Tri Nanda
Penulis

Hi Niyas, am still new on Odoo development, may you specify more details how to do that NIyas?

I found `invoice_payment_state` on "account.move" models, that is the field that store the "paid" status if customer register they payment to paid total,

I want to change my state on my custom module that I have defined above.

I have try to approach your example code Niyas, but still confuse, may you help clarify more details Niyas, please?

Niyas Raphy (Walnut Software Solutions)

For overriding the write function in odoo, see: https://www.youtube.com/watch?v=v8sXFUi1SH4&t=1s

Tri Nanda
Penulis

Hi @Niyas, I try to update my questions, may you help my to give solutions, please?

Niyas Raphy (Walnut Software Solutions)

instead of overiding write method of custom module, override the write method of invoice model and then update your record

Tri Nanda
Penulis

Hi @Niyas, I override the AccountMove models now, but nothing is happen?, is there any solutions Niyas, Please?

Niyas Raphy (Walnut Software Solutions)

Did you applied the logic like if the newly writing state in account move is paid, then did you tried updating the other record ?

Tri Nanda
Penulis

Yes @Niyas, I that logic, but doesnt affect anything, may you sugges me other way with other example code?, or source or tutorial how to do that?, thank you Niyas

Tri Nanda
Penulis

Hello @Niyas, how is it going?, I hope you doing well,

after keep trying in this, finally I can change my state on my other module if my invoice is paid Niyas, but that just if my invoice amount/total of payment is 0 Niyas,

there can't update my state on my other module if the created invoice amount or total is there is a price.

may you help me Niyas, please?

Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
Sales orders stay "in progress" after the invoice is paid
invoice state paid
Avatar
1
Mar 15
11074
AttributeError("The 'Customer' object does not have the 'create_message' attribute") Diselesaikan
invoice v14
Avatar
Avatar
1
Apr 24
2684
how to create customer invoice from code odoo 14 Diselesaikan
invoice v14
Avatar
Avatar
Avatar
Avatar
3
Okt 23
9146
Manual Invoice Sequence Diselesaikan
invoice v14
Avatar
Avatar
1
Sep 21
4019
How to validate the invoice invoice? Diselesaikan
invoice invoice_state
Avatar
Avatar
1
Okt 17
4611
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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