Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DON'T MERGE][IMP] account: make the automatic entry wizard extendable #92

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 62 additions & 49 deletions addons/account/wizard/account_automatic_entry_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,65 @@ def _get_move_dict_vals_change_account(self):
'line_ids': [(0, 0, line) for line in line_vals],
}]

def _get_move_line_dict_vals_change_period(self, aml):
"""Returns a couple (new_date_lines, old_date_lines)"""
accrual_account = self.revenue_accrual_account if self.account_type == 'income' else self.expense_accrual_account

reported_debit = aml.company_id.currency_id.round(
(self.percentage / 100) * aml.debit)
reported_credit = aml.company_id.currency_id.round(
(self.percentage / 100) * aml.credit)
reported_amount_currency = aml.currency_id.round(
(self.percentage / 100) * aml.amount_currency)

new_date_lines = [
(0, 0, {
'name': aml.name or '',
'debit': reported_debit,
'credit': reported_credit,
'amount_currency': reported_amount_currency,
'currency_id': aml.currency_id.id,
'account_id': aml.account_id.id,
'partner_id': aml.partner_id.id,
'analytic_distribution': aml.analytic_distribution,
}),
(0, 0, {
'name': self._format_strings(
_('{percent:0.2f}% recognized on {new_date}'), aml.move_id),
'debit': reported_credit,
'credit': reported_debit,
'amount_currency': -reported_amount_currency,
'currency_id': aml.currency_id.id,
'account_id': accrual_account.id,
'partner_id': aml.partner_id.id,
'analytic_distribution': aml.analytic_distribution,
}),
]
old_date_lines = [
(0, 0, {
'name': aml.name or '',
'debit': reported_credit,
'credit': reported_debit,
'amount_currency': -reported_amount_currency,
'currency_id': aml.currency_id.id,
'account_id': aml.account_id.id,
'partner_id': aml.partner_id.id,
'analytic_distribution': aml.analytic_distribution,
}),
(0, 0, {
'name': self._format_strings(
_('{percent:0.2f}% to recognize on {new_date}'), aml.move_id),
'debit': reported_debit,
'credit': reported_credit,
'amount_currency': reported_amount_currency,
'currency_id': aml.currency_id.id,
'account_id': accrual_account.id,
'partner_id': aml.partner_id.id,
'analytic_distribution': aml.analytic_distribution,
}),
]
return new_date_lines, old_date_lines

def _get_move_dict_vals_change_period(self):
reference_move = self.env['account.move'].new({'journal_id': self.journal_id.id, 'move_type': 'entry'})

Expand All @@ -222,7 +281,6 @@ def get_lock_safe_date(aml):
return reference_move._get_accounting_date(aml.date, aml.move_id._affect_tax_report())

# set the change_period account on the selected journal items
accrual_account = self.revenue_accrual_account if self.account_type == 'income' else self.expense_accrual_account

move_data = {'new_date': {
'currency_id': self.journal_id.currency_id.id or self.journal_id.company_id.currency_id.id,
Expand All @@ -248,54 +306,9 @@ def get_lock_safe_date(aml):
# compute the account.move.lines and the total amount per move
for aml in self.move_line_ids:
# account.move.line data
reported_debit = aml.company_id.currency_id.round((self.percentage / 100) * aml.debit)
reported_credit = aml.company_id.currency_id.round((self.percentage / 100) * aml.credit)
reported_amount_currency = aml.currency_id.round((self.percentage / 100) * aml.amount_currency)

move_data['new_date']['line_ids'] += [
(0, 0, {
'name': aml.name or '',
'debit': reported_debit,
'credit': reported_credit,
'amount_currency': reported_amount_currency,
'currency_id': aml.currency_id.id,
'account_id': aml.account_id.id,
'partner_id': aml.partner_id.id,
'analytic_distribution': aml.analytic_distribution,
}),
(0, 0, {
'name': self._format_strings(_('{percent:0.2f}% recognized on {new_date}'), aml.move_id),
'debit': reported_credit,
'credit': reported_debit,
'amount_currency': -reported_amount_currency,
'currency_id': aml.currency_id.id,
'account_id': accrual_account.id,
'partner_id': aml.partner_id.id,
'analytic_distribution': aml.analytic_distribution,
}),
]
move_data[get_lock_safe_date(aml)]['line_ids'] += [
(0, 0, {
'name': aml.name or '',
'debit': reported_credit,
'credit': reported_debit,
'amount_currency': -reported_amount_currency,
'currency_id': aml.currency_id.id,
'account_id': aml.account_id.id,
'partner_id': aml.partner_id.id,
'analytic_distribution': aml.analytic_distribution,
}),
(0, 0, {
'name': self._format_strings(_('{percent:0.2f}% to recognize on {new_date}'), aml.move_id),
'debit': reported_debit,
'credit': reported_credit,
'amount_currency': reported_amount_currency,
'currency_id': aml.currency_id.id,
'account_id': accrual_account.id,
'partner_id': aml.partner_id.id,
'analytic_distribution': aml.analytic_distribution,
}),
]
new_date_lines, old_date_lines = self._get_move_line_dict_vals_change_period(aml)
move_data['new_date']['line_ids'] += new_date_lines
move_data[get_lock_safe_date(aml)]['line_ids'] += old_date_lines

move_vals = [m for m in move_data.values()]
return move_vals
Expand Down