Exemplo n.º 1
0
 def _check_build_page_info(self, i, p):
     multi_stub = self.company_id.account_check_printing_multi_stub
     return {
         'sequence_number':
         self.check_number if (self.journal_id.check_manual_sequencing
                               and self.check_number != 0) else False,
         'payment_date':
         format_date(self.env, self.payment_date),
         'partner_id':
         self.partner_id,
         'partner_name':
         self.partner_id.name,
         'currency':
         self.currency_id,
         'state':
         self.state,
         'amount':
         formatLang(self.env, self.amount, currency_obj=self.currency_id)
         if i == 0 else 'VOID',
         'amount_in_word':
         self._check_fill_line(self.check_amount_in_words)
         if i == 0 else 'VOID',
         'memo':
         self.communication,
         'stub_cropped':
         not multi_stub and len(self.invoice_ids) > INV_LINES_PER_STUB,
         # If the payment does not reference an invoice, there is no stub line to display
         'stub_lines':
         p,
     }
Exemplo n.º 2
0
    def test_01_code_and_format(self):
        date_str = '2017-01-31'
        lang = self.env['res.lang']

        # Activate French and Simplified Chinese (test with non-ASCII characters)
        lang.search([('active', '=', False), ('code', 'in', ['fr_FR', 'zh_CN'])]).write({'active': True})

        # -- test `date`
        # Change a single parameter
        self.assertEqual(misc.format_date(lang.with_context(lang='fr_FR').env, date_str), '31/01/2017')
        self.assertEqual(misc.format_date(lang.env, date_str, lang_code='fr_FR'), '31/01/2017')
        self.assertEqual(misc.format_date(lang.env, date_str, date_format='MMM d, y'), 'Jan 31, 2017')

        # Change 2 parameters
        self.assertEqual(misc.format_date(lang.with_context(lang='zh_CN').env, date_str, lang_code='fr_FR'), '31/01/2017')
        self.assertEqual(misc.format_date(lang.with_context(lang='zh_CN').env, date_str, date_format='MMM d, y'), u'1\u6708 31, 2017')
        self.assertEqual(misc.format_date(lang.env, date_str, lang_code='fr_FR', date_format='MMM d, y'), 'janv. 31, 2017')

        # Change 3 parameters
        self.assertEqual(misc.format_date(lang.with_context(lang='zh_CN').env, date_str, lang_code='en_US', date_format='MMM d, y'), 'Jan 31, 2017')

        # -- test `datetime`
        datetime_str = '2017-01-31 10:33:00'

        # Change languages and timezones
        self.assertEqual(misc.format_datetime(lang.with_context(lang='fr_FR').env, datetime_str, tz='Europe/Brussels'), '31 janv. 2017 à 11:33:00')
        self.assertEqual(misc.format_datetime(lang.with_context(lang='zh_CN').env, datetime_str, tz='America/New_York'), '2017\u5E741\u670831\u65E5 \u4E0A\u53485:33:00')  # '2017年1月31日 上午5:33:00'

        # Change language, timezone and format
        self.assertEqual(misc.format_datetime(lang.with_context(lang='fr_FR').env, datetime_str, tz='America/New_York', dt_format='short'), '31/01/2017 05:33')
        self.assertEqual(misc.format_datetime(lang.with_context(lang='en_US').env, datetime_str, tz='Europe/Brussels', dt_format='MMM d, y'), 'Jan 31, 2017')

        # Check given `lang_code` overwites context lang
        self.assertEqual(misc.format_datetime(lang.env, datetime_str, tz='Europe/Brussels', dt_format='long', lang_code='fr_FR'), '31 janvier 2017 à 11:33:00 +0100')
        self.assertEqual(misc.format_datetime(lang.with_context(lang='zh_CN').env, datetime_str, tz='Europe/Brussels', dt_format='long', lang_code='en_US'), 'January 31, 2017 at 11:33:00 AM +0100')

        # -- test `time`
        time_part = datetime.time(16, 30, 22)
        time_part_tz = datetime.time(16, 30, 22, tzinfo=pytz.timezone('US/Eastern'))  # 4:30 PM timezoned

        self.assertEqual(misc.format_time(lang.with_context(lang='fr_FR').env, time_part), '16:30:22')
        self.assertEqual(misc.format_time(lang.with_context(lang='zh_CN').env, time_part), '\u4e0b\u53484:30:22')

        # Check format in different languages
        self.assertEqual(misc.format_time(lang.with_context(lang='fr_FR').env, time_part, time_format='short'), '16:30')
        self.assertEqual(misc.format_time(lang.with_context(lang='zh_CN').env, time_part, time_format='short'), '\u4e0b\u53484:30')

        # Check timezoned time part
        self.assertEqual(misc.format_time(lang.with_context(lang='fr_FR').env, time_part_tz, time_format='long'), '16:30:22 -0504')
        self.assertEqual(misc.format_time(lang.with_context(lang='zh_CN').env, time_part_tz, time_format='full'), '\u5317\u7f8e\u4e1c\u90e8\u6807\u51c6\u65f6\u95f4\u0020\u4e0b\u53484:30:22')

        # Check given `lang_code` overwites context lang
        self.assertEqual(misc.format_time(lang.with_context(lang='fr_FR').env, time_part, time_format='short', lang_code='zh_CN'), '\u4e0b\u53484:30')
        self.assertEqual(misc.format_time(lang.with_context(lang='zh_CN').env, time_part, time_format='medium', lang_code='fr_FR'), '16:30:22')
