تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
10 الردود
9808 أدوات العرض

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()


الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
أفضل إجابة

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.

الصورة الرمزية
إهمال
الكاتب

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.

الكاتب

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

الكاتب

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

أفضل إجابة

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.

الصورة الرمزية
إهمال
أفضل إجابة

Hi.

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



الصورة الرمزية
إهمال
الكاتب

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.

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أغسطس 19
2927
1
سبتمبر 17
3549
2
سبتمبر 17
8340
0
أبريل 22
2844
1
ديسمبر 18
4520