def create_period(self, ids, interval=1):
     '''
     Create periods for the fiscal years with month interval
     '''
     period_obj = self.pool.get('ekd.period')
     for fiscalyear in self.browse(ids):
         period_start_date = fiscalyear.start_date
         while period_start_date < fiscalyear.end_date:
             period_end_date = period_start_date + \
                         relativedelta(months=interval - 1) + \
                         relativedelta(day=31)
             if period_end_date > fiscalyear.end_date:
                 period_end_date = fiscalyear.end_date
             name = datetime_strftime(period_start_date, '%m-%Y')
             if name != datetime_strftime(period_end_date, '%m-%Y'):
                 name += ' - ' + datetime_strftime(period_end_date, '%Y-%m')
             period_obj.create({
                     'company': fiscalyear.company,
                     'name': name,
                     'code': name,
                     'start_date': period_start_date,
                     'end_date': period_end_date,
                     'fiscalyear': fiscalyear.id,
                     'post_move_sequence': fiscalyear.post_move_sequence.id,
                     'post_move_line_sequence': fiscalyear.post_move_line_sequence.id,
                     'cash_book_sequence': fiscalyear.cash_book_sequence.id,
                     'type': 'standard',
                     'state': 'open',
                     })
             period_start_date = period_end_date + relativedelta(days=1)
     return True
Exemple #2
0
 def create_period(cls, fiscalyears, interval=1):
     '''
     Create periods for the fiscal years with month interval
     '''
     Period = Pool().get('account.period')
     to_create = []
     for fiscalyear in fiscalyears:
         period_start_date = fiscalyear.start_date
         while period_start_date < fiscalyear.end_date:
             period_end_date = period_start_date + \
                 relativedelta(months=interval - 1) + \
                 relativedelta(day=31)
             if period_end_date > fiscalyear.end_date:
                 period_end_date = fiscalyear.end_date
             name = datetime_strftime(period_start_date, '%Y-%m')
             if name != datetime_strftime(period_end_date, '%Y-%m'):
                 name += ' - ' + datetime_strftime(period_end_date, '%Y-%m')
             to_create.append({
                 'name': name,
                 'start_date': period_start_date,
                 'end_date': period_end_date,
                 'fiscalyear': fiscalyear.id,
                 'type': 'standard',
                 })
             period_start_date = period_end_date + relativedelta(days=1)
     if to_create:
         Period.create(to_create)
 def create_period(cls, fiscalyears, interval=1):
     '''
     Create periods for the fiscal years with month interval
     '''
     Period = Pool().get('account.period')
     to_create = []
     for fiscalyear in fiscalyears:
         period_start_date = fiscalyear.start_date
         while period_start_date < fiscalyear.end_date:
             period_end_date = period_start_date + \
                 relativedelta(months=interval - 1) + \
                 relativedelta(day=31)
             if period_end_date > fiscalyear.end_date:
                 period_end_date = fiscalyear.end_date
             name = datetime_strftime(period_start_date, '%Y-%m')
             if name != datetime_strftime(period_end_date, '%Y-%m'):
                 name += ' - ' + datetime_strftime(period_end_date, '%Y-%m')
             to_create.append({
                 'name': name,
                 'start_date': period_start_date,
                 'end_date': period_end_date,
                 'fiscalyear': fiscalyear.id,
                 'type': 'standard',
             })
             period_start_date = period_end_date + relativedelta(days=1)
     if to_create:
         Period.create(to_create)
Exemple #4
0
 def test0070datetime_strftime(self):
     '''
     Test datetime_strftime
     '''
     self.assert_(datetime_strftime(datetime.date(2005, 3, 2),
         '%Y-%m-%d'), '2005-03-02')
     self.assert_(datetime_strftime(datetime.date(1805, 3, 2),
         '%Y-%m-%d'), '1805-03-02')
    def validate_surgery_period(self):
        Lang = Pool().get('ir.lang')

        languages = Lang.search([
            ('code', '=', Transaction().language),
            ])
        if (self.surgery_end_date and self.surgery_date):
            if (self.surgery_end_date < self.surgery_date):
                self.raise_user_error('end_date_before_start', {
                        'surgery_date': datetime_strftime(self.surgery_date,
                            str(languages[0].date)),
                        'end_date': datetime_strftime(self.surgery_end_date,
                            str(languages[0].date)),
                        })