Exemplo n.º 3
0
    def _check_pos_hash_integrity(self):
        """Checks that all posted or invoiced pos orders have still the same data as when they were posted
        and raises an error with the result.
        """
        def build_order_info(order):
            entry_reference = _('(Receipt ref.: %s)')
            order_reference_string = order.pos_reference and entry_reference % order.pos_reference or ''
            return [ctx_tz(order, 'date_order'), order.l10n_fr_hash, order.name, order_reference_string, ctx_tz(order, 'write_date')]

        hash_verified = True
        msg_alert = ''
        report_dict = {}
        if self._is_accounting_unalterable():
            orders = self.env['pos.order'].search([('state', 'in', ['paid', 'done', 'invoiced']), ('company_id', '=', self.id),
                                    ('l10n_fr_secure_sequence_number', '!=', 0)], order="l10n_fr_secure_sequence_number ASC")

            if not orders:
                msg_alert = (_('There isn\'t any order flagged for data inalterability yet for the company %s. This mechanism only runs for point of sale orders generated after the installation of the module France - Certification CGI 286 I-3 bis. - POS') % self.env.company.name)
                hash_verified = False

            previous_hash = u''
            start_order_info = []
            for order in orders:
                if order.l10n_fr_hash != order._compute_hash(previous_hash=previous_hash):
                    msg_alert = (_('Corrupted data on point of sale order with id %s.') % order.id)
                    hash_verified = False
                    break
                previous_hash = order.l10n_fr_hash

            if hash_verified:
                orders_sorted_date = orders.sorted(lambda o: o.date_order)
                start_order_info = build_order_info(orders_sorted_date[0])
                end_order_info = build_order_info(orders_sorted_date[-1])

                report_dict.update({
                    'first_order_name': start_order_info[2],
                    'first_order_hash': start_order_info[1],
                    'first_order_date': start_order_info[0],
                    'last_order_name': end_order_info[2],
                    'last_order_hash': end_order_info[1],
                    'last_order_date': end_order_info[0],
                })
            return {
                'result': hash_verified and report_dict or 'None',
                'msg_alert': msg_alert or 'None',
                'printing_date': format_date(self.env,  Date.to_string( Date.today())),
            }
