Skip to Content
Menu
This question has been flagged
1 Reply
7252 Views

I want my customers to have a specific payment option when they install my custom module, I've looked everywhere for examples to add a journal / payment option through code and can only find people adding it through the GUI, which is a no-go for me.


Are there any examples out there or a hidden guide? I've been stuck for days on this issue.


Cheers.  

Avatar
Discard
Best Answer

A journal is just like any other Odoo model or class.

You can create an instance of a model (record in a class/table) three ways in your own module:

  • Via code

  • Via XML

  • Via CSV


Each option does exactly the same thing - create  a record in the database.  No matter how it gets there, the result is the same (even when added via the UI).


Code:

vals = {
'name': 'The Name',
'code': 'THECODE',
...
}

self.env[account.journal].create(vals)

More at https://www.odoo.com/documentation/10.0/reference/orm.html#common-orm-methods


XML:

Supply an XML file that imports a record into the database:

<odoo>
    <data>
   
 
<record id="your_id" model="account.journal"> <field name="name">The Name</field>
<field name="code">THECODE</field>
...
</record>
 
</data> </odoo>

More at https://www.odoo.com/documentation/10.0/reference/data.html


CSV:

Supply a file called 'account.journal.csv' in your module with the fields and values you want to import.  You can export an existing Journal to see the schema for the CSV file:

"id", "name", "code", "company_id/id", ...
"your_id", "The Name", "THECODE", "base.main_company", ...

More at https://www.odoo.com/documentation/10.0/reference/data.html#csv-data-files


Note: Since a Journal also requires a sequence, you should also create one of those, before creating the Journal, so the Journal can refer to it.



Avatar
Discard

What a beautiful answer!

How do I create same journal for all companies in Database ? There can be any number of companies in Database for eg. there can be 1 or 2 or 4 companies depending on database so I want to create same journal for all companies available in Database.

Related Posts Replies Views Activity
3
Dec 19
8347
1
Oct 19
5624
2
Jun 23
1141
3
Jul 19
3604
1
Mar 19
3231