跳至内容
菜单
此问题已终结
1 回复
8661 查看

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.  

形象
丢弃
最佳答案

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.



形象
丢弃

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.

相关帖文 回复 查看 活动
3
12月 19
9214
1
10月 19
6802
2
6月 23
1947
3
7月 19
4436
1
3月 19
4092