Exemplo n.º 4
0
    def test_00_accepted_types(self):
        date_datetime = datetime.datetime.strptime('2017-01-31 12:00:00',
                                                   "%Y-%m-%d %H:%M:%S")
        date_date = date_datetime.date()
        date_str = '2017-01-31'

        self.assertEqual(misc.format_date(self.env, date_datetime),
                         '01/31/2017')
        self.assertEqual(misc.format_date(self.env, date_date), '01/31/2017')
        self.assertEqual(misc.format_date(self.env, date_str), '01/31/2017')
        self.assertEqual(misc.format_date(self.env, ''), '')
        self.assertEqual(misc.format_date(self.env, False), '')
        self.assertEqual(misc.format_date(self.env, None), '')
Exemplo n.º 5
0
    def _check_make_stub_line(self, invoice):
        """ Return the dict used to display an invoice/refund in the stub
        """
        # Find the account.partial.reconcile which are common to the invoice and the payment
        if invoice.type in ['in_invoice', 'out_refund']:
            invoice_sign = 1
            invoice_payment_reconcile = invoice.move_id.line_ids.mapped(
                'matched_debit_ids').filtered(
                    lambda r: r.debit_move_id in self.move_line_ids)
        else:
            invoice_sign = -1
            invoice_payment_reconcile = invoice.move_id.line_ids.mapped(
                'matched_credit_ids').filtered(
                    lambda r: r.credit_move_id in self.move_line_ids)

        if self.currency_id != self.journal_id.company_id.currency_id:
            amount_paid = abs(
                sum(invoice_payment_reconcile.mapped('amount_currency')))
        else:
            amount_paid = abs(sum(invoice_payment_reconcile.mapped('amount')))

        amount_residual = invoice_sign * invoice.residual

        return {
            'due_date':
            format_date(self.env, invoice.date_due),
            'number':
            invoice.reference and invoice.number + ' - ' + invoice.reference
            or invoice.number,
            'amount_total':
            formatLang(self.env,
                       invoice_sign * invoice.amount_total,
                       currency_obj=invoice.currency_id),
            'amount_residual':
            formatLang(
                self.env, amount_residual, currency_obj=invoice.currency_id)
            if amount_residual * 10**4 != 0 else '-',
            'amount_paid':
            formatLang(self.env,
                       invoice_sign * amount_paid,
                       currency_obj=invoice.currency_id),
            'currency':
            invoice.currency_id,
        }
Exemplo n.º 6
0
    def test_01_code_and_format(self):
        date_str = '2017-01-31'
        lang = self.env['res.lang']

        # Activate French and Simplified Chinese (test with non-ASCII characters)
        lang.search([('active', '=', False),
                     ('code', 'in', ['fr_FR',
                                     'zh_CN'])]).write({'active': True})

        # Change a single parameter
        self.assertEqual(
            misc.format_date(lang.with_context(lang='fr_FR').env, date_str),
            '31/01/2017')
        self.assertEqual(
            misc.format_date(lang.env, date_str, lang_code='fr_FR'),
            '31/01/2017')
        self.assertEqual(
            misc.format_date(lang.env, date_str, date_format='MMM d, y'),
            'Jan 31, 2017')

        # Change 2 parameters
        self.assertEqual(
            misc.format_date(lang.with_context(lang='zh_CN').env,
                             date_str,
                             lang_code='fr_FR'), '31/01/2017')
        self.assertEqual(
            misc.format_date(lang.with_context(lang='zh_CN').env,
                             date_str,
                             date_format='MMM d, y'), u'1\u6708 31, 2017')
        self.assertEqual(
            misc.format_date(lang.env,
                             date_str,
                             lang_code='fr_FR',
                             date_format='MMM d, y'), 'janv. 31, 2017')

        # Change 3 parameters
        self.assertEqual(
            misc.format_date(lang.with_context(lang='zh_CN').env,
                             date_str,
                             lang_code='en_US',
                             date_format='MMM d, y'), 'Jan 31, 2017')
