İçereği Atla
Menü
Bu soru işaretlendi
10 Cevaplar
9750 Görünümler

I created invoice through a customized button, and wanted that 'open' will be automatically it's state once it's created. Current output, 'paid' is the state. Hope you can help me, thank you.

Here's my code:

    @api.multi

    def create_invoice(self,count):

        # print 'create_invoice'

        customer = self.partner_id.id

        product = self.env['product.template'].search([('default_code', '=', 'HOST')]) 

        account_id = self.env['account.account'].search([('internal_type','=','receivable')]).id

        journal_id = self.env['account.journal'].search([('code','=','INV')]).id


        # create invoice

        invoice_header = self.env['account.invoice'].create({

            'partner_id': customer,

            # 'number': self.get_invoice_sequence(),

            # 'date_invoice': today_date,

            'account_id': account_id,

            'journal_id': journal_id,

            'user_id': self.env.user.id,

        })

        invoice_lines = self.env['account.invoice.line'].create({

            'invoice_id': invoice_header.id,

            'product_id': product[0].id,

            'name':product[0].name,

            'quantity': count,

            'price_unit': product[0].list_price,

            'account_id': account_id,

        })

        invoice_header.action_invoice_open()


Avatar
Vazgeç
En İyi Yanıt

When creating an invoice thru code on odoo, even though the default state is draft, i think that you will need to pass that again in your dict as follows,

      # create invoice

        invoice_header = self.env['account.invoice'].create({

            'partner_id': customer,

            # 'number': self.get_invoice_sequence(),

            # 'date_invoice': today_date,

            'account_id': account_id,

            'journal_id': journal_id,

            'user_id': self.env.user.id,

            'state': 'draft',

        })

After that call the action as you did before in your code and it will be okay:

invoice_header.action_invoice_open()

If there are other issues when this invoice is created, you can always inherit the action_invoice_open def and make your changes in the function itself to avoid complications.

Just make sure to call it with super so that other things get calculated as well.


I hope it is helpfull

Riste Kabranov

Odoo developer at simplify-erp.com

Avatar
Vazgeç
En İyi Yanıt

Hi,

An open invoice with total amount  zero or is reconciled with full payment will be automatically converted to paid state.

Make sure your invoice's total amount is not zero and you are not creating any payment for this invoice.

Avatar
Vazgeç
Üretici

Hello, I see that invoice that I create is reconciled. how can I make it to false? even though I assigned it to false, it automatically becomes false. Is there anything that triggers reconciled to true?

I think the code you provided cannot trigger a payment creation or reconcile.

Also check how a payment is created against the customer in the invoice.

Üretici

I really appreciate your help, can you please give me a sample code where it can trigger a payment creation or reconcile? thank you.

Journal entry for the invoice is called inside function action_invoice_open(), payment creation is maintained in validate button click in register payment wizard. Check if you have edited any of these files

Üretici

once I clicked validate, it doesn't go to register payment, instead, it's already in 'paid' state.

En İyi Yanıt

Hello,

If you call validate button it will create one Journal entry for that invoice.

If the Journal entry  having debit and credit accounts both are payable/receivable then the invoice due amount is zero, so invoice moved to paid state.

Note : Either debit account or credit account only payable/receivable but not both.

Avatar
Vazgeç
En İyi Yanıt

Hi.

Did you get a solution?... I am having the same problem...The invoice is getting the paid state instead of open state.



Avatar
Vazgeç
Üretici

I removed the journal_id in the create of invoice_header, because it would automatically create it's journal_id

Hi Raul, please check your accounting configuration in "Customer Invoice" Journal.

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Ağu 19
2879
1
Eyl 17
3520
2
Eyl 17
8286
0
Nis 22
2805
1
Ara 18
4457