During configure journals and to set property stock journal from stock account , will try to create xmlid to existing records to avoid duplicate journal codes. but there are some existing code journal for inventory valuation already exists. so if already journal with `STJ` and with same company exist then will avoid to create new journal of same code. ``` psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "account_journal_code_company_uniq" DETAIL: Key (company_id, code)=(1, STJ) already exists. ``` closes odoo/odoo#128639 X-original-commit: 6d6a6530bc43f289f8a811347e0ddd7053b5651c Signed-off-by: William Henrotin (whe) <whe@odoo.com>
42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from . import models
|
|
from . import report
|
|
from . import wizard
|
|
|
|
|
|
def _configure_journals(env):
|
|
# if we already have a coa installed, create journal and set property field
|
|
for company in env['res.company'].search([('chart_template', '!=', False)]):
|
|
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 [
|
|
'property_stock_journal',
|
|
'property_stock_account_input_categ_id',
|
|
'property_stock_account_output_categ_id',
|
|
'property_stock_valuation_account_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)
|
|
ChartTemplate._load_data(data)
|
|
ChartTemplate._post_load_data(template_code, company, template_data)
|