Exemplo n.º 7
0
    def test_00_accepted_types(self):
        datetime_str = '2017-01-31 12:00:00'
        date_datetime = datetime.datetime.strptime(datetime_str, "%Y-%m-%d %H:%M:%S")
        date_date = date_datetime.date()
        date_str = '2017-01-31'
        time_part = datetime.time(16, 30, 22)

        self.assertEqual(misc.format_date(self.env, date_datetime), '01/31/2017')
        self.assertEqual(misc.format_date(self.env, date_date), '01/31/2017')
        self.assertEqual(misc.format_date(self.env, date_str), '01/31/2017')
        self.assertEqual(misc.format_date(self.env, ''), '')
        self.assertEqual(misc.format_date(self.env, False), '')
        self.assertEqual(misc.format_date(self.env, None), '')

        self.assertEqual(misc.format_datetime(self.env, date_datetime), 'Jan 31, 2017, 1:00:00 PM')
        self.assertEqual(misc.format_datetime(self.env, datetime_str), 'Jan 31, 2017, 1:00:00 PM')
        self.assertEqual(misc.format_datetime(self.env, ''), '')
        self.assertEqual(misc.format_datetime(self.env, False), '')
        self.assertEqual(misc.format_datetime(self.env, None), '')

        self.assertEqual(misc.format_time(self.env, time_part), '4:30:22 PM')
        self.assertEqual(misc.format_time(self.env, ''), '')
        self.assertEqual(misc.format_time(self.env, False), '')
        self.assertEqual(misc.format_time(self.env, None), '')
Exemplo n.º 8
0
 def _compute_date_deadline_formatted(self):
     for task in self:
         task.date_deadline_formatted = format_date(self.env, task.date_deadline) if task.date_deadline else None
    def _get_statement_line(self, st_line):
        """ Returns the data required by the bank statement reconciliation widget to display a statement line """

        statement_currency = st_line.journal_id.currency_id or st_line.journal_id.company_id.currency_id
        if st_line.amount_currency and st_line.currency_id:
            amount = st_line.amount_currency
            amount_currency = st_line.amount
            amount_currency_str = formatLang(self.env,
                                             abs(amount_currency),
                                             currency_obj=statement_currency)
        else:
            amount = st_line.amount
            amount_currency = amount
            amount_currency_str = ""
        amount_str = formatLang(self.env,
                                abs(amount),
                                currency_obj=st_line.currency_id
                                or statement_currency)

        data = {
            'id':
            st_line.id,
            'ref':
            st_line.ref,
            'note':
            st_line.note or "",
            'name':
            st_line.name,
            'date':
            format_date(self.env, st_line.date),
            'amount':
            amount,
            'amount_str':
            amount_str,  # Amount in the statement line currency
            'currency_id':
            st_line.currency_id.id or statement_currency.id,
            'partner_id':
            st_line.partner_id.id,
            'journal_id':
            st_line.journal_id.id,
            'statement_id':
            st_line.statement_id.id,
            'account_id': [
                st_line.journal_id.default_debit_account_id.id,
                st_line.journal_id.default_debit_account_id.display_name
            ],
            'account_code':
            st_line.journal_id.default_debit_account_id.code,
            'account_name':
            st_line.journal_id.default_debit_account_id.name,
            'partner_name':
            st_line.partner_id.name,
            'communication_partner_name':
            st_line.partner_name,
            'amount_currency_str':
            amount_currency_str,  # Amount in the statement currency
            'amount_currency':
            amount_currency,  # Amount in the statement currency
            'has_no_partner':
            not st_line.partner_id.id,
            'company_id':
            st_line.company_id.id,
        }
        if st_line.partner_id:
            data[
                'open_balance_account_id'] = amount > 0 and st_line.partner_id.property_account_receivable_id.id or st_line.partner_id.property_account_payable_id.id

        return data
