Browse Source

[IMP] ability to use date filters

pull/7/merge
Nicolas Bessi 10 years ago
parent
commit
7d21e1e83a
  1. 46
      account_financial_report_webkit/report/aged_partner_balance.py
  2. 132
      account_financial_report_webkit/wizard/aged_partner_balance_wizard.xml

46
account_financial_report_webkit/report/aged_partner_balance.py

@ -123,15 +123,10 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
del(acc.ledger_lines)
return res
def compute_aged_lines(self, partner_id, lines, data):
lines_to_age = self.filter_lines(partner_id, lines)
def compute_aged_lines(self, partner_id, ledger_lines, data):
lines_to_age = self.filter_lines(partner_id, ledger_lines)
res = {}
period_to_id = data['form']['period_to']
period_to = self.pool['account.period'].browse(self.cr,
self.uid,
period_to_id)
end_date = period_to.date_stop
end_date = self._get_end_date(data)
aged_lines = dict.fromkeys(RANGES, 0.0)
reconcile_lookup = self.get_reconcile_count_lookup(lines_to_age)
res['aged_lines'] = aged_lines
@ -139,30 +134,55 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
compute_method = self.get_compute_method(reconcile_lookup,
partner_id,
line)
delay = compute_method(line, end_date)
delay = compute_method(line, end_date, ledger_lines)
classification = self.classify_line(partner_id, delay)
aged_lines[classification] += line['debit'] - line['credit']
self.compute_balance(res, aged_lines)
return res
def _get_end_date(self, data):
end_date = None
date_to = data['form']['date_to']
period_to_id = data['form']['period_to']
if date_to:
end_date = date_to
elif period_to_id:
period_to = self.pool['account.period'].browse(self.cr,
self.uid,
period_to_id)
end_date = period_to.date_stop
else:
raise ValueError('End date and end period not available')
return end_date
def _compute_delay_from_key(self, key, line, end_date):
from_date = datetime.strptime(line[key], DEFAULT_SERVER_DATE_FORMAT)
end_date = datetime.strptime(end_date, DEFAULT_SERVER_DATE_FORMAT)
delta = end_date - from_date
return delta.days
def compute_delay_from_maturity(self, line, end_date):
def compute_delay_from_maturity(self, line, end_date, ledger_lines):
return self._compute_delay_from_key('date_maturity',
line,
end_date)
def compute_delay_from_date(self, line, end_date):
def compute_delay_from_date(self, line, end_date, ledger_lines):
return self._compute_delay_from_key('date',
line,
end_date)
def compute_delay_from_partial_rec(self, line, end_date):
return 25
def compute_delay_from_partial_rec(self, line, end_date, ledger_lines):
sale_lines = [x for x in ledger_lines if x['jtype'] in REC_PAY_TYPE]
refund_lines = [x for x in ledger_lines if x['jtype'] in REFUND_TYPE]
reference_line = line
if len(sale_lines) == 1:
reference_line = sale_lines[0]
elif len(refund_lines) == 1:
reference_line = refund_lines[0]
key = line.get('date_maturity', reference_line['date'])
return self._compute_delay_from_key(key,
reference_line,
end_date)
def get_compute_method(self, reconcile_lookup, partner_id, line):
if reconcile_lookup.get(line['rec_id'], 0.0) > 1:

132
account_financial_report_webkit/wizard/aged_partner_balance_wizard.xml

