IMP l10n_us_hr_payroll Don't try to migrate rule accounting if the fields don't exist

This commit is contained in:
Jared Kipe
2020-01-10 07:02:02 -08:00
parent 3ec63381b2
commit 494c8db4cb

View File

@@ -76,14 +76,18 @@ def migrate(cr, installed_version):
# Some added rules should have the same accounting side effects of other migrated rules
# To ease the transition, we will copy the accounting fields from one to the other.
for source, destinations in XMLIDS_COPY_ACCOUNTING_2020.items():
source_rule = env.ref(source, raise_if_not_found=False)
if source_rule:
for destination in destinations:
destination_rule = env.ref(destination, raise_if_not_found=False)
if destination_rule:
_logger.warn('Mirgrating accounting from rule: ' + source + ' to rule: ' + destination)
destination_rule.write({
'account_debit': source_rule.account_debit.id,
'account_credit': source_rule.account_credit.id,
})
rule_model = env['hr.salary.rule']
if hasattr(rule_model, 'account_debit'):
for source, destinations in XMLIDS_COPY_ACCOUNTING_2020.items():
source_rule = env.ref(source, raise_if_not_found=False)
if source_rule:
for destination in destinations:
destination_rule = env.ref(destination, raise_if_not_found=False)
if destination_rule:
_logger.warn('Mirgrating accounting from rule: ' + source + ' to rule: ' + destination)
destination_rule.write({
'account_debit': source_rule.account_debit.id,
'account_credit': source_rule.account_credit.id,
'account_tax_id': source_rule.account_tax_id.id,
'analytic_account_id': source_rule.analytic_account_id.id,
})