Exemplo n.º 10
0
    def _prepare_move_lines(self,
                            move_lines,
                            target_currency=False,
                            target_date=False,
                            recs_count=0):
        """ Returns move lines formatted for the manual/bank reconciliation widget

            :param move_line_ids:
            :param target_currency: currency (browse) you want the move line debit/credit converted into
            :param target_date: date to use for the monetary conversion
        """
        context = dict(self._context or {})
        ret = []

        for line in move_lines:
            company_currency = line.company_id.currency_id
            line_currency = (line.currency_id and line.amount_currency
                             ) and line.currency_id or company_currency
            ret_line = {
                'id':
                line.id,
                'name':
                line.name and line.name != '/'
                and line.move_id.name != line.name
                and line.move_id.name + ': ' + line.name or line.move_id.name,
                'ref':
                line.move_id.ref or '',
                # For reconciliation between statement transactions and already registered payments (eg. checks)
                # NB : we don't use the 'reconciled' field because the line we're selecting is not the one that gets reconciled
                'account_id':
                [line.account_id.id, line.account_id.display_name],
                'already_paid':
                line.account_id.internal_type == 'liquidity',
                'account_code':
                line.account_id.code,
                'account_name':
                line.account_id.name,
                'account_type':
                line.account_id.internal_type,
                'date_maturity':
                format_date(self.env, line.date_maturity),
                'date':
                format_date(self.env, line.date),
                'journal_id':
                [line.journal_id.id, line.journal_id.display_name],
                'partner_id':
                line.partner_id.id,
                'partner_name':
                line.partner_id.name,
                'currency_id':
                line_currency.id,
            }

            debit = line.debit
            credit = line.credit
            amount = line.amount_residual
            amount_currency = line.amount_residual_currency

            # For already reconciled lines, don't use amount_residual(_currency)
            if line.account_id.internal_type == 'liquidity':
                amount = debit - credit
                amount_currency = line.amount_currency

            target_currency = target_currency or company_currency

            # Use case:
            # Let's assume that company currency is in USD and that we have the 3 following move lines
            #      Debit  Credit  Amount currency  Currency
            # 1)    25      0            0            NULL
            # 2)    17      0           25             EUR
            # 3)    33      0           25             YEN
            #
            # If we ask to see the information in the reconciliation widget in company currency, we want to see
            # The following information
            # 1) 25 USD (no currency information)
            # 2) 17 USD [25 EUR] (show 25 euro in currency information, in the little bill)
            # 3) 33 USD [25 YEN] (show 25 yen in currency information)
            #
            # If we ask to see the information in another currency than the company let's say EUR
            # 1) 35 EUR [25 USD]
            # 2) 25 EUR (no currency information)
            # 3) 50 EUR [25 YEN]
            # In that case, we have to convert the debit-credit to the currency we want and we show next to it
            # the value of the amount_currency or the debit-credit if no amount currency
            if target_currency == company_currency:
                if line_currency == target_currency:
                    amount = amount
                    amount_currency = ""
                    total_amount = debit - credit
                    total_amount_currency = ""
                else:
                    amount = amount
                    amount_currency = amount_currency
                    total_amount = debit - credit
                    total_amount_currency = line.amount_currency

            if target_currency != company_currency:
                if line_currency == target_currency:
                    amount = amount_currency
                    amount_currency = ""
                    total_amount = line.amount_currency
                    total_amount_currency = ""
                else:
                    amount_currency = line.currency_id and amount_currency or amount
                    company = line.account_id.company_id
                    date = target_date or line.date
                    amount = company_currency._convert(amount, target_currency,
                                                       company, date)
                    total_amount = company_currency._convert(
                        (line.debit - line.credit), target_currency, company,
                        date)
                    total_amount_currency = line.currency_id and line.amount_currency or (
                        line.debit - line.credit)

            ret_line['recs_count'] = recs_count
            ret_line['debit'] = amount > 0 and amount or 0
            ret_line['credit'] = amount < 0 and -amount or 0
            ret_line['amount_currency'] = amount_currency
            ret_line['amount_str'] = formatLang(self.env,
                                                abs(amount),
                                                currency_obj=target_currency)
            ret_line['total_amount_str'] = formatLang(
                self.env, abs(total_amount), currency_obj=target_currency)
            ret_line['amount_currency_str'] = amount_currency and formatLang(
                self.env, abs(amount_currency),
                currency_obj=line_currency) or ""
            ret_line[
                'total_amount_currency_str'] = total_amount_currency and formatLang(
                    self.env,
                    abs(total_amount_currency),
                    currency_obj=line_currency) or ""
            ret.append(ret_line)
        return ret
