DEV Community

Fohnbit
Fohnbit

Posted on

Odoo 17: Early Payment Discount

Hello!

I wrote small Odoo 17 codes for my one-man-company.

Are there a repository for all database fields?

For example:
I need all payments for an invoice. But I don´t know how to fetch this data from database.

Thanks

Top comments (3)

Collapse
 
fohnbit profile image
Fohnbit • Edited

Thank you!

I set a invoice as paid with:



                 payment_values = {
                        'date': date,
                        'amount': abs(invoice['ImportPaymentAmount']),
                        'payment_type': 'inbound',
                        'currency_id': invoice_id.currency_id.id,
                        'partner_id': invoice_id.partner_id.commercial_partner_id.id,
                        'partner_type': 'customer',
                        # 'move_id': invoice_id.id,
                        'journal_id': journal_id.id,
                        'company_id': journal_id.company_id.id,
                        'ref': rec['referenceNumber'],
                    }

                    payment = self.env['account.payment'].create(payment_values)
                    payment.action_post()


Enter fullscreen mode Exit fullscreen mode

This is working so far. But when there is an "early payment" with discount, then in Odoo he show me the invoice is just partial paid.

When I add the payment in the UI manual, then he show me korrekt the early payment option.

Collapse
 
becry1944 profile image
Catherine R. Longoria

Hello!

If you're working with Odoo 17 and need to fetch payments for an invoice, you can use the account.payment model. To get all payments linked to an invoice, you’ll want to check the payment_ids field in the account.move model (which handles invoices). This field holds the relationship between invoices and payments, so you can access all related payments through it.

As for a repository of all database fields, Odoo’s framework doesn’t have a public list, but you can explore the fields using Odoo’s developer mode. It allows you to inspect models and fields directly from the UI. Also, Odoo’s documentation can be a helpful resource.

By the way, if you're thinking about expanding your business, here's an interesting article on whether odoo for retail. It might provide some insights into how Odoo can benefit your operations as you grow.

Collapse
 
fohnbit profile image
Fohnbit

I double check in dev mode. The *payment_ids * in account.move are always empty. Even when the invoice is paid:

Image description

But when I open the payment:

Image description

I found an reconciled_invoice_ids in account.payment, which seems the ID from the invoice

But when I try to fetch all payments from invoice ID 25 with:



payment_ids = self.env['account.payment'].search([('reconciled_invoice_ids', '=', 25)])
                if payment_ids:
                    for payment in payment_ids:
                        logger.info(str(invoice['ImportInvoiceId']) + ' | ref: ' + payment.ref)  


Enter fullscreen mode Exit fullscreen mode

I get alle records. Guess it don´t search in an array?