def get_deposit_balance(self, deposit_account): 'Return the deposit account balance (debit - credit) for the party' pool = Pool() MoveLine = pool.get('account.move.line') cursor = Transaction().cursor line = MoveLine.__table__() assert deposit_account.kind == 'deposit' cursor.lock(MoveLine._table) cursor.execute(*line.select( Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0)), where=(line.account == deposit_account.id) & (line.party == self.id) & (line.reconciliation == Null))) amount, = cursor.fetchone() if amount and not isinstance(amount, Decimal): currency = deposit_account.company.currency amount = currency.round(Decimal(str(amount))) return amount or Decimal(0)
def create(cls, vlist): cursor = Transaction().cursor cursor.lock(cls._table) vlist = [v.copy() for v in vlist] for values in vlist: if not values.get('code'): start = time.time() while True: code = cls.generate_code() same = cls.search([ ('code', '=', code), ('disabled', '=', False), ]) if not same: break now = time.time() if now - start > timeout: cls.raise_user_error('timeout') values['code'] = code return super(Badge, cls).create(vlist)