Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
2 Besvarelser
5238 Visninger

I created sale order in odoo 15:

 

custom_sale_order_id = models.execute_kw(db,uid, password,'sale.order', 'create',

                                    [{

                                    'company_id': int(custom_company_id),  

                                    'create_date': custom_actual_date,

                                    'create_uid': custom_create_uid,

                                    'currency_id': custom_currency_id,

                                    'date_order': custom_actual_date,

                                    'partner_id': custom_partner_id,                                      

                                    'payment_term_id': int(custom_payment_term_id), 

                                    'pricelist_id': int(custom_pricelist_id),

                                    'team_id': int(custom_crm_team),  

                                    'state': custom_sale_order_state,

                                    'invoice_status': custom_sale_order_invoice_status,

                                    'warehouse_id': custom_warehouse_id,

                                    }])

 

and 

 

custom_sale_order_line_id = models.execute_kw(db,uid, password,'sale.order.line', 'create',

                                    [{

                                    'create_date': custom_actual_date,

                                    'create_uid': custom_create_uid,

                                    'currency_id': custom_currency_id,

                                    'order_partner_id': custom_partner_id,

                                    'product_id': custom_product_id,

                                    'product_uom': int(custom_product_uom),

                                    'product_uom_qty': custom_product_qty,

                                    'qty_delivered': custom_product_qty,

                                    'order_id': custom_sale_order_id,

                                    'state': custom_sale_order_state,

                                    'invoice_status': custom_sale_order_invoice_status,

                                    }])

 

 

I’m struggling to automatically create the corresponding invoice to that sales order via xmlrpc. From sale order there is no method to create invoices.

Avatar
Kassér

There is 2 options to do it: 

1) Call the same method that Odoo uses when you press the "Create Invoice" Button on and already created sales order. (Recommend)

2) Insert the data manually through the 'env' object in 'self' (You will have to do everything by your own throw a method in your model and call it from a button)

move_dict = {
'narration': "Name",
'ref': name,
'journal_id': journal_id.id,
'date': date,
}
line_ids = []

debit_line = {
'name': "Name",
'partner_id': partner_id.id,
'account_id': debit_account_id.id,
'journal_id': journal_id.id,
'date': date,
'debit': round(amount if amount > 0.0 else -amount),
'credit': 0.0,
'analytic_account_id': analytic_account_id,
'tax_line_id': tax_account_id,
}

credit_line = {
'name': "Name",
'partner_id': partner_id.id,
'account_id': credit_account_id.id,
'journal_id': journal_id.id,
'date': date,
'debit': 0.0,
'credit': round(amount if amount > 0.0 else -amount),
'analytic_account_id': analytic_account_id.id,
'tax_line_id': tax_account_id.id,
}

line_ids.append(debit_line)
line_ids.append(credit_line)
move_dict['line_ids'] = line_ids
move = self.env['account.move'].create(move_dict)
move.post()



Happy to help :) an upvote will be awesome

Bedste svar

I encountered the same issue, and here's my solution.

I understand that you want to achieve the equivalent of the following code using the XML-RPC API:

payment = self.env ["sale.advance.payment.inv"].create ({})
payment.with_context (active_ids = sale_id).create_invoices ()
1) Creating the payment:
payment = models.execute_kw(db, uid, password, 'sale.advance.payment.inv', 'create', [{
    'advance_payment_method': 'delivered',
    'create_uid': custom_create_uid,
    'currency_id': int(custom_currency_id),
    'deduct_down_payments': True,
    'deposit_account_id': False,
    'fixed_amount': 0.0,
    'has_down_payments': False,
    'write_uid': custom_create_uid,
}])

2) Creating an invoice:
payment_id = 111  # Replace with the payment ID
order_id = 222  # Replace with the sale.order ID

context = {'active_ids': [order_id]}
result = models.execute_kw(db, uid, password, 'sale.advance.payment.inv', 'create_invoices', [payment_id], {'context': context})


I hope you solved your problem beforehand or that it will help other people.

Avatar
Kassér
Forfatter Bedste svar

Thanks a lot for your answer. I tried option 1, also to automatically create a reference from the invoice to the underlying sales order:


First I create a “sale_advance_payment_inv” record:


        payment = models.execute_kw(db,uid, password,'sale.advance.payment.inv', 'create',

                                    [{

                                    'advance_payment_method': 'delivered',  

                                    'create_uid': custom_create_uid,

                                    'currency_id': int(custom_currency_id),

                                    'deduct_down_payments': True,

                                    'deposit_account_id': False,

                                    'fixed_amount': 0.0,

                                    'has_down_payments': False,

                                    'write_uid': custom_create_uid,

                                    }])


  

Second I wanted to create an invoice from that record but it doesn’t work:


    models.execute_kw(db, uid, password, 'sale.advance.payment.inv', 'create_invoices', [payment],{'context': action['context']})



I got the following error message and I´m not able to fix the error:


xmlrpc.client.Fault: ...

Avatar
Kassér
Related Posts Besvarelser Visninger Aktivitet
2
dec. 22
3198
1
jul. 18
5235
0
jun. 15
3511
4
feb. 25
7240
1
jan. 25
1465