1 from openerp.osv import fields, osv
2 import openerp.addons.decimal_precision as dp
3 from openerp.tools.translate import _
5 class CashBox(osv.osv_memory):
8 'name' : fields.char('Reason', required=True),
9 # Attention, we don't set a domain, because there is a journal_type key
10 # in the context of the action
11 'amount' : fields.float('Amount',
12 digits_compute = dp.get_precision('Account'),
16 def run(self, cr, uid, ids, context=None):
20 active_model = context.get('active_model', False) or False
21 active_ids = context.get('active_ids', []) or []
23 records = self.pool[active_model].browse(cr, uid, active_ids, context=context)
25 return self._run(cr, uid, ids, records, context=context)
27 def _run(self, cr, uid, ids, records, context=None):
28 for box in self.browse(cr, uid, ids, context=context):
29 for record in records:
30 if not record.journal_id:
31 raise osv.except_osv(_('Error!'),
32 _("Please check that the field 'Journal' is set on the Bank Statement"))
34 if not record.journal_id.internal_account_id:
35 raise osv.except_osv(_('Error!'),
36 _("Please check that the field 'Internal Transfers Account' is set on the payment method '%s'.") % (record.journal_id.name,))
38 self._create_bank_statement_line(cr, uid, box, record, context=context)
42 def _create_bank_statement_line(self, cr, uid, box, record, context=None):
43 values = self._compute_values_for_statement_line(cr, uid, box, record, context=context)
44 return self.pool.get('account.bank.statement.line').create(cr, uid, values, context=context)
47 class CashBoxIn(CashBox):
50 _columns = CashBox._columns.copy()
52 'ref': fields.char('Reference'),
55 def _compute_values_for_statement_line(self, cr, uid, box, record, context=None):
56 if not record.journal_id.internal_account_id.id:
57 raise osv.except_osv(_('Configuration Error'), _("You should have defined an 'Internal Transfer Account' in your cash register's journal!"))
59 'statement_id': record.id,
60 'journal_id': record.journal_id.id,
61 'amount': box.amount or 0.0,
62 'account_id': record.journal_id.internal_account_id.id,
63 'ref': '%s' % (box.ref or ''),
68 class CashBoxOut(CashBox):
69 _name = 'cash.box.out'
71 _columns = CashBox._columns.copy()
73 def _compute_values_for_statement_line(self, cr, uid, box, record, context=None):
74 if not record.journal_id.internal_account_id.id:
75 raise osv.except_osv(_('Configuration Error'), _("You should have defined an 'Internal Transfer Account' in your cash register's journal!"))
76 amount = box.amount or 0.0
78 'statement_id': record.id,
79 'journal_id': record.journal_id.id,
80 'amount': -amount if amount > 0.0 else amount,
81 'account_id': record.journal_id.internal_account_id.id,