交流OE销售对账单报表的开发 (AEROO)附部分代码, 未完持续更新中.........
-
本报表参照 account\report\account_partner_ledger.py 简化制作, 不足之处,请大牛们指教.
两个菜单:
一, 从菜单中启动报表 (全部的业务伙伴), 菜单定义如下:
<record id="action_form_cs2k_partner_ledger_all" model="ir.actions.act_window">
<field name="name">客户对账单-Aeroo</field>
<field name="res_model">cs2k.partner.ledger</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_form_cs2k_partner_ledger"/>
<field name="context">{'scope':'all'}</field>
<field name="target">new</field>
</record>
<menuitem icon="STOCK_PRINT"
name="客户对账单-Aeroo"
action="action_form_cs2k_partner_ledger_all"
groups="group_sale_pub"
id="menu_cs2k_partner_ledger"
parent="menu_sale_cs2k"/>
(二) 从打印按中启动报表(当前的业务伙伴或选中的业务伙伴)
<record id="action_form_cs2k_partner_ledger_selected" model="ir.actions.act_window">
<field name="name">客户对账单-Aeroo</field>
<field name="res_model">cs2k.partner.ledger</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_form_cs2k_partner_ledger"/>
<field name="context">{'scope':'selected'}</field>
<field name="target">new</field>
</record>
<record model="ir.values" id="ir_values_account_partner_ledger">
<field name="key2" eval="'client_print_multi'"/>
<field name="model" eval="'res.partner'"/>
<field name="name">客户对账单-Aeroo</field>
<field name="value" eval="'ir.actions.act_window,%d'%action_form_cs2k_partner_ledger_selected"/>
</record> -
网上好慢, 附件真难传啊.
def check_report(self, cr, uid, ids, context=None):
if context is None:
context = {}
data = {}
data['ids'] = context.get('active_ids', [])
data['model'] = context.get('active_model', 'ir.ui.menu')
data['form'] = self.read(cr, uid, ids,
['scope', 'target_move', 'page_split', 'filter',
'date_from', 'date_to', 'period_from', 'period_to'], context=context)[0]
if data['form']['scope'] == "selected" and data['ids'] == []:
raise osv.except_osv(_('Error!'), _(u'没有选择业务伙伴可用来对账汇总!!!\n请重新选择!!!'))
if data['form']['page_split']:
return {
'type': 'ir.actions.report.xml',
'report_name': 'report_cs2k_res_partner_partner_ledger_paged',
'datas': data,
}
else:
return {
'type': 'ir.actions.report.xml',
'report_name': 'report_cs2k_res_partner_partner_ledger',
'datas': data,
} -
AEROO 报表定义:
<record id="report_cs2k_res_partner_partner_ledger" model="ir.actions.report.xml">
<field name="name">客户对账单</field>
<field name="type">ir.actions.report.xml</field>
<field name="model">res.partner</field>
<field name="report_name">report_cs2k_res_partner_partner_ledger</field>
<field name="report_type">aeroo</field>
<field name="in_format">oo-ods</field>
<field name="out_format" ref="report_aeroo_ooo.report_mimetypes_xls_odt"/>
<field name="parser_loc">cs2k/report/sales_statement_parser.py</field>
<field name="report_rml">cs2k/report/sales_statement_report.ods</field>
<field name="parser_state">loc</field>
<field name="tml_source">file</field>
</record> -
Parser 文件:
初始化, 函数声明等
class Parser(report_sxw.rml_parse):
def init(self, cr, uid, name, context=None):
super(Parser, self).init(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
'date': date,
'lines': self.lines,
'get_intial_balance': self._get_intial_balance,
'get_date_start': self._get_date_start,
'get_date_end': self._get_date_end,
})
设置报表环境:
def set_context(self, objects, data, ids, report_type=None):
self.datas = data['form']
self.query = " "
self.query_term = ""
self.query_date_start = ""
self.date_start = ""
self.date_end = ""
# 公司ID
user = self.pool.get('res.users').browse(self.cr, self.uid, self.uid, context=None)
self.query += "AND aml.company_id = " + str(user.company_id.id) + " "
# 日否己登账
if data['form']['target_move'] and data['form']['target_move'] == 'posted':
self.query += " AND am.state = '" + str(data['form']['target_move']) + "' "
# 科目ID
# self.query += " AND aml.journal_id = " + str(data['form']['journal_id'][0])
# 日期与时间
# 按时间生成报表.
if data['form']['filter'] and data['form']['filter'] == "filter_date":
self.query_term += " AND aml.date >= '" + str(data['form']['date_from']) + "' "
self.query_term += " AND aml.date <= '" + str(data['form']['date_to']) + "' "
self.query_date_start = " AND aml.date < '" + str(data['form']['date_from']) + "'"
self.date_start = str(data['form']['date_from'])
self.date_end = str(data['form']['date_to'])
elif data['form']['filter'] == "filter_period":
# 按会计期间生成报表.
self.cr.execute(
"select id, date_start, date_stop from account_period where id in %s" <br /> " AND company_id =%s",
((data['form']['period_from'][0], data['form']['period_to'][0]), user.company_id.id))
period_ids = self.cr.dictfetchall()
if period_ids and period_ids[0]['date_start'] and period_ids[1]['date_stop']:
self.query_term += " AND aml.date >= '" + period_ids[0]['date_start'] + "'"
self.query_term += " AND aml.date <= '" + period_ids[1]['date_stop'] + "'"
self.query_date_start = " AND aml.date < '" + str(period_ids[0]['date_start']) + "'"
self.date_start = str(period_ids[0]['date_start'])
self.date_end = str(period_ids[1]['date_stop'])
# 以前两种汇总方式的都必须找到开始时间点, 和结束时间点
domain = []
obj_partner = self.pool.get('res.partner')
if data['form']['scope'] == "selected" and len(ids) > 0:
domain = [('id', 'in', tuple(ids))]
self.partner_ids = obj_partner.search(self.cr, self.uid, domain, context=None)
objects = []
oids = []
for o in obj_partner.browse(self.cr, self.uid, self.partner_ids):
# 去除非公司的业务伙伴
if o.customer and o.is_company:
objects.append(o)
oids.append(o.id)
self.partner_ids = oids
return super(Parser, self).set_context(objects, data, self.partner_ids, report_type)