Skip to content
Snippets Groups Projects
Commit cbbd9c44 authored by Yannick Tivisse's avatar Yannick Tivisse
Browse files

[IMP] stock_account: Convert yml files to python and xml

parent bdbc7a62
No related branches found
No related tags found
No related merge requests found
......@@ -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({
......
......@@ -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')
......@@ -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',
}
-
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)
-
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')
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