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

[IMP] account_debt_report: Company currency is optional in report #603

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
43 changes: 12 additions & 31 deletions account_debt_report/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import api, models, fields, _
from odoo import models, _
from odoo.tools.safe_eval import safe_eval
# from odoo.exceptions import ValidationError

Expand Down Expand Up @@ -40,13 +40,18 @@ def get_line_vals(
historical_full = self._context.get('historical_full', False)
company_id = self._context.get('company_id', False)
show_invoice_detail = self._context.get('show_invoice_detail', False)

only_currency_lines = not self._context.get('company_currency') and self._context.get('secondary_currency')
domain = []

if company_id:
domain += [('company_id', '=', company_id)]
if only_currency_lines:
domain += [('currency_id', '!=', self.env['res.company'].browse(company_id).currency_id.id)]
else:
domain += [('company_id', 'in', self.env.companies.ids)]
company_currency_ids = self.env.companies.mapped('currency_id')
if only_currency_lines and len(company_currency_ids) == 1:
domain += [('currency_id', 'not in', company_currency_ids.ids)]

if not historical_full:
domain += [('reconciled', '=', False), ('full_reconcile_id', '=', False)]
Expand Down Expand Up @@ -78,19 +83,11 @@ def get_line_vals(
res = []

if to_date:
final_line = []
domain.append(('date', '<=', to_date))
else:
final_line = []
final_line = []

records = self.env['account.move.line'].sudo().search(domain, order='date asc, name, move_id desc, date_maturity asc, id')

grouped = self.env['account.payment']._fields.get('payment_group_id') and safe_eval(
self.env['ir.config_parameter'].sudo().get_param(
'account_debt_report.group_payment_group_payments', 'False'))

last_payment_group_id = False

# construimos una nueva lista con los valores que queremos y de
# manera mas facil
for record in records:
Expand All @@ -117,24 +114,8 @@ def get_line_vals(
amount = record.balance
amount_residual = record.amount_residual
amount_currency = record.amount_currency

if grouped and record.payment_id and record.payment_id.payment_group_id == last_payment_group_id:
# si agrupamos pagos y el grupo de pagos coincide con el último, entonces acumulamos en linea anterior
res[-1].update({
'amount': res[-1]['amount'] + record.balance,
'amount_residual': res[-1]['amount_residual'] + record.amount_residual,
'amount_currency': res[-1]['amount_currency'] + record.amount_currency,
'balance': balance,
})
continue
elif grouped and record.payment_id and record.payment_id.payment_group_id != last_payment_group_id:
# si es un payment pero no es del payment group anterior, seteamos este como ultimo payment group
last_payment_group_id = record.payment_id.payment_group_id
elif not grouped and record.payment_id:
# si no agrupamos y es pago, agregamos nombre de diario para que sea mas claro
name += ' - ' + record.journal_id.name
elif not record.payment_id:
last_payment_group_id = False
show_currency = record.currency_id != record.company_id.currency_id
name += ' - ' + record.journal_id.name

# TODO tal vez la suma podriamos probar hacerla en el xls como hacemos en libro iva v11/v12
res.append(get_line_vals(
Expand All @@ -145,8 +126,8 @@ def get_line_vals(
amount=amount,
amount_residual=amount_residual,
balance=balance,
amount_currency=amount_currency,
currency_name=currency.name,
amount_currency=amount_currency if show_currency else False,
currency_name=currency.name if show_currency else False,
# move_line=record.move_line_id,
))
res += final_line
Expand Down
5 changes: 5 additions & 0 deletions account_debt_report/wizard/account_debt_report_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def _default_result_selection(self):
historical_full = fields.Boolean(
help='If true, then it will show all partner history. If not, only '
'unreconciled items will be shown.')
company_currency = fields.Boolean(
defaul=True,
help='Add columns for company currency?'
)
secondary_currency = fields.Boolean(
help='Add columns for secondary currency?')

Expand All @@ -55,6 +59,7 @@ def confirm(self):
return self.env['ir.actions.report'].search(
[('report_name', '=', 'account_debt_report')],
limit=1).with_context(
company_currency=self.company_currency,
secondary_currency=self.secondary_currency,
result_selection=self.result_selection,
company_id=self.company_id.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<field name="historical_full"/>
<field name="from_date" string="Detallar desde" invisible="not historical_full"/>
<field name="to_date" string="Detallar hasta" invisible="not historical_full"/>
<field name="company_currency"/>
<field name="secondary_currency"/>
<field name="show_invoice_detail"/>
<!-- <field name="show_receipt_detail" attrs="{'invisible': [('group_by_move', '=', False)]}"/> -->
Expand Down