1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
23 from report import report_sxw
26 class pos_details_summary(report_sxw.rml_parse):
28 def get_company(self,objects):
29 comp=[obj.company_id.name for obj in objects]
30 return '%s' % (comp[0])
32 def _get_qty_total(self, objects):
33 #code for the sum of qty_total
34 return reduce(lambda acc, object:
43 def _get_sum_discount(self, objects):
44 #code for the sum of discount value
45 return reduce(lambda acc, object:
48 sum_dis + ((line.price_unit * line.qty ) * (line.discount / 100)),
54 def _get_payments(self, objects, ignore_gift=False):
55 gift_journal_id = None
57 config_journal_ids = self.pool.get("pos.config.journal").search(self.cr, self.uid, [('code', '=', 'GIFT')])
58 if len(config_journal_ids):
59 config_journal = self.pool.get("pos.config.journal").browse(self.cr, self.uid, config_journal_ids, {})[0]
60 gift_journal_id = config_journal.journal_id.id
64 for payment in obj.payments:
65 if gift_journal_id and gift_journal_id == payment.journal_id.id:
67 result[payment.journal_id.name] = result.get(payment.journal_id.name, 0.0) + payment.amount
70 def _paid_total(self, objects):
71 return sum(self._get_payments(objects, True).values(), 0.0)
73 def _total_of_the_day(self, objects):
74 total_paid = sum(self._get_payments(objects, True).values(), 0.0)
75 total_invoiced = self._sum_invoice(objects)
76 return total_paid - total_invoiced
78 def _sum_invoice(self, objects):
79 return reduce(lambda acc, obj:
80 acc + obj.invoice_id.amount_total,
81 [o for o in objects if o.invoice_id and o.invoice_id.number],
84 def _ellipsis(self, string, maxlen=100, ellipsis = '...'):
85 ellipsis = ellipsis or ''
86 return string[:maxlen - len(ellipsis) ] + (ellipsis, '')[len(string) < maxlen]
88 def _strip_name(self, name, maxlen=50):
89 return self._ellipsis(name, maxlen, ' ...')
91 def _get_tax_amount(self, objects):
95 for line in order.lines:
96 if len(line.product_id.taxes_id):
97 tax = line.product_id.taxes_id[0]
98 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)
99 list_ids.append(tax.id)
102 def _get_sales_total(self, objects):
103 return reduce(lambda x, o: x + len(o.lines), objects, 0)
105 def _get_period(self, objects):
106 date_orders = [obj.date_order for obj in objects]
107 min_date = min(date_orders)
108 max_date = max(date_orders)
109 if min_date == max_date:
110 return '%s' % min_date
112 return '%s - %s' % (min_date, max_date)
114 def __init__(self, cr, uid, name, context):
115 super(pos_details_summary, self).__init__(cr, uid, name, context)
117 self.localcontext.update({
119 'strip_name': self._strip_name,
120 'getpayments': self._get_payments,
121 'getqtytotal': self._get_qty_total,
122 'getsumdisc': self._get_sum_discount,
123 'getpaidtotal': self._paid_total,
124 'gettotalofthaday': self._total_of_the_day,
125 'getsuminvoice': self._sum_invoice,
126 'gettaxamount': self._get_tax_amount,
127 'getsalestotal': self._get_sales_total,
128 'getperiod': self._get_period,
129 'getcompany':self.get_company
132 report_sxw.report_sxw('report.pos.details_summary',
134 'addons/point_of_sale/report/pos_details_summary.rml',
135 parser=pos_details_summary,
138 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: