Skip to content
Snippets Groups Projects
Commit de1556ac authored by Josse Colpaert's avatar Josse Colpaert
Browse files

[FIX] stock_account: Post install should check for all companies and not always create

The method will check all companies with a chart of account if they have a property for the stock journal.
If there is no stock journal it will create one.  Previously it created only one for the main company and this
gave an error when updating the module again
parent 4716664d
No related branches found
No related tags found
No related merge requests found
......@@ -3,19 +3,26 @@
-
!python {model: account.journal} : |
#if we already have a coa installed, create journal and set property field
company_id = ref('base.main_company')
if self.pool.get('res.company').browse(cr, uid, company_id).chart_template_id:
company_obj = self.pool['res.company']
company_ids = company_obj.search(cr, uid, [('chart_template_id', '!=', False)])
for company_id in company_ids:
from openerp.tools.translate import _
journal_id = self.create(cr, uid, {'name': _('Stock Journal'), 'type': 'general', 'code': 'STJ', 'show_on_dashboard': False,})
#update property
#Check if property exists for stock account journal exists
PropertyObj = self.pool.get('ir.property')
properties = PropertyObj.search(cr, uid, [('name', '=', 'property_stock_journal'), ('company_id', '=', company_id)])
vals = {'name': 'property_stock_journal',
'fields_id': self.pool.get('ir.model.fields').search(cr, uid, [('name', '=', 'property_stock_journal'), ('model', '=', 'product.category'), ('relation', '=', 'account.journal')], limit=1)[0],
'company_id': company_id,
'value': 'account.journal,' + str(journal_id)}
if properties:
PropertyObj.write(cr, uid, properties, vals)
else:
#create the property
AccountJournal = self.pool.get('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_ids = AccountJournal.search(cr, uid, [('name', '=', _('Stock Journal')), ('company_id', '=', company_id), ('type', '=', 'general')])
if journal_ids:
journal_id = journal_ids[0]
else:
journal_id = AccountJournal.create(cr, uid, {'name': _('Stock Journal'), 'type': 'general', 'code': 'STJ', 'company_id': company_id, 'show_on_dashboard': False})
vals = {'name': 'property_stock_journal',
'fields_id': self.pool.get('ir.model.fields').search(cr, uid, [('name', '=', 'property_stock_journal'), ('model', '=', 'product.category'), ('relation', '=', 'account.journal')], limit=1)[0],
'company_id': company_id,
'value': 'account.journal,' + str(journal_id)}
PropertyObj.create(cr, uid, vals)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment