diff --git a/addons/stock/tests/test_warehouse.py b/addons/stock/tests/test_warehouse.py index bcffba2509db7e1a24895ab5780d70c15f34b64f..e793b323b984858b9cef3b951cbe53d8ca227002 100644 --- a/addons/stock/tests/test_warehouse.py +++ b/addons/stock/tests/test_warehouse.py @@ -74,7 +74,6 @@ class TestWarehouse(TestStockCommon): # TDE TODO: expand this test def test_basic_move(self): - # TDE NOTE: replaces test/move.yml present until saas-10, including onchanges product = self.product_3.sudo(self.user_stock_manager) product.type = 'product' picking_out = self.env['stock.picking'].create({ diff --git a/addons/stock_account/__init__.py b/addons/stock_account/__init__.py index 2ae6446f9dc25fe7563ce0c6a4f1cc4904124cc5..833007351803273d0e1eaaeaea56e5140e8e5923 100644 --- a/addons/stock_account/__init__.py +++ b/addons/stock_account/__init__.py @@ -3,3 +3,89 @@ from . import models 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 + properties = env['ir.property'].search([ + ('name', '=', 'property_stock_journal'), + ('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', '=', _('Stock Journal')), + ('company_id', '=', company_id.id), + ('type', '=', 'general')], limit=1).id + if not journal_id: + journal_id = env['account.journal'].create({ + 'name': _('Stock Journal'), + 'type': 'general', + 'code': 'STJ', + 'company_id': company_id.id, + 'show_on_dashboard': False + }).id + vals = { + 'name': 'property_stock_journal', + 'fields_id': 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) + } + env['ir.property'].create(vals) + + # Property Stock Accounts + todo_list = [ + '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 = 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, + 'res_id': 'product.category,'+str(env.ref('product.product_category_all').id), + } + properties = env['ir.property'].search([ + ('name', '=', record), + ('company_id', '=', company_id.id), + ('value_reference', '!=', False)]) + if not properties: + # create the property + env['ir.property'].create(vals) + + if not tools.config['without_demo']: + account_id = env['account.account'].search([('tag_ids', '=', env.ref('account.demo_stock_account').id)], limit=1).id + fields_id = env['ir.model.fields'].search([('model', '=', 'product.category'), ('name', '=', 'property_stock_valuation_account_id')], limit=1).id + if not account_id: + account_id = env['account.account'].search([('user_type_id', '=', env.ref('account.data_account_type_current_assets').id)], limit=1).id + if account_id: + vals = { + 'name': 'property_stock_valuation_account_id', + 'fields_id': fields_id, + 'value': 'account.account,'+str(account_id), + 'company_id': env.ref('base.main_company').id, + } + env['ir.model.data']._update('ir.property', 'stock_account', vals, 'property_stock_valuation_account_id') diff --git a/addons/stock_account/__manifest__.py b/addons/stock_account/__manifest__.py index d3b7ebdf7730241df3673f385506287e1a355d07..b64e93af1fdd2a6db261afb45830662fc3c7d7ba 100644 --- a/addons/stock_account/__manifest__.py +++ b/addons/stock_account/__manifest__.py @@ -23,9 +23,6 @@ Dashboard / Reports for Warehouse Management includes: 'depends': ['stock', 'account'], 'category': 'Hidden', 'sequence': 16, - 'demo': [ - 'data/stock_account_demo.yml' - ], 'data': [ 'security/stock_account_security.xml', 'security/ir.model.access.csv', @@ -35,10 +32,10 @@ Dashboard / Reports for Warehouse Management includes: 'views/res_config_settings_views.xml', 'data/product_data.xml', 'views/product_views.xml', - 'data/stock_account_data_post_install.yml', ], 'test': [ ], 'installable': True, 'auto_install': True, + 'post_init_hook': '_configure_journals', } diff --git a/addons/stock_account/data/stock_account_data_post_install.yml b/addons/stock_account/data/stock_account_data_post_install.yml deleted file mode 100644 index 332c995f708e049d79bc66932aa8de0b29cb9b5f..0000000000000000000000000000000000000000 --- a/addons/stock_account/data/stock_account_data_post_install.yml +++ /dev/null @@ -1,62 +0,0 @@ -- - 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)]).ids - for company_id in company_ids: - from odoo.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)]) - 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), ('type', '=', 'general')], limit=1).id - if not journal_id: - journal_id = AccountJournal.create({ - 'name': _('Stock Journal'), - 'type': 'general', - 'code': 'STJ', - 'company_id': company_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, - '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', - ] - company = company_obj.browse(company_id) - for record in todo_list: - account = getattr(company, 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, - 'fields_id': field_id, - 'value': value, - 'res_id': 'product.category,'+str(ref('product.product_category_all')), - } - properties = PropertyObj.search([('name', '=', record), ('company_id', '=', company.id), ('value_reference', '!=', False)]) - if not properties: - #create the property - PropertyObj.create(vals) diff --git a/addons/stock_account/data/stock_account_demo.yml b/addons/stock_account/data/stock_account_demo.yml deleted file mode 100644 index 0621c20f94911186423db29f6790f595f95a4b79..0000000000000000000000000000000000000000 --- a/addons/stock_account/data/stock_account_demo.yml +++ /dev/null @@ -1,16 +0,0 @@ -- - Setting property field -- - !python {model: ir.model.data, id: False} : | - account_id = self.env['account.account'].search([('tag_ids', 'in', [ref('account.demo_stock_account')])], limit=1).id - fields_id = self.env['ir.model.fields'].search([('model','=','product.category'),('name','=','property_stock_valuation_account_id')], limit=1).id - if not account_id: - account_id = self.env['account.account'].search([('user_type_id', '=', ref('account.data_account_type_current_assets'))], limit=1).id - if account_id: - vals = { - 'name': 'property_stock_valuation_account_id', - 'fields_id': fields_id, - 'value': 'account.account,'+str(account_id), - 'company_id': ref('base.main_company'), - } - self._update('ir.property', 'stock_account', vals, 'property_stock_valuation_account_id')