Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
5 Răspunsuri
6803 Vizualizări

Hello Experts,    

I am trying to generate vendor bills from the custom module. but code is inserting/creating bills in the customer invoice.  Following is the code which i am using. Can you please guide where i am doing wrong.

@api.multi

    def create_invoices(self):

        self.state = 'create_invoices'

        inv_obj = self.env['account.invoice']

        inv_line_obj = self.env['account.invoice.line']

        vendor = self.vendor_id

        if not vendor.name:

            raise UserError(

                _(

                    'Please select a Vendor Name.'))

        company_id = self.env['res.users'].browse(1).company_id

        currency_value = company_id.currency_id.id

        self.ensure_one()

        ir_values = self.env['ir.values']

        journal_id = ir_values.get_default('cust.mod', 'invoice_journal_type')

        if not journal_id:

            journal_id = 1


        inv_data = {

            'name': vendor.name,

            'reference': self.name,

            'account_id': vendor.property_account_payable_id.id,

            'partner_id': vendor.id,

            'currency_id': currency_value,

            'journal_id': journal_id,

            'origin': self.name,

            'company_id': company_id.id,

        }

        inv_id = inv_obj.create(inv_data)

        for records in self.cust_line:

            if records.exp_id.product_id :

                expense_account = records.exp_id.product.property_account_expense_id.id

            if not expense_account:

                raise UserError(_('There is no expense account defined for this product: "%s".') %

                                (records.exp_id.product.name,))


            inv_line_data = {

                'name': records.exp_id.product.name,

                'account_id': expense_account,

                'price_unit': records.amount,

                'quantity': 1,

                'product_id': records.exp_id.product.product_id,

                'invoice_id': inv_id.id,

            }

            inv_line_obj.create(inv_line_data)

in xml using button code to generate vendor bill.

Imagine profil
Abandonează
Cel mai bun răspuns

Hello, 

pass the type of the invoice while you create invoice.

see into below dictionary.

 inv_data = {
'type': 'in_invoice',
            'name': vendor.name,
            'reference': self.name,
            'account_id': vendor.property_account_payable_id.id,
            'partner_id': vendor.id,
            'currency_id': currency_value,
            'journal_id': journal_id,
            'origin': self.name,
            'company_id': company_id.id,
        }
Imagine profil
Abandonează

what if i want to add lines to invoice lines !!!!!!!!!

into inv_data dictionary add the key and value like

{'invoice_line_ids': [(0, 0, inv_line_vals)]

Cel mai bun răspuns

you missed type field In Invoice Data .

'type': 'in_invoice'  means Vendor bill
'type': 'out_invoice' means Customer Invoice

By default it's  'out_invoice', so it's creating Customer Invoice

Imagine profil
Abandonează
Cel mai bun răspuns


 inv_data = {
'type': 'in_invoice',
            'name': vendor.name,
            'reference': self.name,
            'account_id': vendor.property_account_payable_id.id,
            'partner_id': vendor.id,
            'currency_id': currency_value,
            'journal_id': journal_id,
            'origin': self.name,
            'company_id': company_id.id,

create a vender bill from purchase order
please tell me the answer as soon as possible.?



Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
oct. 18
3809
4
oct. 20
8875
0
mai 24
1458
3
feb. 24
10325
1
nov. 23
2766