[MERGE] account: cash register view improvements
authorThibault Delavallée <tde@openerp.com>
Thu, 2 Jan 2014 11:30:09 +0000 (12:30 +0100)
committerThibault Delavallée <tde@openerp.com>
Thu, 2 Jan 2014 11:30:09 +0000 (12:30 +0100)
- now looking like cash control methods from the point of sale module.

point of sale: improved some tooltips + cash control form view improvements

bzr revid: tde@openerp.com-20140102113009-lb1vv2w3g4dz2oqw

1  2 
addons/account/account_bank_statement.py
addons/account/account_cash_statement.py
addons/point_of_sale/point_of_sale.py

@@@ -449,23 -450,26 +450,26 @@@ class account_bank_statement(osv.osv)
  
      def _compute_balance_end_real(self, cr, uid, journal_id, context=None):
          res = False
 -        journal = self.pool.get('account.journal').browse(cr, uid, journal_id, context=context)
          if journal_id:
-             cr.execute('SELECT balance_end_real \
-                     FROM account_bank_statement \
-                     WHERE journal_id = %s AND NOT state = %s \
-                     ORDER BY date DESC,id DESC LIMIT 1', (journal_id, 'draft'))
-             res = cr.fetchone()
++            journal = self.pool.get('account.journal').browse(cr, uid, journal_id, context=context)
+             if journal.with_last_closing_balance:
+                 cr.execute('SELECT balance_end_real \
+                       FROM account_bank_statement \
+                       WHERE journal_id = %s AND NOT state = %s \
+                       ORDER BY date DESC,id DESC LIMIT 1', (journal_id, 'draft'))
+                 res = cr.fetchone()
          return res and res[0] or 0.0
  
      def onchange_journal_id(self, cr, uid, statement_id, journal_id, context=None):
          if not journal_id:
              return {}
          balance_start = self._compute_balance_end_real(cr, uid, journal_id, context=context)
-         journal_data = self.pool.get('account.journal').read(cr, uid, journal_id, ['company_id', 'currency'], context=context)
-         company_id = journal_data['company_id']
-         currency_id = journal_data['currency'] or self.pool.get('res.company').browse(cr, uid, company_id[0], context=context).currency_id.id
-         return {'value': {'balance_start': balance_start, 'company_id': company_id, 'currency': currency_id}}
+         journal = self.pool.get('account.journal').browse(cr, uid, journal_id, context=context)
+         currency = journal.currency or journal.company_id.currency_id
 -        res = {'balance_start' : balance_start, 'company_id' : journal.company_id.id, 'currency' : currency.id}
++        res = {'balance_start': balance_start, 'company_id': journal.company_id.id, 'currency': currency.id}
+         if journal.type == 'cash':
+             res['cash_control'] = journal.cash_control
+         return {'value': res}
  
      def unlink(self, cr, uid, ids, context=None):
          stat = self.read(cr, uid, ids, ['state'], context=context)
@@@ -233,7 -240,11 +240,10 @@@ class account_cash_statement(osv.osv)
  
          @return: True on success, False otherwise
          """
--
 -        cashbox_line_obj = self.pool.get('account.cashbox.line')
+         if vals.get('journal_id', False):
++            cashbox_line_obj = self.pool.get('account.cashbox.line')
+             cashbox_ids = cashbox_line_obj.search(cr, uid, [('bank_statement_id', 'in', ids)], context=context)
+             cashbox_line_obj.unlink(cr, uid, cashbox_ids, context)
          res = super(account_cash_statement, self).write(cr, uid, ids, vals, context=context)
          self._update_balances(cr, uid, ids, context)
          return res
@@@ -45,6 -45,17 +45,16 @@@ class pos_config(osv.osv)
          ('deprecated', 'Deprecated')
      ]
  
+     def _get_currency(self, cr, uid, ids, fieldnames, args, context=None):
+         result = dict.fromkeys(ids, False)
 -        user = self.pool.get('res.users')
+         for pos_config in self.browse(cr, uid, ids, context=context):
+             if pos_config.journal_id:
+                 currency_id = pos_config.journal_id.currency.id or pos_config.journal_id.company_id.currency_id.id
+             else:
 -                currency_id = user.browse(cr, uid, uid, context=context).company_id.currency_id.id
++                currency_id = self.pool['res.users'].browse(cr, uid, uid, context=context).company_id.currency_id.id
+             result[pos_config.id] = currency_id
+         return result
      _columns = {
          'name' : fields.char('Point of Sale Name', size=32, select=1,
               required=True, help="An internal identification of the point of sale"),