1 # -*- encoding: utf-8 -*-
2 ###############################################################################
4 ## Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
6 ## WARNING: This program as such is intended to be used by professional
7 ## programmers who take the whole responsability of assessing all potential
8 ## consequences resulting from its eventual inadequacies and bugs
9 ## End users who are looking for a ready-to-use solution with commercial
10 ## garantees and support are strongly adviced to contract a Free Software
13 ## This program is Free Software; you can redistribute it and/or
14 ## modify it under the terms of the GNU General Public License
15 ## as published by the Free Software Foundation; either version 2
16 ## of the License, or (at your option) any later version.
18 ## This program is distributed in the hope that it will be useful,
19 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ## GNU General Public License for more details.
23 ## You should have received a copy of the GNU General Public License
24 ## along with this program; if not, write to the Free Software
25 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ###############################################################################
30 from report import report_sxw
33 class pos_details(report_sxw.rml_parse):
35 def _get_qty_total(self, objects):
36 #code for the sum of qty_total
37 return reduce(lambda acc, object:
46 def _get_sum_discount(self, objects):
47 #code for the sum of discount value
48 return reduce(lambda acc, object:
51 sum_dis + ((line.price_unit * line.qty) * (line.discount / 100)),
57 def _get_payments(self, objects, ignore_gift=False):
58 gift_journal_id = None
60 config_journal_ids = self.pool.get("pos.config.journal").search(self.cr, self.uid, [('code', '=', 'GIFT')])
61 if len(config_journal_ids):
62 config_journal = self.pool.get("pos.config.journal").browse(self.cr, self.uid, config_journal_ids, {})[0]
63 gift_journal_id = config_journal.journal_id.id
67 for payment in obj.payments:
68 if gift_journal_id and gift_journal_id == payment.journal_id.id:
70 result[payment.journal_id.name] = result.get(payment.journal_id.name, 0.0) + payment.amount
73 def _paid_total(self, objects):
74 return sum(self._get_payments(objects, True).values(), 0.0)
76 def _total_of_the_day(self, objects):
77 total_paid = sum(self._get_payments(objects, True).values(), 0.0)
78 total_invoiced = self._sum_invoice(objects)
79 return total_paid - total_invoiced
81 def _sum_invoice(self, objects):
82 return reduce(lambda acc, obj:
83 acc + obj.invoice_id.amount_total,
84 [o for o in objects if o.invoice_id and o.invoice_id.number],
87 def _ellipsis(self, orig_str, maxlen=100, ellipsis='...'):
88 maxlen = maxlen - len(ellipsis)
91 new_str = orig_str[:maxlen]
94 def _strip_name(self, name, maxlen=50):
95 return self._ellipsis(name, maxlen, ' ...')
97 def _get_tax_amount(self, objects):
100 for order in objects:
101 for line in order.lines:
102 if len(line.product_id.taxes_id):
103 tax = line.product_id.taxes_id[0]
104 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)
105 list_ids.append(tax.id)
108 def _get_sales_total(self, objects):
109 return reduce(lambda x, o: x + len(o.lines), objects, 0)
111 def _get_period(self, objects):
112 date_orders = [obj.date_order for obj in objects]
113 min_date = min(date_orders)
114 max_date = max(date_orders)
115 if min_date == max_date:
116 return '%s' % min_date
118 return '%s - %s' % (min_date, max_date)
120 def __init__(self, cr, uid, name, context):
121 super(pos_details, self).__init__(cr, uid, name, context)
123 self.localcontext.update({
125 'strip_name': self._strip_name,
126 'getpayments': self._get_payments,
127 'getqtytotal': self._get_qty_total,
128 'getsumdisc': self._get_sum_discount,
129 'getpaidtotal': self._paid_total,
130 'gettotalofthaday': self._total_of_the_day,
131 'getsuminvoice': self._sum_invoice,
132 'gettaxamount': self._get_tax_amount,
133 'getsalestotal': self._get_sales_total,
134 'getperiod': self._get_period,
137 report_sxw.report_sxw('report.pos.details', 'pos.order', 'addons/point_of_sale/report/pos_details.rml', parser=pos_details, header=None)
139 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: