def test_fifo_perpetual_01_mc_01(self): self.product_A.categ_id.property_cost_method = "fifo" rate = self.currency_data["rates"].sorted()[0].rate move_form = Form(self.env["account.move"].with_context( default_move_type="out_invoice")) move_form.partner_id = self.partner_a move_form.currency_id = self.currency_data["currency"] with move_form.invoice_line_ids.new() as line_form: line_form.product_id = self.product_A line_form.tax_ids.clear() invoice = move_form.save() self.assertAlmostEqual(self.product_A.lst_price * rate, invoice.amount_total) self.assertAlmostEqual(self.product_A.lst_price * rate, invoice.amount_residual) self.assertEqual(len(invoice.mapped("line_ids")), 2) self.assertEqual(len(invoice.mapped("line_ids.currency_id")), 1) invoice._post() self.assertAlmostEqual(self.product_A.lst_price * rate, invoice.amount_total) self.assertAlmostEqual(self.product_A.lst_price * rate, invoice.amount_residual) self.assertEqual(len(invoice.mapped("line_ids")), 4) self.assertEqual( len(invoice.mapped("line_ids").filtered("is_anglo_saxon_line")), 2) self.assertEqual(len(invoice.mapped("line_ids.currency_id")), 2)
def _create_invoice_for_po(self, purchase_order, date): move_form = Form(self.env['account.move'].with_context( default_move_type='in_invoice', default_date=date)) move_form.invoice_date = date move_form.partner_id = self.partner_a move_form.currency_id = self.currency_data['currency'] move_form.purchase_id = purchase_order return move_form.save()
def test_out_refund_line_onchange_currency_1(self): move_form = Form(self.invoice) move_form.currency_id = self.currency_data['currency'] move_form.save() self.assertInvoiceValues(self.invoice, [ { **self.product_line_vals_1, 'currency_id': self.currency_data['currency'].id, 'amount_currency': 1000.0, 'debit': 500.0, }, { **self.product_line_vals_2, 'currency_id': self.currency_data['currency'].id, 'amount_currency': 200.0, 'debit': 100.0, }, { **self.tax_line_vals_1, 'currency_id': self.currency_data['currency'].id, 'amount_currency': 180.0, 'debit': 90.0, }, { **self.tax_line_vals_2, 'currency_id': self.currency_data['currency'].id, 'amount_currency': 30.0, 'debit': 15.0, }, { **self.term_line_vals_1, 'currency_id': self.currency_data['currency'].id, 'amount_currency': -1410.0, 'credit': 705.0, }, ], { **self.move_vals, 'currency_id': self.currency_data['currency'].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': self.currency_data['currency'].id, 'amount_currency': 1000.0, 'debit': 333.33, }, { **self.product_line_vals_2, 'currency_id': self.currency_data['currency'].id, 'amount_currency': 200.0, 'debit': 66.67, }, { **self.tax_line_vals_1, 'currency_id': self.currency_data['currency'].id, 'amount_currency': 180.0, 'debit': 60.0, }, { **self.tax_line_vals_2, 'currency_id': self.currency_data['currency'].id, 'amount_currency': 30.0, 'debit': 10.0, }, { **self.term_line_vals_1, 'currency_id': self.currency_data['currency'].id, 'amount_currency': -1410.0, 'credit': 470.0, }, ], { **self.move_vals, 'currency_id': self.currency_data['currency'].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': self.currency_data['currency'].id, 'amount_currency': 0.005, 'debit': 0.0, }, { **self.product_line_vals_2, 'currency_id': self.currency_data['currency'].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': self.currency_data['currency'].id, 'amount_currency': 30.001, 'debit': 10.0, }, { **self.tax_line_vals_2, 'currency_id': self.currency_data['currency'].id, 'amount_currency': 30.0, 'debit': 10.0, }, { **self.term_line_vals_1, 'currency_id': self.currency_data['currency'].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': self.currency_data['currency'].id, 'date': fields.Date.from_string('2016-01-01'), 'amount_untaxed': 200.005, 'amount_tax': 60.001, 'amount_total': 260.006, }) # Exit the multi-currencies. 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.05, 'price_subtotal': 0.01, 'price_total': 0.01, 'amount_currency': 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, 'amount_currency': 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, 'amount_currency': -260.01, 'credit': 260.01, }, ], { **self.move_vals, 'currency_id': self.company_data['currency'].id, 'date': fields.Date.from_string('2016-01-01'), 'amount_untaxed': 200.01, 'amount_tax': 60.0, 'amount_total': 260.01, })
def test_payment_move_sync_onchange(self): copy_receivable = self.copy_account( self.company_data['default_account_receivable']) pay_form = Form(self.env['account.payment'].with_context( default_journal_id=self.company_data['default_journal_bank'].id)) pay_form.amount = 50.0 pay_form.payment_type = 'inbound' pay_form.partner_type = 'customer' pay_form.destination_account_id = copy_receivable payment = pay_form.save() expected_payment_values = { 'amount': 50.0, 'payment_type': 'inbound', 'partner_type': 'customer', 'payment_reference': False, 'is_reconciled': False, 'currency_id': self.company_data['currency'].id, 'partner_id': False, 'destination_account_id': copy_receivable.id, 'payment_method_id': self.env.ref('account.account_payment_method_manual_in').id, } expected_move_values = { 'currency_id': self.company_data['currency'].id, 'partner_id': False, } expected_liquidity_line = { 'debit': 50.0, 'credit': 0.0, 'amount_currency': 50.0, 'currency_id': self.company_data['currency'].id, 'account_id': self.payment_debit_account_id.id, } expected_counterpart_line = { 'debit': 0.0, 'credit': 50.0, 'amount_currency': -50.0, 'currency_id': self.company_data['currency'].id, 'account_id': copy_receivable.id, } self.assertRecordValues(payment, [expected_payment_values]) self.assertRecordValues(payment.move_id, [expected_move_values]) self.assertRecordValues(payment.line_ids.sorted('balance'), [ expected_counterpart_line, expected_liquidity_line, ]) # ==== Check editing the account.payment ==== pay_form = Form(payment) pay_form.partner_type = 'supplier' pay_form.currency_id = self.currency_data['currency'] pay_form.partner_id = self.partner_a payment = pay_form.save() self.assertRecordValues(payment, [{ **expected_payment_values, 'partner_type': 'supplier', 'destination_account_id': self.partner_a.property_account_payable_id.id, 'currency_id': self.currency_data['currency'].id, 'partner_id': self.partner_a.id, }]) self.assertRecordValues(payment.move_id, [{ **expected_move_values, 'currency_id': self.currency_data['currency'].id, 'partner_id': self.partner_a.id, }]) self.assertRecordValues(payment.line_ids.sorted('balance'), [ { **expected_counterpart_line, 'debit': 0.0, 'credit': 25.0, 'amount_currency': -50.0, 'currency_id': self.currency_data['currency'].id, 'account_id': self.partner_a.property_account_payable_id.id, }, { **expected_liquidity_line, 'debit': 25.0, 'credit': 0.0, 'amount_currency': 50.0, 'currency_id': self.currency_data['currency'].id, }, ]) # ==== Check editing the account.move.line ==== move_form = Form(payment.move_id) with move_form.line_ids.edit(0) as line_form: line_form.currency_id = self.company_data['currency'] line_form.amount_currency = 100.0 line_form.partner_id = self.partner_b with move_form.line_ids.edit(1) as line_form: line_form.currency_id = self.company_data['currency'] line_form.amount_currency = -75.0 line_form.account_id = copy_receivable line_form.partner_id = self.partner_b with move_form.line_ids.new() as line_form: line_form.currency_id = self.company_data['currency'] line_form.amount_currency = -25.0 line_form.account_id = self.company_data['default_account_revenue'] line_form.partner_id = self.partner_b move_form.save() self.assertRecordValues(payment, [{ **expected_payment_values, 'amount': 100.0, 'partner_id': self.partner_b.id, }]) self.assertRecordValues(payment.line_ids.sorted('balance'), [ { **expected_counterpart_line, 'debit': 0.0, 'credit': 75.0, 'amount_currency': -75.0, 'partner_id': self.partner_b.id, }, { 'debit': 0.0, 'credit': 25.0, 'amount_currency': -25.0, 'currency_id': self.company_data['currency'].id, 'account_id': self.company_data['default_account_revenue'].id, 'partner_id': self.partner_b.id, }, { **expected_liquidity_line, 'debit': 100.0, 'credit': 0.0, 'amount_currency': 100.0, 'account_id': self.payment_debit_account_id.id, 'partner_id': self.partner_b.id, }, ])