def get_current_asset(self): pool = Pool() Date = pool.get('ir.date') AccountType = pool.get('account.account.type') today = Date.today() company = Transaction().context.get('company') transaction = Transaction() context = Transaction().context total_current_asset = current_asset = Decimal('0.0') today = Date.today() company = Transaction().context.get('company') to_date = Transaction().context.get('to_date') if self.is_consolidated: companies = context.get('companies', []) date = today if to_date is None else to_date for company in context.get('companies', []): with transaction.set_context(company=company['id'], posted=True, cumulate=True, date=date, to_date=date, from_date=None): current_asset = Decimal('0.0') current_assets = AccountType.search([ ('company', '=', company['id']), ('name', '=', '1) ACTIVOS CORRIENTES') ]) if len(current_assets) == 1: current_asset = current_assets[0].amount * Decimal( '1.0') total_current_asset += current_asset return total_current_asset else: date = today if to_date is None else to_date with transaction.set_context( posted=True, cumulate=True, date=date, to_date=date, from_date=None, ): current_assets = AccountType.search([ ('company', '=', company), ('name', '=', '1) ACTIVOS CORRIENTES') ]) if len(current_assets) == 1: current_asset = current_assets[0].amount * Decimal('1.0') return current_asset
def get_current_asset(self): pool = Pool() Date = pool.get('ir.date') AccountType = pool.get('account.account.type') today = Date.today() company = Transaction().context.get('company') transaction = Transaction() context = Transaction().context total_current_asset = current_asset = Decimal('0.0') today = Date.today() company = Transaction().context.get('company') to_date = Transaction().context.get('to_date') if self.is_consolidated: companies = context.get('companies',[]) date = today if to_date is None else to_date for company in context.get('companies', []): with transaction.set_context(company=company['id'], posted=True, cumulate=True, date=date, to_date=date, from_date=None): current_asset = Decimal('0.0') current_assets = AccountType.search([('company','=',company['id']), ('name','=','1) ACTIVOS CORRIENTES') ]) if len(current_assets)==1: current_asset = current_assets[0].amount * Decimal('1.0') total_current_asset += current_asset return total_current_asset else: date = today if to_date is None else to_date with transaction.set_context( posted=True, cumulate=True, date=date, to_date=date, from_date=None, ): current_assets = AccountType.search([('company','=',company), ('name','=','1) ACTIVOS CORRIENTES')]) if len(current_assets)==1: current_asset = current_assets[0].amount * Decimal('1.0') return current_asset
def do_print_(self, action): #start_date = self.start.date end_date = self.start.to_date #fiscalyear = self.start.fiscalyear.id #start_date = Date(start_date.year, start_date.month, start_date.day) end_date = Date(end_date.year, end_date.month, end_date.day) data = { 'company': self.start.company.id, 'account': self.start.account.id, #'fiscalyear': self.start.fiscalyear.name, #'fiscalyear_id': self.start.fiscalyear.id, #'start_date': self.start.fiscalyear.start_date, 'end_date': self.start.to_date, 'omit_zero': self.start.omit_zero, } action['pyson_context'] = PYSONEncoder().encode({ 'company': self.start.company.id, #'fiscalyear': self.start.fiscalyear.id, #'start_date': start_date, 'end_date': end_date, }) #if self.start.fiscalyear: # action['name'] += ' - %s' % self.start.fiscalyear.rec_name return action, data
def do_open(self, action): pool = Pool() Location = pool.get('stock.location') Lang = pool.get('ir.lang') context = {} context['locations'] = Transaction().context.get('active_ids') date = self.start.forecast_date or datetime.date.max context['stock_date_end'] = Date(date.year, date.month, date.day) action['pyson_context'] = PYSONEncoder().encode(context) locations = Location.browse(context['locations']) for code in [Transaction().language, 'en_US']: langs = Lang.search([ ('code', '=', code), ]) if langs: break lang = langs[0] date = Lang.strftime(date, lang.code, lang.date) action['name'] += ' - (%s) @ %s' % (','.join(l.name for l in locations), date) return action, {}
def get_expenses(self): pool = Pool() Date = pool.get('ir.date') AccountType = pool.get('account.account.type') today = Date.today() transaction = Transaction() context = Transaction().context total_expense = expense = Decimal('0.0') if self.is_consolidated: companies = context.get('companies',[]) for company in context.get('companies', []): with transaction.set_context(company=company['id']): expense = Decimal('0.0') expenses = AccountType.search([('company','=',company['id']), ('name','=','GASTOS FINANCIEROS') ]) if len(expenses)==1: expense = expenses[0].amount * Decimal('1.0') total_expense += expense return total_expense else: company = Transaction().context.get('company') expense = Decimal('0.0') expenses = AccountType.search([('company','=',company), ('name','=','GASTOS FINANCIEROS')]) if len(expenses)==1: expense = expenses[0].amount * Decimal('1.0') return expense
def get_expenses(self): pool = Pool() Date = pool.get('ir.date') AccountType = pool.get('account.account.type') today = Date.today() transaction = Transaction() context = Transaction().context total_expense = expense = Decimal('0.0') if self.is_consolidated: companies = context.get('companies', []) for company in context.get('companies', []): with transaction.set_context(company=company['id']): expense = Decimal('0.0') expenses = AccountType.search([ ('company', '=', company['id']), ('name', '=', 'GASTOS FINANCIEROS') ]) if len(expenses) == 1: expense = expenses[0].amount * Decimal('1.0') total_expense += expense return total_expense else: company = Transaction().context.get('company') expense = Decimal('0.0') expenses = AccountType.search([('company', '=', company), ('name', '=', 'GASTOS FINANCIEROS') ]) if len(expenses) == 1: expense = expenses[0].amount * Decimal('1.0') return expense
def get_cash(self): pool = Pool() Date = pool.get('ir.date') AccountType = pool.get('account.account.type') today = Date.today() company = Transaction().context.get('company') balance = Decimal('0.0') transaction = Transaction() context = Transaction().context total_cash = Decimal('0.0') if self.is_consolidated: companies = context.get('companies', []) for company in context.get('companies', []): with transaction.set_context(company=company['id']): cash = Decimal('0.0') accounts = AccountType.search([ ('company', '=', company['id']), ('name', '=', '10. Efectivo y Equivalencias de Efectivo') ]) if len(accounts) == 1: cash = accounts[0].amount * Decimal('1.0') total_cash += cash return total_cash else: accounts = AccountType.search([ ('company', '=', company), ('name', '=', '10. Efectivo y Equivalencias de Efectivo') ]) if len(accounts) == 1: balance = accounts[0].amount * Decimal('1.0') return balance
def get_cash(self): pool = Pool() Date = pool.get('ir.date') AccountType = pool.get('account.account.type') today = Date.today() company = Transaction().context.get('company') balance = Decimal('0.0') transaction = Transaction() context = Transaction().context total_cash = Decimal('0.0') if self.is_consolidated: companies = context.get('companies',[]) for company in context.get('companies', []): with transaction.set_context(company=company['id']): cash = Decimal('0.0') accounts = AccountType.search([('company','=',company['id']), ('name','=','10. Efectivo y Equivalencias de Efectivo') ]) if len(accounts)==1: cash = accounts[0].amount * Decimal('1.0') total_cash += cash return total_cash else: accounts = AccountType.search([('company','=',company), ('name','=','10. Efectivo y Equivalencias de Efectivo')]) if len(accounts)==1: balance = accounts[0].amount * Decimal('1.0') return balance
def get_recommended_capital(self): pool = Pool() Date = pool.get('ir.date') Fiscalyear = pool.get('account.fiscalyear') Budget = pool.get('account.budget') today = Date.today() transaction = Transaction() context = Transaction().context company = context.get('company') balance = Decimal('0.0') if self.is_consolidated: companies = context.get('companies',[]) for company in context.get('companies', []): total_amount = Decimal('0.0') with transaction.set_context(company=company['id']): fiscalyears = Fiscalyear.search([('company','=',company['id']), ('start_date','<=',today), ('end_date','>=',today)]) fiscalyear = None if len(fiscalyears)==1: fiscalyear = fiscalyears[0].id budgets = Budget.search([('fiscalyear','=',fiscalyear), ('company','=',company['id']), ('parent','=',None)]) if len(budgets)==1: budget = Budget(budgets[0].id) balance += budget.children[1].amount * Decimal('0.15') #balance *= -1 else: fiscalyear = Transaction().context.get('fiscalyear') if fiscalyear is not None: fiscalyears = Fiscalyear.search([('company','=',company), ('id','=',fiscalyear) ]) else: fiscalyears = Fiscalyear.search([('company','=',company), ('start_date','<=',today), ('end_date','>=',today)]) if len(fiscalyears)==1: fiscalyear = fiscalyears[0].id budgets = Budget.search([('fiscalyear','=',fiscalyear), ('company','=',company), ('parent','=',None)]) if len(budgets)==1: budget = Budget(budgets[0].id) print("BUDGET: ", str(budget)) balance = budget.children[0].amount * Decimal('0.15') print("BALANCE: ", str(balance)) #balance *= -1 return balance
def do_print_(self, action): start_date = self.start.from_date end_date = self.start.to_date start_date = Date(start_date.year, start_date.month, start_date.day) end_date = Date(end_date.year, end_date.month, end_date.day) data = { 'company': self.start.company.id, #'fiscalyear': self.start.fiscalyear.name, #'fiscalyear_id': self.start.fiscalyear.id, 'start_date': self.start.from_date, 'end_date': self.start.to_date, } action['pyson_context'] = PYSONEncoder().encode({ #'company': self.start.company.id, 'start_date': start_date, 'end_date': end_date, }) return action, data
def get_recommended_capital(self): pool = Pool() Date = pool.get('ir.date') Fiscalyear = pool.get('account.fiscalyear') Budget = pool.get('account.budget') today = Date.today() transaction = Transaction() context = Transaction().context company = context.get('company') balance = Decimal('0.0') if self.is_consolidated: companies = context.get('companies', []) for company in context.get('companies', []): total_amount = Decimal('0.0') with transaction.set_context(company=company['id']): fiscalyears = Fiscalyear.search([ ('company', '=', company['id']), ('start_date', '<=', today), ('end_date', '>=', today) ]) fiscalyear = None if len(fiscalyears) == 1: fiscalyear = fiscalyears[0].id budgets = Budget.search([('fiscalyear', '=', fiscalyear), ('company', '=', company['id']), ('parent', '=', None)]) if len(budgets) == 1: budget = Budget(budgets[0].id) balance += budget.children[1].amount * Decimal('0.15') #balance *= -1 else: fiscalyear = Transaction().context.get('fiscalyear') if fiscalyear is not None: fiscalyears = Fiscalyear.search([('company', '=', company), ('id', '=', fiscalyear)]) else: fiscalyears = Fiscalyear.search([('company', '=', company), ('start_date', '<=', today), ('end_date', '>=', today)]) if len(fiscalyears) == 1: fiscalyear = fiscalyears[0].id budgets = Budget.search([('fiscalyear', '=', fiscalyear), ('company', '=', company), ('parent', '=', None)]) if len(budgets) == 1: budget = Budget(budgets[0].id) print("BUDGET: ", str(budget)) balance = budget.children[0].amount * Decimal('0.15') print("BALANCE: ", str(balance)) #balance *= -1 return balance
def do_print_(self, action): start_date = self.start.fiscalyear.start_date end_date = self.start.fiscalyear.end_date fiscalyear = self.start.fiscalyear.id start_date = Date(start_date.year, start_date.month, start_date.day) end_date = Date(end_date.year, end_date.month, end_date.day) data = { 'company': self.start.company.id, 'budget': self.start.budget.id, 'fiscalyear': self.start.fiscalyear.name, 'start_date': self.start.fiscalyear.start_date, 'end_date': self.start.fiscalyear.end_date, } action['pyson_context'] = PYSONEncoder().encode({ 'company': self.start.company.id, 'fiscalyear': self.start.fiscalyear.id, }) if self.start.fiscalyear: action['name'] += ' - %s' % self.start.fiscalyear.rec_name return action, data
class Checkout(ModelSQL, ModelView): 'Checkout' __name__ = 'library.user.checkout' user = fields.Many2One('library.user', 'User', required=True, ondelete='CASCADE', select=True) exemplary = fields.Many2One('library.book.exemplary', 'Exemplary', required=True, ondelete='CASCADE', select=True) date = fields.Date('Date', required=True, domain=[('date', '<=', Date())]) return_date = fields.Date('Return Date', domain=[ If(~Eval('return_date'), [], [('return_date', '<=', Date()), ('return_date', '>=', Eval('date'))]) ], depends=['date']) expected_return_date = fields.Function( fields.Date('Expected return date', help='The date at which the ' 'exemplary is supposed to be returned'), 'getter_expected_return_date', searcher='search_expected_return_date') def getter_expected_return_date(self, name): return self.date + datetime.timedelta(days=20) @classmethod def search_expected_return_date(cls, name, clause): _, operator, value = clause if isinstance(value, datetime.date): value = value + datetime.timedelta(days=-20) if isinstance(value, (list, tuple)): value = [(x + datetime.timedelta(days=-20) if x else x) for x in value] return [('date', operator, value)]
def do_print_(self, action): start_date = self.start.start_date end_date = self.start.end_date start_date = Date(start_date.year, start_date.month, start_date.day) end_date = Date(end_date.year, end_date.month, end_date.day) data = { 'company': self.start.company.id, 'account': self.start.account.id, #'fiscalyear': self.start.fiscalyear.name, 'start_date': self.start.start_date, 'end_date': self.start.end_date, 'omit_zero': self.start.omit_zero, } action['pyson_context'] = PYSONEncoder().encode({ 'company': self.start.company.id, 'start_date': start_date, 'end_date': end_date, }) return action, data
def do_enter(self, action): date = self.start.date date = Date(date.year, date.month, date.day) action['pyson_domain'] = PYSONEncoder().encode([ ('employee', '=', self.start.employee.id), ('date', '=', date), ]) action['pyson_context'] = PYSONEncoder().encode({ 'employee': self.start.employee.id, 'date': date, }) action['name'] += " - " + self.start.employee.rec_name return action, {}
def _get_budget_value(self, budget=None): ''' Set the values for budget creation. ''' Date = Pool().get('ir.date') today = Date.today() year = today.year res = {} if not budget or budget.name != self.name: res['name'] = self.name if not budget or budget.amount != self.amount: res['amount'] = self.amount if not budget or budget.template != self: res['template'] = self.id return res
def do_enter(self, action): pool = Pool() Lang = pool.get('ir.lang') date = self.start.date date = Date(date.year, date.month, date.day) action['pyson_domain'] = PYSONEncoder().encode([ ('employee', '=', self.start.employee.id), ('company', '=', self.start.employee.company.id), ('date', '=', date), ]) action['pyson_context'] = PYSONEncoder().encode({ 'employee': self.start.employee.id, 'company': self.start.employee.company.id, 'date': date, }) action['name'] += ' @ %(date)s - %(employee)s' % { 'date': Lang.get().strftime(self.start.date), 'employee': self.start.employee.rec_name, } return action, {}
def get_current_capital(self): pool = Pool() Date = pool.get('ir.date') AccountType = pool.get('account.account.type') today = Date.today() company = Transaction().context.get('company') current_capital = current_liability = Decimal('0.0') current_capitals = AccountType.search([('company','=',company), ('name','=','1) ACTIVOS CORRIENTES')]) if len(current_capitals)==1: current_capital = current_capitals[0].amount * Decimal('1.0') current_liabilities = AccountType.search([('company','=',company), ('name','=','3) PASIVOS CORRIENTES')]) if len(current_liabilities)==1: current_liability = current_liabilities[0].amount * Decimal('1.0') balance = (current_capital - current_liability) * Decimal('1.0') return balance
def get_current_capital(self): pool = Pool() Date = pool.get('ir.date') AccountType = pool.get('account.account.type') today = Date.today() company = Transaction().context.get('company') current_capital = current_liability = Decimal('0.0') current_capitals = AccountType.search([('company', '=', company), ('name', '=', '1) ACTIVOS CORRIENTES')]) if len(current_capitals) == 1: current_capital = current_capitals[0].amount * Decimal('1.0') current_liabilities = AccountType.search([('company', '=', company), ('name', '=', '3) PASIVOS CORRIENTES')]) if len(current_liabilities) == 1: current_liability = current_liabilities[0].amount * Decimal('1.0') balance = (current_capital - current_liability) * Decimal('1.0') return balance
def default_to_date(cls): Date = Pool().get('ir.date') return Date.today()
class User(ModelSQL, ModelView): 'Library User' __name__ = 'library.user' checkouts = fields.One2Many('library.user.checkout', 'user', 'Checkouts') name = fields.Char('Name', required=True) registration_date = fields.Date( 'Registration Date', domain=[ If(~Eval('registration_date'), [], [('registration_date', '<=', Date())]) ], help='The date at which the user registered in the library') checkedout_books = fields.Function( fields.Integer('Checked-out books', help='The number of books a user ' 'has currently checked out'), 'getter_checkedout_books') late_checkedout_books = fields.Function( fields.Integer('Late checked-out books', help='The number of books a ' 'user is late returning'), 'getter_checkedout_books') expected_return_date = fields.Function( fields.Date('Expected return date', help='The date at which the user ' 'is (or was) expected to return his books'), 'getter_checkedout_books', searcher='search_expected_return_date') @classmethod def getter_checkedout_books(cls, users, name): checkout = Pool().get('library.user.checkout').__table__() cursor = Transaction().connection.cursor() default_value = None if name not in ('checkedout_books', 'late_checkedout_books'): default_value = 0 result = {x.id: default_value for x in users} column, where = cls._get_checkout_column(checkout, name) cursor.execute( *checkout.select(checkout.user, column, where=where & checkout.user.in_([x.id for x in users]), group_by=[checkout.user])) for user_id, value in cursor.fetchall(): result[user_id] = value if name == 'expected_return_date' and value: result[user_id] += datetime.timedelta(days=20) return result @classmethod def _get_checkout_column(cls, checkout_table, name): column, where = None, None if name == 'checkedout_books': column = Count(checkout_table.id) where = checkout_table.return_date == Null elif name == 'late_checkedout_books': column = Count(checkout_table.id) where = (checkout_table.return_date == Null) & (checkout_table.date < datetime.date.today() + datetime.timedelta(days=20)) elif name == 'expected_return_date': column = Min(checkout_table.date) where = checkout_table.return_date == Null else: raise Exception('Invalid function field name %s' % name) return column, where @classmethod def search_expected_return_date(cls, name, clause): user = cls.__table__() checkout = Pool().get('library.user.checkout').__table__() _, operator, value = clause if isinstance(value, datetime.date): value = value + datetime.timedelta(days=-20) if isinstance(value, (list, tuple)): value = [(x + datetime.timedelta(days=-20) if x else x) for x in value] Operator = SQL_OPERATORS[operator] query_table = user.join(checkout, 'LEFT OUTER', condition=checkout.user == user.id) query = query_table.select(user.id, where=(checkout.return_date == Null) | (checkout.id == Null), group_by=user.id, having=Operator(Min(checkout.date), value)) return [('id', 'in', query)]