示例#1
0
 def create_payment(self, invoices):
     payment_register = Form(self.env['account.payment'].with_context(
         active_model='account.move', active_ids=invoices.ids))
     payment_register.payment_date = time.strftime('%Y') + '-07-15'
     payment_register.journal_id = self.bank_journal
     payment_register.payment_method_id = self.payment_method_check
     payment = payment_register.save()
     payment.post()
     return payment
示例#2
0
    def test_partial_payment(self):
        """ Create test to pay invoices (cust. inv + vendor bill) with partial payment """
        # Test Customer Invoice
        inv_1 = self.create_invoice(amount=600)
        payment_register = Form(self.env['account.payment'].with_context(
            active_model='account.move', active_ids=inv_1.ids))
        payment_register.payment_date = time.strftime('%Y') + '-07-15'
        payment_register.journal_id = self.bank_journal_euro
        payment_register.payment_method_id = self.payment_method_manual_in

        # Perform the partial payment by setting the amount at 550 instead of 600
        payment_register.amount = 550

        payment = payment_register.save()

        self.assertEqual(len(payment), 1)
        self.assertEqual(payment.invoice_ids[0].id, inv_1.id)
        self.assertAlmostEquals(payment.amount, 550)
        self.assertEqual(payment.payment_type, 'inbound')
        self.assertEqual(payment.partner_id, self.partner_agrolait)
        self.assertEqual(payment.partner_type, 'customer')

        # Test Vendor Bill
        inv_2 = self.create_invoice(amount=500,
                                    type='in_invoice',
                                    partner=self.partner_china_exp.id)
        payment_register = Form(self.env['account.payment'].with_context(
            active_model='account.move', active_ids=inv_2.ids))
        payment_register.payment_date = time.strftime('%Y') + '-07-15'
        payment_register.journal_id = self.bank_journal_euro
        payment_register.payment_method_id = self.payment_method_manual_in

        # Perform the partial payment by setting the amount at 300 instead of 500
        payment_register.amount = 300

        payment = payment_register.save()

        self.assertEqual(len(payment), 1)
        self.assertEqual(payment.invoice_ids[0].id, inv_2.id)
        self.assertAlmostEquals(payment.amount, 300)
        self.assertEqual(payment.payment_type, 'outbound')
        self.assertEqual(payment.partner_id, self.partner_china_exp)
        self.assertEqual(payment.partner_type, 'supplier')
