[MERGE] account: cleanup refund creation + ease inheritance, courtesy of Benoit Guill...
[odoo/odoo.git] / addons / point_of_sale / wizard / pos_box.py
1 #!/usr/bin/env python
2
3 from openerp.osv import osv, fields
4 from openerp.tools.translate import _
5
6 from openerp.addons.account.wizard.pos_box import CashBox
7
8 class PosBox(CashBox):
9     _register = False
10
11     def run(self, cr, uid, ids, context=None):
12         if not context:
13             context = dict()
14
15         active_model = context.get('active_model', False) or False
16         active_ids = context.get('active_ids', []) or []
17
18         if active_model == 'pos.session':
19             records = self.pool.get(active_model).browse(cr, uid, active_ids, context=context)
20             bank_statements = [record.cash_register_id for record in records if record.cash_register_id]
21
22             if not bank_statements:
23                 raise osv.except_osv(_('Error!'),
24                                      _("There is no cash register for this PoS Session"))
25
26             return self._run(cr, uid, ids, bank_statements, context=context)
27         else:
28             return super(PosBox, self).run(cr, uid, ids, context=context)
29
30 class PosBoxIn(PosBox):
31     _inherit = 'cash.box.in'
32
33     def _compute_values_for_statement_line(self, cr, uid, box, record, context=None):
34         values = super(PosBoxIn, self)._compute_values_for_statement_line(cr, uid, box, record, context=context)
35
36         active_model = context.get('active_model', False) or False
37         active_ids = context.get('active_ids', []) or []
38
39         if active_model == 'pos.session':
40             session = self.pool.get(active_model).browse(cr, uid, active_ids, context=context)[0]
41             values['ref'] = session.name
42
43         return values
44
45
46 class PosBoxOut(PosBox):
47     _inherit = 'cash.box.out'
48
49     def _compute_values_for_statement_line(self, cr, uid, box, record, context=None):
50         values = super(PosBoxOut, self)._compute_values_for_statement_line(cr, uid, box, record, context=context)
51
52         active_model = context.get('active_model', False) or False
53         active_ids = context.get('active_ids', []) or []
54
55         if active_model == 'pos.session':
56             session = self.pool.get(active_model).browse(cr, uid, active_ids, context=context)[0]
57             values['ref'] = session.name
58
59         return values