Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
5053 Lượt xem

Hello,

Is it possible to update a record by installing a module?

i mean i just want to update the record once  the module installed

here's my  function:

def _default_pos_receivable_account(self):
for record in self:
account_default_pos_receivable_account_id = self.env['account.account'].search([('code', '=', '772600')],
limit=1)
self.write({'account_default_pos_receivable_account_id': account_default_pos_receivable_account_id})
return record

but when i install it nothing happens, is there any other steps that i should do?
Thanks
Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Thanks, i solved it by pre_init_hook

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello Ali,

Yes, It is possible to update a record on module installation. 

1. You can call such python functions by pre_init_hook and update the record using database cursor

\https://www.odoo.com/documentation/master/reference/module.html

pre_init_hook takes a cursor as its only argument, this function is executed prior to the module's installation.

2. If you wish to change any property or module data, You can also do it by creating new data record with same reference id along with module name. 

<record id="base.main_company" model="res.company">

<field name="account_default_pos_receivable_account_id" model="account.account" search="[('code','=','772600')]" />

</record>

Hope this will help you


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
5
thg 12 23
50384
2
thg 6 24
6330
2
thg 5 24
6528
2
thg 3 24
1324
1
thg 12 22
9017