示例#3
0
 def _init_payment(cls, payment_type, partner_type=None):
     payment_form = Form(cls.env['account.payment'])
     payment_form.journal_id = cls.bank_journal
     payment_form.payment_date = fields.Date.from_string('2019-01-01')
     payment_form.amount = 100
     if payment_type == 'transfer':
         payment_form.destination_journal_id = cls.cash_journal
     else:
         payment_form.partner_type = partner_type
         payment_form.partner_id = cls.partner_a
     payment_form.payment_type = payment_type
     return payment_form.save()
    def test_out_refund_line_onchange_currency_1(self):
        # New journal having a foreign currency set.
        journal = self.company_data['default_journal_sale'].copy()
        journal.currency_id = self.currency_data['currency']

        move_form = Form(self.invoice)
        move_form.journal_id = journal
        move_form.save()

        self.assertInvoiceValues(
            self.invoice, [
                {
                    **self.product_line_vals_1,
                    'currency_id':
                    journal.currency_id.id,
                    'amount_currency':
                    1000.0,
                    'debit':
                    500.0,
                },
                {
                    **self.product_line_vals_2,
                    'currency_id':
                    journal.currency_id.id,
                    'amount_currency':
                    200.0,
                    'debit':
                    100.0,
                },
                {
                    **self.tax_line_vals_1,
                    'currency_id': journal.currency_id.id,
                    'amount_currency': 180.0,
                    'debit': 90.0,
                },
                {
                    **self.tax_line_vals_2,
                    'currency_id': journal.currency_id.id,
                    'amount_currency': 30.0,
                    'debit': 15.0,
                },
                {
                    **self.term_line_vals_1,
                    'currency_id': journal.currency_id.id,
                    'amount_currency': -1410.0,
                    'credit': 705.0,
                },
            ], {
                **self.move_vals,
                'currency_id': journal.currency_id.id,
                'journal_id': journal.id,
            })

        move_form = Form(self.invoice)
        # Change the date to get another rate: 1/3 instead of 1/2.
        move_form.date = fields.Date.from_string('2016-01-01')
        move_form.save()

        self.assertInvoiceValues(
            self.invoice, [
                {
                    **self.product_line_vals_1,
                    'currency_id':
                    journal.currency_id.id,
                    'amount_currency':
                    1000.0,
                    'debit':
                    333.33,
                },
                {
                    **self.product_line_vals_2,
                    'currency_id':
                    journal.currency_id.id,
                    'amount_currency':
                    200.0,
                    'debit':
                    66.67,
                },
                {
                    **self.tax_line_vals_1,
                    'currency_id': journal.currency_id.id,
                    'amount_currency': 180.0,
                    'debit': 60.0,
                },
                {
                    **self.tax_line_vals_2,
                    'currency_id': journal.currency_id.id,
                    'amount_currency': 30.0,
                    'debit': 10.0,
                },
                {
                    **self.term_line_vals_1,
                    'currency_id': journal.currency_id.id,
                    'amount_currency': -1410.0,
                    'credit': 470.0,
                },
            ], {
                **self.move_vals,
                'currency_id': journal.currency_id.id,
                'journal_id': journal.id,
                'date': fields.Date.from_string('2016-01-01'),
            })

        move_form = Form(self.invoice)
        with move_form.invoice_line_ids.edit(0) as line_form:
            # 0.045 * 0.1 = 0.0045. As the foreign currency has a 0.001 rounding,
            # the result should be 0.005 after rounding.
            line_form.quantity = 0.1
            line_form.price_unit = 0.045
        move_form.save()

        self.assertInvoiceValues(
            self.invoice, [
                {
                    **self.product_line_vals_1,
                    'quantity': 0.1,
                    'price_unit': 0.05,
                    'price_subtotal': 0.005,
                    'price_total': 0.006,
                    'currency_id': journal.currency_id.id,
                    'amount_currency': 0.005,
                    'debit': 0.0,
                },
                {
                    **self.product_line_vals_2,
                    'currency_id':
                    journal.currency_id.id,
                    'amount_currency':
                    200.0,
                    'debit':
                    66.67,
                },
                {
                    **self.tax_line_vals_1,
                    'price_unit': 30.0,
                    'price_subtotal': 30.001,
                    'price_total': 30.001,
                    'currency_id': journal.currency_id.id,
                    'amount_currency': 30.001,
                    'debit': 10.0,
                },
                {
                    **self.tax_line_vals_2,
                    'currency_id': journal.currency_id.id,
                    'amount_currency': 30.0,
                    'debit': 10.0,
                },
                {
                    **self.term_line_vals_1,
                    'currency_id': journal.currency_id.id,
                    'price_unit': -260.01,
                    'price_subtotal': -260.006,
                    'price_total': -260.006,
                    'amount_currency': -260.006,
                    'credit': 86.67,
                },
            ], {
                **self.move_vals,
                'currency_id': journal.currency_id.id,
                'journal_id': journal.id,
                'date': fields.Date.from_string('2016-01-01'),
                'amount_untaxed': 200.005,
                'amount_tax': 60.001,
                'amount_total': 260.006,
            })

        # The journal forces you to provide a secondary currency.
        with self.assertRaises(UserError), self.cr.savepoint():
            move_form = Form(self.invoice)
            move_form.currency_id = self.company_data['currency']
            move_form.save()

        # Exit the multi-currencies.
        journal.currency_id = False
        move_form = Form(self.invoice)
        move_form.currency_id = self.company_data['currency']
        move_form.save()

        self.assertInvoiceValues(
            self.invoice, [
                {
                    **self.product_line_vals_1,
                    'quantity': 0.1,
                    'price_unit': 0.1,
                    'price_subtotal': 0.01,
                    'price_total': 0.01,
                    'debit': 0.01,
                },
                self.product_line_vals_2,
                {
                    **self.tax_line_vals_1,
                    'price_unit': 30.0,
                    'price_subtotal': 30.0,
                    'price_total': 30.0,
                    'debit': 30.0,
                },
                self.tax_line_vals_2,
                {
                    **self.term_line_vals_1,
                    'price_unit': -260.01,
                    'price_subtotal': -260.01,
                    'price_total': -260.01,
                    'credit': 260.01,
                },
            ], {
                **self.move_vals,
                'currency_id': self.company_data['currency'].id,
                'journal_id': journal.id,
                'date': fields.Date.from_string('2016-01-01'),
                'amount_untaxed': 200.01,
                'amount_tax': 60.0,
                'amount_total': 260.01,
            })