python 2.7 - Partner Ledger Report using ORM methods in Odoo8 -
i working on partner ledger report , have prepared report using sql query
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 null" self.cr.execute( "select l.id, l.date, j.code, acc.code a_code, acc.name a_name,inv.state,inv.date_due, l.ref, m.name move_name, l.name, l.debit, l.credit, l.amount_currency,l.currency_id, c.symbol 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 , " + self.query +" " \ "and m.state in %s " \ " " + reconcile_tag + " "\ "order 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 r in res: sum += r['debit'] - r['credit'] r['progress'] = sum full_account.append(r) return full_account
my result accurate want using orm methods , code this:
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 r in move_lines: sum += r['debit'] - r['credit'] r['progress'] = sum full_account_custom.append(r) return full_account_custom
by doing getting sum of invoices of partner/customer list of invoice not showing. mistake , how resolve it
using orm methods there difficulties.. easy way use raw query.
Comments
Post a Comment