Exemple #6
0
    def compute(cls, from_currency, amount, to_currency, round=True):
        '''
        Take a currency and an amount
        Return the amount to the new currency
        Use the rate of the date of the context or the current date
        '''
        Date = Pool().get('ir.date')
        Lang = Pool().get('ir.lang')
        from_currency = cls(int(from_currency))
        to_currency = cls(int(to_currency))

        if to_currency == from_currency:
            if round:
                return to_currency.round(amount)
            else:
                return amount
        if (not from_currency.rate) or (not to_currency.rate):
            date = Transaction().context.get('date', Date.today())
            if not from_currency.rate:
                name = from_currency.name
            else:
                name = to_currency.name

            languages = Lang.search([
                    ('code', '=', Transaction().language),
                    ])
            cls.raise_user_error('no_rate', {
                    'currency': name,
                    'date': datetime_strftime(date, str(languages[0].date))
                    })
        if round:
            return to_currency.round(
                amount * to_currency.rate / from_currency.rate)
        else:
            return amount * to_currency.rate / from_currency.rate
Exemple #7
0
    def compute(cls, from_currency, amount, to_currency, round=True):
        '''
        Take a currency and an amount
        Return the amount to the new currency
        Use the rate of the date of the context or the current date
        '''
        Date = Pool().get('ir.date')
        Lang = Pool().get('ir.lang')
        from_currency = cls(from_currency.id)
        to_currency = cls(to_currency.id)

        if to_currency == from_currency:
            if round:
                return to_currency.round(amount)
            else:
                return amount
        if (not from_currency.rate) or (not to_currency.rate):
            date = Transaction().context.get('date', Date.today())
            if not from_currency.rate:
                name = from_currency.name
            else:
                name = to_currency.name

            languages = Lang.search([
                    ('code', '=', Transaction().language),
                    ])
            cls.raise_user_error('no_rate', {
                    'currency': name,
                    'date': datetime_strftime(date, str(languages[0].date))
                    })
        if round:
            return to_currency.round(
                amount * to_currency.rate / from_currency.rate)
        else:
            return amount * to_currency.rate / from_currency.rate
Exemple #8
0
    def validate_surgery_period(self):
        Lang = Pool().get('ir.lang')

        languages = Lang.search([
            ('code', '=', Transaction().language),
        ])
        if (self.surgery_end_date and self.surgery_date):
            if (self.surgery_end_date < self.surgery_date):
                self.raise_user_error(
                    'end_date_before_start', {
                        'surgery_date':
                        datetime_strftime(self.surgery_date,
                                          str(languages[0].date)),
                        'end_date':
                        datetime_strftime(self.surgery_end_date,
                                          str(languages[0].date)),
                    })
Exemple #9
0
 def create_period(self, ids, interval=1):
     '''
     Create periods for the fiscal years with month interval
     '''
     period_obj = self.pool.get('ekd.period')
     for fiscalyear in self.browse(ids):
         period_start_date = fiscalyear.start_date
         while period_start_date < fiscalyear.end_date:
             period_end_date = period_start_date + \
                         relativedelta(months=interval - 1) + \
                         relativedelta(day=31)
             if period_end_date > fiscalyear.end_date:
                 period_end_date = fiscalyear.end_date
             name = datetime_strftime(period_start_date, '%m-%Y')
             if name != datetime_strftime(period_end_date, '%m-%Y'):
                 name += ' - ' + datetime_strftime(period_end_date, '%Y-%m')
             period_obj.create({
                 'company':
                 fiscalyear.company,
                 'name':
                 name,
                 'code':
                 name,
                 'start_date':
                 period_start_date,
                 'end_date':
                 period_end_date,
                 'fiscalyear':
                 fiscalyear.id,
                 'post_move_sequence':
                 fiscalyear.post_move_sequence.id,
                 'post_move_line_sequence':
                 fiscalyear.post_move_line_sequence.id,
                 'cash_book_sequence':
                 fiscalyear.cash_book_sequence.id,
                 'type':
                 'standard',
                 'state':
                 'open',
             })
             period_start_date = period_end_date + relativedelta(days=1)
     return True
