- Setting journal and property field (if needed) - !python {model: account.journal, id: False} : | #if we already have a coa installed, create journal and set property field company_obj = self.env['res.company'] company_ids = company_obj.search([('chart_template_id', '!=', False)]) for company_id in company_ids: from flectra.tools.translate import _ #Check if property exists for stock account journal exists PropertyObj = self.env['ir.property'] properties = PropertyObj.search([('name', '=', 'property_stock_journal'), ('company_id', '=', company_id.id)]) AccountJournal = self.env['account.journal'] #If not, check if you can find a journal that is already there with the same name, otherwise create one if not properties: journal_id = AccountJournal.search([('name', '=', _('Stock Journal')), ('company_id', '=', company_id.id), ('type', '=', 'general')], limit=1).id if not journal_id: journal_id = AccountJournal.create({ 'name': _('Stock Journal'), 'type': 'general', 'code': 'STJ', 'company_id': company_id.id, 'branch_id': company_id.branch_id.id, 'show_on_dashboard': False }).id vals = {'name': 'property_stock_journal', 'fields_id': self.env['ir.model.fields'].search([ ('name', '=', 'property_stock_journal'), ('model', '=', 'product.category'), ('relation', '=', 'account.journal')], limit=1).id, 'company_id': company_id.id, 'value': 'account.journal,' + str(journal_id)} PropertyObj.create(vals) todo_list = [ # Property Stock Accounts 'property_stock_account_input_categ_id', 'property_stock_account_output_categ_id', 'property_stock_valuation_account_id', ] for record in todo_list: account = getattr(company_id, record) value = account and 'account.account,' + str(account.id) or False if value: field_id = self.env['ir.model.fields'].search([ ('name', '=', record), ('model', '=', 'product.category'), ('relation', '=', 'account.account') ], limit=1).id vals = { 'name': record, 'company_id': company_id.id, 'fields_id': field_id, 'value': value, } properties = PropertyObj.search([('name', '=', record), ('company_id', '=', company_id.id)], limit=1) if not properties: # create the property PropertyObj.create(vals) elif not properties.value_reference: # update the property if False properties.write(vals)