[FIX] l10n_be: fix installation of module

The previous commit https://github.com/odoo/odoo/commit/7a31a92afa9a2ad280a6ec110fc9547e48b89466 removed the liquidity transfer account template to replace it with a system of prefix like we already had for bank/cash accounts. However, that transfer account template was used as account_id in an account.reconcile.model.template object.

To fix that, at the creation of chart template (using _update() of ir.model.data, because we need to have the module/xml_id reference) we create the account.account.template and its xml reference in ir_model_data table

Was OPW https://www.odoo.com/web?#id=1851523&action=333&active_id=1278&model=project.task&view_type=form&menu_id=
This commit is contained in:
qdp-odoo
2018-05-25 16:49:08 +02:00
parent 82592edaba
commit 98fa196e00
3 changed files with 49 additions and 31 deletions
+1 -2
View File
@@ -91,8 +91,7 @@ class AccountAccount(models.Model):
rec = self.search([('code', '=', new_code), ('company_id', '=', company.id)], limit=1)
if not rec:
return new_code
else:
raise UserError(_('Cannot generate an unused account code.'))
raise UserError(_('Cannot generate an unused account code.'))
def _compute_opening_debit_credit(self):
for record in self:
+47 -28
View File
@@ -124,6 +124,34 @@ class AccountChartTemplate(models.Model):
property_stock_account_output_categ_id = fields.Many2one('account.account.template', string="Output Account for Stock Valuation", oldname="property_stock_account_output_categ")
property_stock_valuation_account_id = fields.Many2one('account.account.template', string="Account Template for Stock Valuation")
@api.model
def _prepare_transfer_account(self):
''' Prepare values to create the transfer account that is an intermediary account used when moving money
from a liquidity account to another.
:param name: The transfer account name.
:param company: The company owning this account.
:return: A dictionary of values to create a new account.account.
'''
digits = self.code_digits
prefix = self.transfer_account_code_prefix or ''
new_code = ''
for num in range(1, 100):
new_code = str(prefix.ljust(digits - 1, '0')) + str(num)
rec = self.env['account.account.template'].search([('code', '=', new_code), ('chart_template_id', '=', self.id)], limit=1)
if not rec:
break
else:
raise UserError(_('Cannot generate an unused account code.'))
current_assets_type = self.env.ref('account.data_account_type_current_assets', raise_if_not_found=False)
return {
'name': _('Liquidity Transfer'),
'code': new_code,
'user_type_id': current_assets_type and current_assets_type.id or False,
'reconcile': True,
'chart_template_id': self.id,
}
@api.one
def try_loading_for_current_company(self):
self.ensure_one()
@@ -909,10 +937,6 @@ class WizardMultiChartsAccounts(models.TransientModel):
# Install all the templates objects and generate the real objects
acc_template_ref, taxes_ref = self.chart_template_id._install_template(company, code_digits=self.code_digits)
# Create Transfer account
transfer_account_vals = self._prepare_transfer_account(_('Liquidity Transfers'), company)
company.transfer_account_id = self.env['account.account'].create(transfer_account_vals)
# Create Bank journals
self._create_bank_journals_from_o2m(company, acc_template_ref)
@@ -924,30 +948,6 @@ class WizardMultiChartsAccounts(models.TransientModel):
company.account_purchase_tax_id = self.env['account.tax'].search([('type_tax_use', 'in', ('purchase', 'all')), ('company_id', '=', company.id)], limit=1).id
return {}
@api.model
def _prepare_transfer_account(self, name, company):
''' Prepare values to create the transfer account that is ani ntermediary account used when moving money
from a liquidity account to another.
:param name: The transfer account name.
:param company: The company owning this account.
:return: A dictionary of values to create a new account.account.
'''
digits = 6
acc = self.env['account.account'].search([('company_id', '=', company.id)], limit=1)
if acc:
digits = len(acc.code)
account_code_prefix = company.transfer_account_code_prefix or ''
current_assets_type = self.env.ref('account.data_account_type_current_assets', raise_if_not_found=False)
return {
'name': name,
'code': self.env['account.account']._search_new_account_code(company, digits, account_code_prefix),
'user_type_id': current_assets_type and current_assets_type.id or False,
'reconcile': True,
'company_id': company.id,
}
@api.multi
def _create_bank_journals_from_o2m(self, company, acc_template_ref):
'''
@@ -1005,3 +1005,22 @@ class AccountReconcileModelTemplate(models.Model):
], string="Second Amount type",required=True, default='percentage')
second_amount = fields.Float(string='Second Amount', digits=0, required=True, default=100.0, help="Fixed amount will count as a debit if it is negative, as a credit if it is positive.")
second_tax_id = fields.Many2one('account.tax.template', string='Second Tax', ondelete='restrict', domain=[('type_tax_use', '=', 'purchase')])
class IrModelData(models.Model):
_inherit = 'ir.model.data'
@api.model
def _update(self, model, module, values, xml_id=False, store=True, noupdate=False, mode='init', res_id=False):
record_id = super(IrModelData, self)._update(model, module, values, xml_id=xml_id, store=store, noupdate=noupdate, mode=mode, res_id=res_id)
# When creating a chart template create, for the liquidity transfer account
# - an account.account.template: this allow to define account.reconcile.model.template objects refering that liquidity transfer
# account although it's not existing in any xml file
# - an entry in ir_model_data: this allow to still use the method create_record_with_xmlid() and don't make any difference between
# regular accounts created and that liquidity transfer account
if model == 'account.chart.template' and xml_id and module:
new_xml_id = xml_id + '_liquidity_transfer'
if not self.search([('model', '=', 'account.account.template'), ('module', '=', module), ('name', '=', new_xml_id)]):
vals = self.env[model].browse(record_id)._prepare_transfer_account()
self._update('account.account.template', module, vals, xml_id=new_xml_id, store=True, noupdate=noupdate, mode=mode, res_id=False)
return record_id
@@ -27,8 +27,8 @@
</record>
<record id="virements_internes_template" model="account.reconcile.model.template">
<field name="chart_template_id" ref="l10nbe_chart_template"/>
<field name="account_id" search="[('code', '=like', obj().env.ref('l10n_be.l10nbe_chart_template').transfer_account_code_prefix + '%')]"/>
<field name="name">Virements internes</field>
<field name="account_id" ref="trans"/>
<field name="amount_type">percentage</field>
<field name="amount">100</field>
<field name="label">Virements internes</field>