Exemple #10
0
 def test_datetime_strftime(self):
     'Test datetime_strftime'
     self.assert_(datetime_strftime(datetime.date(2005, 3, 2),
         '%Y-%m-%d'), '2005-03-02')
     self.assert_(datetime_strftime(datetime.date(1805, 3, 2),
         '%Y-%m-%d'), '1805-03-02')
     self.assert_(datetime_strftime(datetime.datetime(2005, 3, 2, 0, 0, 0),
         '%Y-%m-%d'), '2005-03-02')
     with self.assertRaises(TypeError):
         datetime_strftime(None, '%Y-%m-%d')
     with self.assertRaises(TypeError):
         datetime_strftime(2, '%Y-%m-%d')
Exemple #11
0
    def compute(self, from_currency, amount, to_currency, round=True):
        '''
        Take a currency and an amount
        Return the amount to the new currency
        Use the rate of the date of the context or the current date
        '''
        date_obj = self.pool.get('ir.date')
        lang_obj = self.pool.get('ir.lang')
        if amount == Decimal('0.0'):
            return amount
        if isinstance(from_currency, (int, long)):
            from_currency = self.browse(from_currency)
        if isinstance(to_currency, (int, long)):
            to_currency = self.browse(to_currency)
        if to_currency == from_currency:
            if round:
                return self.round(to_currency, amount)
            else:
                return amount
        if (not from_currency.rate) or (not to_currency.rate):
            date = Transaction().context.get('date', date_obj.today())
            if not from_currency.rate:
                name = from_currency.name
            else:
                name = to_currency.name

            for code in [Transaction().language, 'en_US']:
                lang_ids = lang_obj.search([
                    ('code', '=', code),
                ])
                if lang_ids:
                    break
            lang = lang_obj.browse(lang_ids[0])

            self.raise_user_error(
                'no_rate', (name, datetime_strftime(date, str(lang.date))))
        if round:
            return self.round(
                to_currency,
                amount / from_currency.unit_from * to_currency.rate)
        else:
            return amount / from_currency.unit_from * to_currency.rate
    def compute(self, from_currency, amount, to_currency, round=True):
        '''
        Take a currency and an amount
        Return the amount to the new currency
        Use the rate of the date of the context or the current date
        '''
        date_obj = self.pool.get('ir.date')
        lang_obj = self.pool.get('ir.lang')
        if amount == Decimal('0.0'):
            return amount
        if isinstance(from_currency, (int, long)):
            from_currency = self.browse(from_currency)
        if isinstance(to_currency, (int, long)):
            to_currency = self.browse(to_currency)
        if to_currency == from_currency:
            if round:
                return self.round(to_currency, amount)
            else:
                return amount
        if (not from_currency.rate) or (not to_currency.rate):
            date = Transaction().context.get('date', date_obj.today())
            if not from_currency.rate:
                name = from_currency.name
            else:
                name = to_currency.name

            for code in [Transaction().language, 'en_US']:
                lang_ids = lang_obj.search([
                    ('code', '=', code),
                    ])
                if lang_ids:
                    break
            lang = lang_obj.browse(lang_ids[0])

            self.raise_user_error('no_rate', (name,
                datetime_strftime(date, str(lang.date))))
        if round:
            return self.round(to_currency,
                    amount / from_currency.unit_from * to_currency.rate)
        else:
            return amount / from_currency.unit_from * to_currency.rate
Exemple #13
0
 def test_datetime_strftime(self):
     'Test datetime_strftime'
     self.assert_(datetime_strftime(datetime.date(2005, 3, 2), '%Y-%m-%d'),
                  '2005-03-02')
     self.assert_(datetime_strftime(datetime.date(1805, 3, 2), '%Y-%m-%d'),
                  '1805-03-02')