我正在处理合作伙伴分类帐报告,并且我已使用SQL查询准备报告
def lines(self, partner):
move_state = ['draft','posted']
if self.target_move == 'posted':
move_state = ['posted']
full_account = []
if self.reconcil:
RECONCILE_TAG = " "
else:
RECONCILE_TAG = "AND l.reconcile_id IS NULL"
self.cr.execute(
"SELECT l.id, l.date, j.code, acc.code as a_code, acc.name as a_name,inv.state,inv.date_due, l.ref, m.name as move_name, l.name, l.debit, l.credit, l.amount_currency,l.currency_id, c.symbol AS currency_code " \
"FROM account_move_line l " \
"LEFT JOIN account_journal j " \
"ON (l.journal_id = j.id) " \
"LEFT JOIN account_account acc " \
"ON (l.account_id = acc.id) " \
"LEFT JOIN res_currency c ON (l.currency_id=c.id)" \
"LEFT JOIN account_move m ON (m.id=l.move_id)" \
"LEFT JOIN account_invoice inv ON (inv.move_id = l.move_id)" \
"WHERE l.partner_id = %s " \
"AND l.account_id IN %s AND " + self.query +" " \
"AND m.state IN %s " \
" " + RECONCILE_TAG + " "\
"ORDER BY l.date",
(partner.id, tuple(self.account_ids), tuple(move_state)))
res = self.cr.dictfetchall()
sum = 0.0
if self.initial_balance:
sum = self.init_bal_sum
for r in res:
sum += r['debit'] - r['credit']
r['progress'] = sum
full_account.append(r)
return full_account
我的结果是准确的 但现在我想使用ORM方法和代码来做到这一点:
account_move_model = self.pool.get('account.move.line')
full_account_custom = []
move_line_ids = account_move_model.search(self.cr, self.uid, [
('partner_id', '=', partner.id), ('account_id', 'in', tuple(self.account_ids)),
('state', 'in', tuple(move_state))
])
move_lines = account_move_model.browse(self.cr, self.uid, move_line_ids)
sum = 0.0
if self.initial_balance:
sum = self.init_bal_sum
for r in move_lines:
sum += r['debit'] - r['credit']
r['progress'] = sum
full_account_custom.append(r)
return full_account_custom
通过这样做,我只得到合作伙伴/客户的所有发票的总和,但所有发票的清单都没有显示。 错误在哪里以及如何解决它
答案 0 :(得分:1)
使用ORM方法存在一些困难.. 简单的方法是使用原始查询。