mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-24 16:42:09 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -1,61 +1,82 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields
|
||||
|
||||
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)"""
|
||||
def _post_init_hook(env):
|
||||
_configure_journals(env)
|
||||
_create_product_value(env)
|
||||
_configure_stock_account_company_data(env)
|
||||
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
|
||||
def _create_product_value(env):
|
||||
product_vals_list = []
|
||||
products = env['product.product'].search([('type', '=', 'consu')])
|
||||
for company in env['res.company'].search([]):
|
||||
products = products.with_company(company)
|
||||
product_vals_list += [
|
||||
{
|
||||
'product_id': product.id,
|
||||
'value': product.standard_price,
|
||||
'date': fields.Date.today(),
|
||||
'company_id': company.id,
|
||||
'description': 'Initial cost',
|
||||
}
|
||||
for product in products if not product.company_id or product.company_id == company
|
||||
]
|
||||
env['product.value'].create(product_vals_list)
|
||||
|
||||
|
||||
def _configure_journals(env):
|
||||
# if we already have a coa installed, create journal and set property field
|
||||
company_ids = env['res.company'].search([('chart_template_id', '!=', False)])
|
||||
todo_list = [
|
||||
'property_stock_account_input_categ_id',
|
||||
'property_stock_account_output_categ_id',
|
||||
'property_stock_valuation_account_id',
|
||||
]
|
||||
# Property Stock Accounts
|
||||
categ_values = {category.id: False for category in env['product.category'].search([])}
|
||||
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)])
|
||||
for company in env['res.company'].search([('chart_template', '!=', False)], order="parent_path"):
|
||||
ChartTemplate = env['account.chart.template'].with_company(company)
|
||||
template_code = company.chart_template
|
||||
full_data = ChartTemplate._get_chart_template_data(template_code)
|
||||
data = {
|
||||
'template_data': {
|
||||
fname: value
|
||||
for fname, value in full_data['template_data'].items()
|
||||
if fname in [
|
||||
'stock_journal',
|
||||
'stock_valuation_account_id',
|
||||
]
|
||||
}
|
||||
}
|
||||
data['res.company'] = {company.id: {
|
||||
'account_stock_journal_id': full_data['res.company'][company.id].get('account_stock_journal_id'),
|
||||
'account_stock_valuation_id': full_data['res.company'][company.id].get('account_stock_valuation_id'),
|
||||
}}
|
||||
|
||||
# If not, check if you can find a journal that is already there with the same code, otherwise create one
|
||||
if not properties:
|
||||
journal_id = env['account.journal'].search([
|
||||
('code', '=', 'STJ'),
|
||||
('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,
|
||||
)
|
||||
template_data = data.pop('template_data')
|
||||
journal = env['account.journal'].search([
|
||||
('code', '=', 'STJ'),
|
||||
('company_id', '=', company.id),
|
||||
('type', '=', 'general')], limit=1)
|
||||
if journal:
|
||||
env['ir.model.data']._update_xmlids([{
|
||||
'xml_id': f"account.{company.id}_inventory_valuation",
|
||||
'record': journal,
|
||||
'noupdate': True,
|
||||
}])
|
||||
else:
|
||||
data['account.journal'] = ChartTemplate._get_stock_account_journal(template_code)
|
||||
|
||||
for name in todo_list:
|
||||
account = getattr(company_id, name)
|
||||
if account:
|
||||
env['ir.property']._set_default(
|
||||
name,
|
||||
'product.category',
|
||||
account,
|
||||
company_id,
|
||||
)
|
||||
env['ir.property'].with_company(company_id.id)._set_multi(name, 'product.category', categ_values, True)
|
||||
ChartTemplate._load_data(data)
|
||||
ChartTemplate._post_load_data(template_code, company, template_data)
|
||||
|
||||
|
||||
def _configure_stock_account_company_data(env):
|
||||
for company in env['res.company'].search([('chart_template', '!=', False)], order="parent_path"):
|
||||
ChartTemplate = env['account.chart.template'].with_company(company)
|
||||
template_code = company.chart_template
|
||||
res_company_data = ChartTemplate._get_stock_account_res_company(template_code)
|
||||
account_account_data = ChartTemplate._get_stock_account_account(template_code)
|
||||
ChartTemplate._load_data({
|
||||
'res.company': res_company_data,
|
||||
'account.account': account_account_data,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue