1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
24 from report import report_sxw
27 class pos_details_summary(report_sxw.rml_parse):
29 def _get_qty_total(self, objects):
30 #code for the sum of qty_total
31 return reduce(lambda acc, object:
40 def _get_sum_discount(self, objects):
41 #code for the sum of discount value
42 return reduce(lambda acc, object:
45 sum_dis + ((line.price_unit * line.qty ) * (line.discount / 100)),
51 def _get_payments(self, objects, ignore_gift=False):
52 gift_journal_id = None
54 config_journal_ids = self.pool.get("pos.config.journal").search(self.cr, self.uid, [('code', '=', 'GIFT')])
55 if len(config_journal_ids):
56 config_journal = self.pool.get("pos.config.journal").browse(self.cr, self.uid, config_journal_ids, {})[0]
57 gift_journal_id = config_journal.journal_id.id
61 for payment in obj.payments:
62 if gift_journal_id and gift_journal_id == payment.journal_id.id:
64 result[payment.journal_id.name] = result.get(payment.journal_id.name, 0.0) + payment.amount
67 def _paid_total(self, objects):
68 return sum(self._get_payments(objects, True).values(), 0.0)
70 def _total_of_the_day(self, objects):
71 total_paid = sum(self._get_payments(objects, True).values(), 0.0)
72 total_invoiced = self._sum_invoice(objects)
73 return total_paid - total_invoiced
75 def _sum_invoice(self, objects):
76 return reduce(lambda acc, obj:
77 acc + obj.invoice_id.amount_total,
78 [o for o in objects if o.invoice_id and o.invoice_id.number],
81 def _ellipsis(self, string, maxlen=100, ellipsis = '...'):
82 ellipsis = ellipsis or ''
83 return string[:maxlen - len(ellipsis) ] + (ellipsis, '')[len(string) < maxlen]
85 def _strip_name(self, name, maxlen=50):
86 return self._ellipsis(name, maxlen, ' ...')
88 def _get_tax_amount(self, objects):
92 for line in order.lines:
93 if len(line.product_id.taxes_id):
94 tax = line.product_id.taxes_id[0]
95 res[tax.name] = (line.price_unit * line.qty * (1-(line.discount or 0.0) / 100.0)) + (tax.id in list_ids and res[tax.name] or 0)
96 list_ids.append(tax.id)
99 def _get_sales_total(self, objects):
100 return reduce(lambda x, o: x + len(o.lines), objects, 0)
102 def _get_period(self, objects):
103 date_orders = [obj.date_order for obj in objects]
104 min_date = min(date_orders)
105 max_date = max(date_orders)
106 if min_date == max_date:
107 return '%s' % min_date
109 return '%s - %s' % (min_date, max_date)
111 def __init__(self, cr, uid, name, context):
112 super(pos_details_summary, self).__init__(cr, uid, name, context=context)
114 self.localcontext.update({
116 'strip_name': self._strip_name,
117 'getpayments': self._get_payments,
118 'getqtytotal': self._get_qty_total,
119 'getsumdisc': self._get_sum_discount,
120 'getpaidtotal': self._paid_total,
121 'gettotalofthaday': self._total_of_the_day,
122 'getsuminvoice': self._sum_invoice,
123 'gettaxamount': self._get_tax_amount,
124 'getsalestotal': self._get_sales_total,
125 'getperiod': self._get_period,
128 report_sxw.report_sxw('report.pos.details_summary',
130 'addons/point_of_sale/report/pos_details_summary.rml',
131 parser=pos_details_summary,
134 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: