This question has been flagged
2 Replies
2344 Views

Hi, I develop under odoo 15. 

I have already created a module of entities "entities" management (Customers, Vondors, Products, ...), and now I am creating an invoincing "invoice" module.


For the moment, in the "invoice" module, I have created a model "invoice_temporary.py" to collect all the data needed for an invoice from the "entities" models.


So now I plan to create the real invoice (which respects the condition of inalterability) from the "invoice_temporary" model.

With this model, I have all the data needed for the real invoice, so I ask here :

"How can I create an inalterable invoice from a simple model ?"

"Should I create the invoice in another way ?"


Thanks in advance, I tried to be as clear as possible,

Hugo


Avatar
Discard
Author

Hi, and thanks for the answer,

For the first link you gave me (the other forum answer), I understand how the function works, but not how to use it. I mean that I don't know where (in which file ?) to put it, I tried to place it in the model itself, but I don't know how to use it after it has been declared.

Could you please help me to know in which file i have to place the function, and then how and where do I call it ?

Thank you

Best Answer

Hi Hugo,

Check this existing forum answer : https://www.odoo.com/forum/help-1/create-invoice-by-code-odoo14-190183

And for creating record from odoo code ,refer: https://www.youtube.com/watch?v=Jssb15ADeyg 

Hope this will help you 

Thank you




Avatar
Discard
Best Answer

Hello Hugo,

If you want to create Invoice from the model "invoice_temporary",

Simply add a button in form view and call its function on your .py file

.xml

<button name="create_invoice" class="oe_highlight" string="Invoice" type="object"/>


 .py

def create_invoice(self):
for record in self:
delivey_invoice = self.env['account.move'].create([
{
'move_type': 'out_invoice',
'invoice_date': fields.Date.context_today(record),
'partner_id': record.partner_id.id,
'currency_id': record.currency_id.id,
'amount_total': self.delivery_total,
'invoice_line_ids': [
(0, None, {
'product_id': 1,
'name': 'Delivery Service',
'quantity': 1,
'price_unit': record.delivery_total,
'price_subtotal': record.delivery_total,
}),
],
},
])
delivey_invoice.action_post()


Regards

Avatar
Discard