Exemplo n.º 11
0
    def _check_hash_integrity(self):
        """Checks that all posted moves have still the same data as when they were posted
        and raises an error with the result.
        """
        def build_move_info(move):
            return (move.name, move.inalterable_hash,
                    fields.Date.to_string(move.date))

        journals = self.env['account.journal'].search([('company_id', '=',
                                                        self.id)])
        results_by_journal = {
            'results': [],
            'printing_date':
            format_date(self.env, fields.Date.to_string(fields.Date.today()))
        }

        for journal in journals:
            rslt = {
                'journal_name':
                journal.name,
                'journal_code':
                journal.code,
                'restricted_by_hash_table':
                journal.restrict_mode_hash_table and 'V' or 'X',
                'msg_cover':
                '',
                'first_hash':
                'None',
                'first_move_name':
                'None',
                'first_move_date':
                'None',
                'last_hash':
                'None',
                'last_move_name':
                'None',
                'last_move_date':
                'None',
            }
            if not journal.restrict_mode_hash_table:
                rslt.update(
                    {'msg_cover': _('This journal is not in strict mode.')})
                results_by_journal['results'].append(rslt)
                continue

            all_moves_count = self.env['account.move'].search_count([
                ('state', '=', 'posted'), ('journal_id', '=', journal.id)
            ])
            moves = self.env['account.move'].search(
                [('state', '=', 'posted'), ('journal_id', '=', journal.id),
                 ('secure_sequence_number', '!=', 0)],
                order="secure_sequence_number ASC")
            if not moves:
                rslt.update({
                    'msg_cover':
                    _('There isn\'t any journal entry flagged for data inalterability yet for this journal.'
                      ),
                })
                results_by_journal['results'].append(rslt)
                continue

            previous_hash = u''
            start_move_info = []
            hash_corrupted = False
            for move in moves:
                if move.inalterable_hash != move._compute_hash(
                        previous_hash=previous_hash):
                    rslt.update({
                        'msg_cover':
                        _('Corrupted data on journal entry with id %s.') %
                        move.id
                    })
                    results_by_journal['results'].append(rslt)
                    hash_corrupted = True
                    break
                if not previous_hash:
                    #save the date and sequence number of the first move hashed
                    start_move_info = build_move_info(move)
                previous_hash = move.inalterable_hash
            end_move_info = build_move_info(move)

            if hash_corrupted:
                continue

            rslt.update({
                'first_move_name':
                start_move_info[0],
                'first_hash':
                start_move_info[1],
                'first_move_date':
                format_date(self.env, start_move_info[2]),
                'last_move_name':
                end_move_info[0],
                'last_hash':
                end_move_info[1],
                'last_move_date':
                format_date(self.env, end_move_info[2]),
            })
            if len(moves) == all_moves_count:
                rslt.update({'msg_cover': _('All entries are hashed.')})
            else:
                rslt.update({
                    'msg_cover':
                    _('Entries are hashed from %s (%s)') %
                    (start_move_info[0],
                     format_date(self.env, start_move_info[2]))
                })
            results_by_journal['results'].append(rslt)

        return results_by_journal