[IMP] improvements on open invoice report.
parent
51288edf0d
commit
cb0547b382
|
@ -13,17 +13,46 @@ class OpenInvoiceReport(models.AbstractModel):
|
|||
|
||||
_name = 'report.account_financial_report_qweb.open_invoice_report_qweb'
|
||||
|
||||
def _get_domain(self, data):
|
||||
account_type = ('payable', 'receivable')
|
||||
if data['form']['result_selection'] == 'customer':
|
||||
account_type = ('receivable', )
|
||||
elif data['form']['result_selection'] == 'supplier':
|
||||
account_type = ('payable', )
|
||||
domain = [
|
||||
('company_id', '=', data['form']['company_id'][0]),
|
||||
('move_id.date', '<=', data['form']['at_date']),
|
||||
('account_id.user_type_id.type', 'in', account_type)
|
||||
]
|
||||
if data['form']['target_move'] != 'all':
|
||||
domain.append(('move_id.state', 'in', ('posted', )), )
|
||||
if data['form']['partner_ids']:
|
||||
domain.append(('partner_id', 'in',
|
||||
[p.id for p in data['form']['partner_ids']]), )
|
||||
return domain
|
||||
|
||||
def _query(self, data):
|
||||
|
||||
moves = self.env['account.move.line'].search(
|
||||
self._get_domain(data), order='date asc')
|
||||
if not moves:
|
||||
return True # ----- Show a message here
|
||||
return moves
|
||||
|
||||
@api.multi
|
||||
def render_html(self, data=None):
|
||||
report_obj = self.env['report']
|
||||
doc_ids = self._ids
|
||||
moves = self._query(data)
|
||||
docargs = {
|
||||
'doc_model': 'account.move.line',
|
||||
'doc_ids': doc_ids,
|
||||
'sorted': sorted,
|
||||
'doc_ids': data['ids'],
|
||||
'docs': moves,
|
||||
'header': data['header'],
|
||||
'account_obj': self.env['account.account'],
|
||||
'partner_obj': self.env['res.partner'],
|
||||
'currency_obj': self.env['res.currency'],
|
||||
}
|
||||
if data:
|
||||
docargs.update(data)
|
||||
|
||||
return report_obj.render(
|
||||
'account_financial_report_qweb.open_invoice_report_qweb',
|
||||
docargs)
|
||||
|
|
|
@ -47,30 +47,53 @@
|
|||
</div>
|
||||
<div class="act_as_tbody">
|
||||
<div class="act_as_row">
|
||||
<div class="act_as_cell first_column"><span t-esc="general['company']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="general['at_date']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="general['account_filters']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="general['target_moves']"/></div>
|
||||
<div class="act_as_cell first_column"><span t-esc="header['company']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="header['at_date']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="header['account_filters']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="header['target_moves']"/></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Informations group by account -->
|
||||
<t t-foreach="sorted(data.keys())" t-as="account">
|
||||
<!-- Group by account -->
|
||||
<t t-foreach="docs.read_group([('id', 'in', docs.ids)],['account_id'],['account_id'])" t-as="acc">
|
||||
<t t-set="account"
|
||||
t-value="account_obj.browse(acc['account_id'][0])"/>
|
||||
<t t-set="account_debit" t-value="0.0" />
|
||||
<t t-set="account_credit" t-value="0.0" />
|
||||
<t t-set="account_balance" t-value="0.0" />
|
||||
<div class="act_as_caption account_title">
|
||||
<span t-esc="account"/>
|
||||
<span t-esc="account.code"/> - <span
|
||||
t-esc="account.name"/>
|
||||
</div>
|
||||
<!-- Informations group by partner -->
|
||||
<t t-foreach="sorted(data[account].keys())" t-as="partner">
|
||||
<!-- Group by partner -->
|
||||
<t t-foreach="docs.read_group([('id', 'in', docs.ids), ('account_id', '=', account.id)],['partner_id'],['partner_id'])" t-as="part">
|
||||
<t t-set="partner"
|
||||
t-value="partner_obj.browse(part['partner_id'][0])"/>
|
||||
<t t-set="partner_debit" t-value="0.0" />
|
||||
<t t-set="partner_credit" t-value="0.0" />
|
||||
<t t-set="partner_balance" t-value="0.0" />
|
||||
<div class="act_as_caption account_title">
|
||||
<span t-esc="partner"/>
|
||||
<span t-esc="partner.name"/>
|
||||
</div>
|
||||
<!-- Group by currency -->
|
||||
<t t-foreach="docs.read_group([('id', 'in', docs.ids), ('account_id', '=', account.id), ('partner_id', '=', partner.id)],['currency_id'],['currency_id'])" t-as="curr">
|
||||
<t t-set="currency_id" t-value="False" />
|
||||
<t t-if="curr['currency_id']">
|
||||
<t t-set="currency"
|
||||
t-value="currency_obj.browse(curr['currency_id'][0])"/>
|
||||
<t t-set="currency_id"
|
||||
t-value="currency.id"/>
|
||||
</t>
|
||||
<t t-set="currency_debit" t-value="0.0" />
|
||||
<t t-set="currency_credit" t-value="0.0" />
|
||||
<t t-set="currency_balance" t-value="0.0" />
|
||||
<t t-set="currency_amount_balance" t-value="0.0"/>
|
||||
<t t-if="currency_id">
|
||||
<div class="act_as_caption account_title">
|
||||
<span t-esc="currency.name"/>
|
||||
</div>
|
||||
</t>
|
||||
<div class="act_as_table data_table">
|
||||
<div class="act_as_thead">
|
||||
<div class="act_as_row labels">
|
||||
|
@ -84,60 +107,103 @@
|
|||
<div class="act_as_cell">Due Date</div>
|
||||
<div class="act_as_cell">Debit</div>
|
||||
<div class="act_as_cell">Credit</div>
|
||||
<div class="act_as_cell">Cumul.Bal.</div>
|
||||
<div class="act_as_cell">Cum. Balance</div>
|
||||
<t t-if="curr['currency_id']">
|
||||
<div class="act_as_cell">Curr. amount</div>
|
||||
<div class="act_as_cell">Cum. Curr. Bal.</div>
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
<div class="act_as_tbody">
|
||||
<t t-foreach="data[account][partner]" t-as="move">
|
||||
<t t-set="moves" t-value="docs.search(
|
||||
[('id', 'in', docs.ids),
|
||||
('account_id', '=', account.id),
|
||||
('partner_id', '=', partner.id),
|
||||
('currency_id', '=', currency_id)])"/>
|
||||
<t t-foreach="moves" t-as="move">
|
||||
<div class="act_as_row">
|
||||
<div class="act_as_cell first_column"><span t-esc="move['date']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="move['entry']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="move['journal']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="partner"/></div>
|
||||
<div class="act_as_cell"><span t-esc="move['reference']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="move['label']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="move['rec']"/></div>
|
||||
<div class="act_as_cell"><span t-esc="move['due_date']"/></div>
|
||||
<t t-set="account_debit" t-value="account_debit + move['debit']" />
|
||||
<t t-set="account_credit" t-value="account_credit + move['credit']" />
|
||||
<t t-set="account_balance" t-value="account_balance - move['credit'] + move['debit']" />
|
||||
<t t-set="partner_debit" t-value="partner_debit + move['debit']" />
|
||||
<t t-set="partner_credit" t-value="partner_credit + move['credit']" />
|
||||
<t t-set="partner_balance" t-value="partner_balance - move['credit'] + move['debit']" />
|
||||
<div class="act_as_cell amount"><span t-esc="move['debit']"/></div>
|
||||
<div class="act_as_cell amount"><span t-esc="move['credit']"/></div>
|
||||
<div class="act_as_cell amount"><span t-esc="partner_balance" /></div>
|
||||
<div class="act_as_cell first_column"><span t-esc="move.date"/></div>
|
||||
<div class="act_as_cell"><span t-esc="move.name"/></div>
|
||||
<div class="act_as_cell"><span t-esc="move.journal_id.code"/></div>
|
||||
<div class="act_as_cell"><span t-esc="partner.name"/></div>
|
||||
<div class="act_as_cell"><span
|
||||
t-esc="move.ref"/></div>
|
||||
<div class="act_as_cell"><span
|
||||
t-esc="move.name"/>
|
||||
<t t-if="move.invoice_id"> - <span t-esc="move.invoice_id.number"/></t>
|
||||
</div>
|
||||
<div class="act_as_cell"><span t-esc="move.full_reconcile_id.name"/></div>
|
||||
<div class="act_as_cell"><span t-esc="move.date_maturity"/></div>
|
||||
<t t-set="account_debit" t-value="account_debit + move.debit" />
|
||||
<t t-set="account_credit" t-value="account_credit + move.credit" />
|
||||
<t t-set="account_balance" t-value="account_balance - move.credit + move.debit" />
|
||||
<t t-set="partner_debit" t-value="partner_debit + move.debit" />
|
||||
<t t-set="partner_credit" t-value="partner_credit + move.credit" />
|
||||
<t t-set="partner_balance" t-value="partner_balance - move.credit + move.debit" />
|
||||
<t t-set="currency_balance" t-value="currency_balance + move.amount_currency" />
|
||||
<div class="act_as_cell amount"><span t-esc="move.debit"/></div>
|
||||
<div class="act_as_cell amount"><span t-esc="move.credit"/></div>
|
||||
<div class="act_as_cell amount"><span t-esc="partner_balance"/></div>
|
||||
<t t-if="currency_id">
|
||||
<div class="act_as_cell amount"><span t-esc="move.amount_currency"/></div>
|
||||
<div class="act_as_cell amount"><span t-esc="currency_balance"/></div>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
<div class="act_as_row">
|
||||
<div class="act_as_cell first_column"></div>
|
||||
<div class="act_as_cell"></div>
|
||||
<div class="act_as_cell"></div>
|
||||
<div class="act_as_cell"></div>
|
||||
<div class="act_as_cell"></div>
|
||||
<div class="act_as_cell"></div>
|
||||
<div class="act_as_cell"></div>
|
||||
<div class="act_as_cell">Comulate Balance on Partner</div>
|
||||
<div class="act_as_cell amount"><span t-esc="partner_debit" /></div>
|
||||
<div class="act_as_cell amount"><span t-esc="partner_credit" /></div>
|
||||
<div class="act_as_cell amount"><span t-esc="partner_balance" /></div>
|
||||
</div>
|
||||
</div>
|
||||
<t t-if="currency_id">
|
||||
<div class="act_as_table totals_table">
|
||||
<div class="act_as_row">
|
||||
<div class="act_as_cell first_column"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell account_title"><span t-esc="currency.name"/> Total</div>
|
||||
<div class="act_as_cell amount"><strong><span t-esc="currency_balance" /></strong></div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
<div class="act_as_table data_table">
|
||||
<div class="act_as_tbody">
|
||||
<div class="act_as_row labels">
|
||||
<div class="act_as_cell first_column"><span t-esc="account"/></div>
|
||||
<div class="act_as_cell cell"><strong>Comulate Balance</strong></div>
|
||||
</t>
|
||||
<div class="act_as_table totals_table">
|
||||
<div class="act_as_row">
|
||||
<div class="act_as_cell first_column"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell account_title"><span t-esc="partner.name"/> Total</div>
|
||||
<div class="act_as_cell amount"><strong><span t-esc="partner_debit" /></strong></div>
|
||||
<div class="act_as_cell amount"><strong><span t-esc="partner_credit" /></strong></div>
|
||||
<div class="act_as_cell amount"><strong><span t-esc="partner_balance" /></strong></div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
<div class="act_as_table totals_table">
|
||||
<div class="act_as_row">
|
||||
<div class="act_as_cell first_column"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell account_title"><span t-esc="account.name"/> Total</div>
|
||||
<div class="act_as_cell amount"><span t-esc="account_debit" /></div>
|
||||
<div class="act_as_cell amount"><span t-esc="account_credit" /></div>
|
||||
<div class="act_as_cell amount"><span t-esc="account_balance" /></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
|
|
|
@ -18,14 +18,14 @@ body, table, td, span, div {
|
|||
.act_as_tbody {
|
||||
display: table-row-group !important;
|
||||
}
|
||||
.list_table, .data_table {
|
||||
.list_table, .data_table, .totals_table{
|
||||
width: 100% !important;
|
||||
table-layout: fixed !important;
|
||||
}
|
||||
.act_as_row.labels {
|
||||
background-color:#F0F0F0 !important;
|
||||
}
|
||||
.list_table, .data_table, .list_table .act_as_row {
|
||||
.list_table, .data_table, .totals_table, .list_table .act_as_row {
|
||||
border-left:0px;
|
||||
border-right:0px;
|
||||
text-align:left;
|
||||
|
@ -36,18 +36,22 @@ body, table, td, span, div {
|
|||
padding-bottom:2px;
|
||||
border-collapse:collapse;
|
||||
}
|
||||
.totals_table {
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
}
|
||||
.list_table .act_as_row.labels, .list_table .act_as_row.initial_balance, .list_table .act_as_row.lines {
|
||||
border-color:grey !important;
|
||||
border-bottom:1px solid lightGrey !important;
|
||||
}
|
||||
.data_table .act_as_cell {
|
||||
.data_table .act_as_cell{
|
||||
border: 1px solid lightGrey;
|
||||
text-align: center;
|
||||
}
|
||||
.data_table .act_as_cell, .list_table .act_as_cell {
|
||||
.data_table .act_as_cell, .list_table .act_as_cell, .totals_table .act_as_cell {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
.data_table .act_as_row.labels {
|
||||
.data_table .act_as_row.labels, .totals_table .act_as_row.labels {
|
||||
font-weight: bold;
|
||||
}
|
||||
.initial_balance .act_as_cell {
|
||||
|
|
|
@ -22,10 +22,6 @@ class OpenInvoiceWizard(models.TransientModel):
|
|||
default=fields.Date.to_string(datetime.today()))
|
||||
partner_ids = fields.Many2many(
|
||||
'res.partner', string='Filter partners')
|
||||
amount_currency = fields.Boolean(
|
||||
"With Currency", help="It adds the currency column")
|
||||
group_by_currency = fields.Boolean(
|
||||
"Group Partner by currency", help="It adds the currency column")
|
||||
result_selection = fields.Selection([
|
||||
('customer', 'Receivable Accounts'),
|
||||
('supplier', 'Payable Accounts'),
|
||||
|
@ -35,16 +31,6 @@ class OpenInvoiceWizard(models.TransientModel):
|
|||
('posted', 'All Posted Entries'),
|
||||
('all', 'All Entries')], 'Target Moves',
|
||||
required=True, default='all')
|
||||
until_date = fields.Date(
|
||||
"Clearance date",
|
||||
help="""The clearance date is essentially a tool used for debtors
|
||||
provisionning calculation.
|
||||
By default, this date is equal to the the end date (
|
||||
ie: 31/12/2011 if you select fy 2011).
|
||||
By amending the clearance date, you will be, for instance,
|
||||
able to answer the question : 'based on my last
|
||||
year end debtors open invoices, which invoices are still
|
||||
unpaid today (today is my clearance date)?'""")
|
||||
|
||||
@api.onchange('at_date')
|
||||
def onchange_atdate(self):
|
||||
|
@ -58,64 +44,12 @@ class OpenInvoiceWizard(models.TransientModel):
|
|||
raise UserError(
|
||||
'Until Date must be equal or greater than At Date')
|
||||
|
||||
@staticmethod
|
||||
def _get_domain(data):
|
||||
account_type = ('payable', 'receivable')
|
||||
if data['result_selection'] == 'customer':
|
||||
account_type = ('receivable', )
|
||||
elif data['result_selection'] == 'supplier':
|
||||
account_type = ('payable', )
|
||||
domain = [
|
||||
('company_id', '=', data['company_id'].id),
|
||||
('move_id.date', '<=', data['at_date']),
|
||||
('account_id.user_type_id.type', 'in', account_type)
|
||||
]
|
||||
if data['target_move'] != 'all':
|
||||
domain.append(('move_id.state', 'in', ('posted', )), )
|
||||
if data['partner_ids']:
|
||||
domain.append(('partner_id', 'in', [p.id
|
||||
for p
|
||||
in data['partner_ids']]), )
|
||||
return domain
|
||||
def _build_contexts(self, data):
|
||||
result = {}
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _get_move_line_data(move):
|
||||
label = move.name
|
||||
if move.invoice_id:
|
||||
label = '{label} ({inv_nummber})'.format(
|
||||
label=label, inv_nummber=move.invoice_id.number)
|
||||
def _build_header(self):
|
||||
return {
|
||||
'date': move.date,
|
||||
'entry': move.move_id.name,
|
||||
'journal': move.move_id.journal_id.code,
|
||||
'reference': move.ref,
|
||||
'label': label,
|
||||
'rec': move.full_reconcile_id.name,
|
||||
'due_date': move.date_maturity,
|
||||
'debit': move.debit,
|
||||
'credit': move.credit,
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def print_report(self):
|
||||
self.ensure_one()
|
||||
moves = self.env['account.move.line'].search(
|
||||
self._get_domain(self), order='date asc')
|
||||
if not moves:
|
||||
return True # ----- Show a message here
|
||||
datas = {}
|
||||
for move in moves:
|
||||
account = '{code} - {name}'.format(
|
||||
code=move.account_id.code,
|
||||
name=move.account_id.name)
|
||||
partner = move.partner_id.name
|
||||
if account not in datas:
|
||||
datas[account] = {}
|
||||
if partner not in datas[account]:
|
||||
datas[account][partner] = []
|
||||
datas[account][partner].append(
|
||||
self._get_move_line_data(move))
|
||||
generals = {
|
||||
'company': self.company_id.name,
|
||||
'fiscal_year': '',
|
||||
'at_date': self.at_date,
|
||||
|
@ -125,6 +59,23 @@ class OpenInvoiceWizard(models.TransientModel):
|
|||
'target_moves': dict(
|
||||
self._columns['target_move'].selection)[self.target_move],
|
||||
}
|
||||
|
||||
def _get_form_fields(self):
|
||||
return self.read(['company_id', 'at_date', 'partner_ids',
|
||||
'result_selection', 'target_move',
|
||||
'until_date'])[0]
|
||||
|
||||
@api.multi
|
||||
def print_report(self):
|
||||
self.ensure_one()
|
||||
data = {}
|
||||
data['ids'] = self.env.context.get('active_ids', [])
|
||||
data['model'] = self.env.context.get('active_model', 'ir.ui.menu')
|
||||
data['form'] = self._get_form_fields()
|
||||
used_context = self._build_contexts(data)
|
||||
data['form']['used_context'] = dict(
|
||||
used_context, lang=self.env.context.get('lang', 'en_US'))
|
||||
data['header'] = self._build_header()
|
||||
return self.env['report'].get_action(
|
||||
self, 'account_financial_report_qweb.open_invoice_report_qweb',
|
||||
data={'data': datas, 'general': generals})
|
||||
data=data)
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
<field name="partner_ids" />
|
||||
</group>
|
||||
<group name="layout_info">
|
||||
<field name="amount_currency" />
|
||||
<field name="group_by_currency" />
|
||||
<field name="result_selection" />
|
||||
<field name="target_move" />
|
||||
</group>
|
||||
|
|
Loading…
Reference in New Issue