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 osv import osv, fields
24 from tools.translate import _
25 import pos_box_entries
29 class pos_make_payment(osv.osv_memory):
30 _name = 'pos.make.payment'
31 _description = 'Point of Sale Payment'
33 def default_get(self, cr, uid, fields, context=None):
35 To get default values for the object.
36 @param self: The object pointer.
37 @param cr: A database cursor
38 @param uid: ID of the user currently logged in
39 @param fields: List of fields for which we want default values
40 @param context: A standard dictionary
41 @return: A dictionary which of fields with values.
46 res = super(pos_make_payment, self).default_get(cr, uid, fields, context=context)
47 record_id = context and context.get('active_id', False)
48 j_obj = self.pool.get('account.journal')
49 company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
50 journal = j_obj.search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', company_id)])
56 order = self.pool.get('pos.order').browse(cr, uid, record_id, context)
58 amount = order.amount_total - order.amount_paid
61 context.update({'flag': True})
62 self.pool.get('pos.order').action_paid(cr, uid, [record_id], context)
63 elif order.amount_paid > 0.0:
64 self.pool.get('pos.order').write(cr, uid, [record_id], {'state': 'advance'})
66 invoice_wanted_checked = False
68 current_date = time.strftime('%Y-%m-%d')
70 if 'journal' in fields:
71 res.update({'journal': journal})
72 if 'amount' in fields:
73 res.update({'amount': amount})
74 if 'invoice_wanted' in fields:
75 res.update({'invoice_wanted': invoice_wanted_checked})
76 if 'payment_date' in fields:
77 res.update({'payment_date': current_date})
78 if 'payment_name' in fields:
79 res.update({'payment_name': 'Payment'})
82 def view_init(self, cr, uid, fields_list, context=None):
83 res = super(pos_make_payment, self).view_init(cr, uid, fields_list, context=context)
84 record_id = context and context.get('active_id', False) or False
85 order = self.pool.get('pos.order').browse(cr, uid, record_id)
87 raise osv.except_osv('Error!', 'No Order Lines ')
90 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
92 Changes the view dynamically
94 @param self: The object pointer.
95 @param cr: A database cursor
96 @param uid: ID of the user currently logged in
97 @param context: A standard dictionary
99 @return: New arch of view.
102 record_id = context and context.get('record_id', False) or False
103 res = super(pos_make_payment, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False)
106 order = self.pool.get('pos.order').browse(cr, uid, record_id)
107 amount = order.amount_total - order.amount_paid
109 res['arch'] = """ <form string="Make Payment" colspan="4">
110 <group col="2" colspan="2">
111 <label string="Do you want to print the Receipt?" colspan="4"/>
112 <separator colspan="4"/>
113 <button icon="gtk-cancel" special="cancel" string="No" readonly="0"/>
114 <button name="print_report" string="Print Receipt" type="object" icon="gtk-print"/>
120 def check(self, cr, uid, ids, context=None):
123 if the order is not paid: continue payment,
124 if the order is paid print invoice (if wanted) or ticket.
126 record_id = context and context.get('active_id', False)
127 order_obj = self.pool.get('pos.order')
128 jrnl_obj = self.pool.get('account.journal')
129 order = order_obj.browse(cr, uid, record_id, context)
130 amount = order.amount_total - order.amount_paid
131 data = self.read(cr, uid, ids)[0]
133 # Todo need to check ...
135 invoice_wanted = data['invoice_wanted']
136 order_obj.write(cr, uid, [record_id], {'invoice_wanted': invoice_wanted})
137 order_obj.add_payment(cr, uid, record_id, data, context=context)
140 context.update({'flag': True})
141 order_obj.action_paid(cr, uid, [record_id], context)
142 if order_obj.test_paid(cr, uid, [record_id]):
143 if order.partner_id and order.invoice_wanted:
144 return self.create_invoice(cr, uid, ids, context)
146 order_obj.write(cr, uid, [record_id],{'state':'paid'})
147 return self.print_report(cr, uid, ids, context)
148 if order.amount_paid > 0.0:
149 self.pool.get('pos.order').write(cr, uid, [record_id],{'state':'advance'})
150 return self.print_report(cr, uid, ids, context)
153 def create_invoice(self, cr, uid, ids, context):
154 wf_service = netsvc.LocalService("workflow")
155 record_ids = context and context.get('active_ids', False)
157 wf_service.trg_validate(uid, 'pos.order', i, 'invoice', cr)
158 datas = {'ids': context.get('active_ids', [])}
160 'type': 'ir.actions.report.xml',
161 'report_name': 'pos.invoice',
165 def print_report(self, cr, uid, ids, context=None):
167 @summary: To get the date and print the report
168 @param self: The object pointer.
169 @param cr: A database cursor
170 @param uid: ID of the user currently logged in
171 @param context: A standard dictionary
172 @return : retrun report
177 datas = {'ids': context.get('active_ids', [])}
181 'type': 'ir.actions.report.xml',
182 'report_name': 'pos.receipt',
186 def trigger_wkf(self, cr, uid, data, context):
187 record_id = context and context.get('active_id', False)
188 wf_service = netsvc.LocalService("workflow")
189 wf_service.trg_validate(uid, 'pos.order', record_id, 'payment', cr)
193 'journal': fields.selection(pos_box_entries.get_journal, "Journal", required=True),
194 'product_id': fields.many2one('product.product', "Acompte"),
195 'amount': fields.float('Amount', digits=(16, 2), required= True),
196 'payment_name': fields.char('Payment name', size=32, required=True),
197 'payment_date': fields.date('Payment date', required=True),
198 'is_acc': fields.boolean('Accompte'),
199 'invoice_wanted': fields.boolean('Invoice'),
200 'num_sale': fields.char('Num.File', size=32),
205 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: