diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/stock_account/__init__.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/stock_account/__init__.py')
| -rw-r--r-- | addons/stock_account/__init__.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/addons/stock_account/__init__.py b/addons/stock_account/__init__.py new file mode 100644 index 00000000..fd3f4a2e --- /dev/null +++ b/addons/stock_account/__init__.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models +from . import report +from . import wizard + +from odoo import api, SUPERUSER_ID, _, tools + +def _configure_journals(cr, registry): + """Setting journal and property field (if needed)""" + + env = api.Environment(cr, SUPERUSER_ID, {}) + + # if we already have a coa installed, create journal and set property field + company_ids = env['res.company'].search([('chart_template_id', '!=', False)]) + + for company_id in company_ids: + # Check if property exists for stock account journal exists + field = env['ir.model.fields']._get("product.category", "property_stock_journal") + properties = env['ir.property'].sudo().search([ + ('fields_id', '=', field.id), + ('company_id', '=', company_id.id)]) + + # 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 = env['account.journal'].search([ + ('name', '=', _('Inventory Valuation')), + ('company_id', '=', company_id.id), + ('type', '=', 'general')], limit=1).id + if not journal_id: + journal_id = env['account.journal'].create({ + 'name': _('Inventory Valuation'), + 'type': 'general', + 'code': 'STJ', + 'company_id': company_id.id, + 'show_on_dashboard': False + }).id + env['ir.property']._set_default( + 'property_stock_journal', + 'product.category', + journal_id, + company_id, + ) + + # Property Stock Accounts + todo_list = [ + 'property_stock_account_input_categ_id', + 'property_stock_account_output_categ_id', + 'property_stock_valuation_account_id', + ] + + for name in todo_list: + account = getattr(company_id, name) + if account: + env['ir.property']._set_default( + name, + 'product.category', + account, + company_id, + ) |