@ -2,83 +2,61 @@
<openerp>
<data>
<record id="account_aged_trial_balance_webkit" model="ir.ui.view">
<field name="name">Aged Partner Balance Report</field>
<field name="model">account.aged.trial.balance.webkit</field>
<field name="inherit_id" ref="account.account_common_report_view"/>
<field name="arch" type="xml">
<data>
<xpath expr="/form/label[@string='']" position="replace">
<separator string="Aged Partner Balance" colspan="4"/>
<label nolabel="1"
colspan="4"
string="This report list partner open balances and indicate when payment is (or was) supposed to be completed"/>
</xpath>
<field name="chart_account_id" position='attributes'>
<attribute name="colspan">4</attribute>
</field>
<xpath expr="//field[@name='target_move']" position="after">
<newline/>
<field name="result_selection" colspan="4"/>
</xpath>
<xpath expr="/form/notebook[1]" position="after">
<separator string="Clearance Analysis Options" colspan="4"/>
<newline/>
<field name="until_date"/>
</xpath>
<field name="filter" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<page name="filters" position="after">
<page string="Partners Filters" name="partners">
<separator string="Print only" colspan="4"/>
<field name="partner_ids" colspan="4" nolabel="1"/>
</page>
</page>
<page name="journal_ids" position="attributes">
<attribute name="invisible">True</attribute>
</page>
<field name="fiscalyear_id" position="attributes">
<attribute name="on_change">onchange_fiscalyear(fiscalyear_id, period_to, date_to, until_date)</attribute>
</field>
<field name="date_from" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="date_to" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<group string="Dates" position="attributes">
<attribute name="invisible">1</attribute>
<attribute name="attrs"></attribute>
</group>
<group string="Periods" position="attributes">
<attribute name="invisible">0</attribute>
<attribute name="attrs"></attribute>
</group>
<field name="period_from" position="attributes">
<attribute name="domain">[('fiscalyear_id', '=', fiscalyear_id), ('special', '=', False)]</attribute>
</field>
<field name="period_to" position="attributes">
<attribute name="domain">[('fiscalyear_id', '=', fiscalyear_id), ('special', '=', False)]</attribute>
</field>
</data>
</field>
</record>
<record id="account_aged_trial_balance_webkit" model="ir.ui.view">
<field name="name">Aged Partner Balance Report</field>
<field name="model">account.aged.trial.balance.webkit</field>
<field name="inherit_id" ref="account.account_common_report_view"/>
<field name="arch" type="xml">
<data>
<xpath expr="/form/label[@string='']" position="replace">
<separator string="Aged Partner Balance" colspan="4"/>
<label nolabel="1"
colspan="4"
string="This report list partner open balances and indicate when payment is (or was) supposed to be completed"/>
</xpath>
<field name="chart_account_id" position='attributes'>
<attribute name="colspan">4</attribute>
</field>
<xpath expr="//field[@name='target_move']" position="after">
<newline/>
<field name="result_selection" colspan="4"/>
</xpath>
<xpath expr="/form/notebook[1]" position="after">
<separator string="Clearance Analysis Options" colspan="4"/>
<newline/>
<field name="until_date"/>
</xpath>
<page name="filters" position="after">
<page string="Partners Filters" name="partners">
<separator string="Print only" colspan="4"/>
<field name="partner_ids" colspan="4" nolabel="1"/>
</page>
</page>
<page name="filters" position="attributes">
<attribute name="string">Time Filters</attribute>
</page>
<page name="journal_ids" position="attributes">
<attribute name="invisible">True</attribute>
</page>
<field name="fiscalyear_id" position="attributes">
<attribute name="on_change">onchange_fiscalyear(fiscalyear_id, period_to, date_to, until_date)</attribute>
</field>
<field name="date_to" position="attributes">
<attribute name="on_change">onchange_date_to(fiscalyear_id, period_to, date_to, until_date)</attribute>
</field>
<field name="period_to" position="attributes">
<attribute name="on_change">onchange_period_to(fiscalyear_id, period_to, date_to, until_date)</attribute>
</field>
<field name="period_from" position="attributes">
<attribute name="domain">[('fiscalyear_id', '=', fiscalyear_id), ('special', '=', False)]</attribute>
</field>
<field name="period_to" position="attributes">
<attribute name="domain">[('fiscalyear_id', '=', fiscalyear_id), ('special', '=', False)]</attribute>
</field>
</data>
</field>
</record>
<record id="action_account_aged_trial_balance_menu_webkit"
model="ir.actions.act_window">

Loading…
Cancel
Save