invoice_report.py 961 B

1234567891011121314151617181920212223
  1. from openerp.osv import fields, osv
  2. import openerp.addons.decimal_precision as dp
  3. class DiscountInvoiceReport(osv.osv):
  4. _inherit = 'account.invoice.report'
  5. _columns = {
  6. 'discount': fields.float('Discount', readonly=True,digits=dp.get_precision('Discount')),
  7. }
  8. def _select(self):
  9. res = super(DiscountInvoiceReport,self)._select()
  10. select_str = res + """, sub.discount / cr.rate as discount """
  11. return select_str
  12. def _sub_select(self):
  13. res = super(DiscountInvoiceReport,self)._sub_select()
  14. select_str = res + """,SUM(CASE
  15. WHEN ai.type::text = ANY (ARRAY['out_refund'::character varying::text, 'in_invoice'::character varying::text])
  16. THEN - ((ail.quantity / u.factor * u2.factor) * ail.price_unit * (ail.discount) / 100.0)
  17. ELSE ((ail.quantity / u.factor * u2.factor) * ail.price_unit * (ail.discount) / 100.0) END) as discount"""
  18. return select_str