[IMP] ability to use date filters

pull/7/merge
Nicolas Bessi 2014-03-14 15:20:12 +01:00
parent 004c3f2093
commit 7d21e1e83a
2 changed files with 87 additions and 89 deletions

View File

@ -123,15 +123,10 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
del(acc.ledger_lines) del(acc.ledger_lines)
return res return res
def compute_aged_lines(self, partner_id, lines, data): def compute_aged_lines(self, partner_id, ledger_lines, data):
lines_to_age = self.filter_lines(partner_id, lines) lines_to_age = self.filter_lines(partner_id, ledger_lines)
res = {} res = {}
period_to_id = data['form']['period_to'] end_date = self._get_end_date(data)
period_to = self.pool['account.period'].browse(self.cr,
self.uid,
period_to_id)
end_date = period_to.date_stop
aged_lines = dict.fromkeys(RANGES, 0.0) aged_lines = dict.fromkeys(RANGES, 0.0)
reconcile_lookup = self.get_reconcile_count_lookup(lines_to_age) reconcile_lookup = self.get_reconcile_count_lookup(lines_to_age)
res['aged_lines'] = aged_lines res['aged_lines'] = aged_lines
@ -139,30 +134,55 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
compute_method = self.get_compute_method(reconcile_lookup, compute_method = self.get_compute_method(reconcile_lookup,
partner_id, partner_id,
line) line)
delay = compute_method(line, end_date) delay = compute_method(line, end_date, ledger_lines)
classification = self.classify_line(partner_id, delay) classification = self.classify_line(partner_id, delay)
aged_lines[classification] += line['debit'] - line['credit'] aged_lines[classification] += line['debit'] - line['credit']
self.compute_balance(res, aged_lines) self.compute_balance(res, aged_lines)
return res 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): def _compute_delay_from_key(self, key, line, end_date):
from_date = datetime.strptime(line[key], DEFAULT_SERVER_DATE_FORMAT) from_date = datetime.strptime(line[key], DEFAULT_SERVER_DATE_FORMAT)
end_date = datetime.strptime(end_date, DEFAULT_SERVER_DATE_FORMAT) end_date = datetime.strptime(end_date, DEFAULT_SERVER_DATE_FORMAT)
delta = end_date - from_date delta = end_date - from_date
return delta.days 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', return self._compute_delay_from_key('date_maturity',
line, line,
end_date) 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', return self._compute_delay_from_key('date',
line, line,
end_date) end_date)
def compute_delay_from_partial_rec(self, line, end_date): def compute_delay_from_partial_rec(self, line, end_date, ledger_lines):
return 25 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): def get_compute_method(self, reconcile_lookup, partner_id, line):
if reconcile_lookup.get(line['rec_id'], 0.0) > 1: if reconcile_lookup.get(line['rec_id'], 0.0) > 1:

View File

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