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
25 class pos_details_summary(report_sxw.rml_parse):
26 def __init__(self, cr, uid, name, context):
27 super(pos_details_summary, self).__init__(cr, uid, name, context=context)
29 self.localcontext.update({
31 'strip_name': self._strip_name,
32 'getpayments': self._get_payments,
33 'getqtytotal': self._get_qty_total,
34 'getsumdisc': self._get_sum_discount,
35 'getpaidtotal': self._paid_total,
36 'gettotalofthaday': self._total_of_the_day,
37 'getsuminvoice': self._sum_invoice,
38 'gettaxamount': self._get_tax_amount,
39 'getsalestotal': self._get_sales_total,
40 'getstartperiod': self._get_start_period,
41 'getendperiod': self._get_end_period,
42 'getcompany':self.get_company
45 def get_company(self,objects):
46 comp=[obj.company_id.name for obj in objects]
47 return '%s' % (comp[0])
49 def _get_qty_total(self, objects):
50 #code for the sum of qty_total
51 return reduce(lambda acc, object:
60 def _get_sum_discount(self, objects):
61 #code for the sum of discount value
62 return reduce(lambda acc, object:
65 sum_dis + ((line.price_unit * line.qty ) * (line.discount / 100)),
71 def _get_payments(self, objects):
72 # gift_journal_id = None
74 # config_journal_ids = self.pool.get("pos.config.journal").search(self.cr, self.uid, [('code', '=', 'GIFT')])
75 # if len(config_journal_ids):
76 # config_journal = self.pool.get("pos.config.journal").browse(self.cr, self.uid, config_journal_ids, {})[0]
77 # gift_journal_id = config_journal.journal_id.id
81 for statement in obj.statement_ids:
82 if statement.journal_id:
83 result[statement.journal_id] = result.get(statement.journal_id, 0.0) + statement.amount
86 def _paid_total(self, objects):
87 return sum(self._get_payments(objects).values(), 0.0)
89 def _total_of_the_day(self, objects):
90 total_paid = self._paid_total(objects)
91 total_invoiced = self._sum_invoice(objects)
92 return total_paid - total_invoiced
94 def _sum_invoice(self, objects):
95 return reduce(lambda acc, obj:
96 acc + obj.invoice_id.amount_total,
97 [o for o in objects if o.invoice_id and o.invoice_id.number],
100 def _ellipsis(self, string, maxlen=100, ellipsis = '...'):
101 ellipsis = ellipsis or ''
102 return string[:maxlen - len(ellipsis) ] + (ellipsis, '')[len(string) < maxlen]
104 def _strip_name(self, name, maxlen=50):
105 return self._ellipsis(name, maxlen, ' ...')
107 def _get_tax_amount(self, objects):
110 for order in objects:
111 for line in order.lines:
112 if len(line.product_id.taxes_id):
113 tax = line.product_id.taxes_id[0]
114 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)
115 list_ids.append(tax.id)
118 def _get_sales_total(self, objects):
119 return reduce(lambda x, o: x + len(o.lines), objects, 0)
121 def _get_start_period(self, objects):
122 date_orders = sorted([obj.date_order for obj in objects])
123 min_date = date_orders[0]
124 return '%s' % min_date
127 def _get_end_period(self, objects):
128 date_orders = sorted([obj.date_order for obj in objects])
129 max_date = date_orders[-1]
130 return '%s' % max_date
133 report_sxw.report_sxw('report.pos.details_summary',
135 'addons/point_of_sale/report/pos_details_summary.rml',
136 parser=pos_details_summary,
139 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: