12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133 |
- # -*- coding: utf-8 -*-
- # pylint: disable=bad-whitespace
- from lxml import etree
- from odoo.addons.account.tests.common import AccountTestInvoicingCommon
- from odoo.tests.common import Form
- from odoo.tests import tagged
- from odoo import fields, Command
- from collections import defaultdict
- @tagged('post_install', '-at_install')
- class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon):
- @classmethod
- def setUpClass(cls, chart_template_ref=None):
- super().setUpClass(chart_template_ref=chart_template_ref)
- cls.invoice = cls.init_invoice('in_refund', products=cls.product_a+cls.product_b)
- cls.product_line_vals_1 = {
- 'name': cls.product_a.name,
- 'product_id': cls.product_a.id,
- 'account_id': cls.product_a.property_account_expense_id.id,
- 'partner_id': cls.partner_a.id,
- 'product_uom_id': cls.product_a.uom_id.id,
- 'quantity': 1.0,
- 'discount': 0.0,
- 'price_unit': 800.0,
- 'price_subtotal': 800.0,
- 'price_total': 920.0,
- 'tax_ids': cls.product_a.supplier_taxes_id.ids,
- 'tax_line_id': False,
- 'currency_id': cls.company_data['currency'].id,
- 'amount_currency': -800.0,
- 'debit': 0.0,
- 'credit': 800.0,
- 'date_maturity': False,
- }
- cls.product_line_vals_2 = {
- 'name': cls.product_b.name,
- 'product_id': cls.product_b.id,
- 'account_id': cls.product_b.property_account_expense_id.id,
- 'partner_id': cls.partner_a.id,
- 'product_uom_id': cls.product_b.uom_id.id,
- 'quantity': 1.0,
- 'discount': 0.0,
- 'price_unit': 160.0,
- 'price_subtotal': 160.0,
- 'price_total': 208.0,
- 'tax_ids': cls.product_b.supplier_taxes_id.ids,
- 'tax_line_id': False,
- 'currency_id': cls.company_data['currency'].id,
- 'amount_currency': -160.0,
- 'debit': 0.0,
- 'credit': 160.0,
- 'date_maturity': False,
- }
- cls.tax_line_vals_1 = {
- 'name': cls.tax_purchase_a.name,
- 'product_id': False,
- 'account_id': cls.company_data['default_account_tax_purchase'].id,
- 'partner_id': cls.partner_a.id,
- 'product_uom_id': False,
- 'quantity': False,
- 'discount': 0.0,
- 'price_unit': 0.0,
- 'price_subtotal': 0.0,
- 'price_total': 0.0,
- 'tax_ids': [],
- 'tax_line_id': cls.tax_purchase_a.id,
- 'currency_id': cls.company_data['currency'].id,
- 'amount_currency': -144.0,
- 'debit': 0.0,
- 'credit': 144.0,
- 'date_maturity': False,
- }
- cls.tax_line_vals_2 = {
- 'name': cls.tax_purchase_b.name,
- 'product_id': False,
- 'account_id': cls.company_data['default_account_tax_purchase'].id,
- 'partner_id': cls.partner_a.id,
- 'product_uom_id': False,
- 'quantity': False,
- 'discount': 0.0,
- 'price_unit': 0.0,
- 'price_subtotal': 0.0,
- 'price_total': 0.0,
- 'tax_ids': [],
- 'tax_line_id': cls.tax_purchase_b.id,
- 'currency_id': cls.company_data['currency'].id,
- 'amount_currency': -24.0,
- 'debit': 0.0,
- 'credit': 24.0,
- 'date_maturity': False,
- }
- cls.term_line_vals_1 = {
- 'name': '',
- 'product_id': False,
- 'account_id': cls.company_data['default_account_payable'].id,
- 'partner_id': cls.partner_a.id,
- 'product_uom_id': False,
- 'quantity': False,
- 'discount': 0.0,
- 'price_unit': 0.0,
- 'price_subtotal': 0.0,
- 'price_total': 0.0,
- 'tax_ids': [],
- 'tax_line_id': False,
- 'currency_id': cls.company_data['currency'].id,
- 'amount_currency': 1128.0,
- 'debit': 1128.0,
- 'credit': 0.0,
- 'date_maturity': fields.Date.from_string('2019-01-01'),
- }
- cls.move_vals = {
- 'partner_id': cls.partner_a.id,
- 'currency_id': cls.company_data['currency'].id,
- 'journal_id': cls.company_data['default_journal_purchase'].id,
- 'invoice_date': fields.Date.from_string('2019-01-01'),
- 'fiscal_position_id': False,
- 'payment_reference': '',
- 'invoice_payment_term_id': cls.pay_terms_a.id,
- 'amount_untaxed': 960.0,
- 'amount_tax': 168.0,
- 'amount_total': 1128.0,
- }
- def setUp(self):
- super(TestAccountMoveInRefundOnchanges, self).setUp()
- self.assertInvoiceValues(self.invoice, [
- self.product_line_vals_1,
- self.product_line_vals_2,
- self.tax_line_vals_1,
- self.tax_line_vals_2,
- self.term_line_vals_1,
- ], self.move_vals)
- def test_in_refund_line_onchange_product_1(self):
- move_form = Form(self.invoice)
- with move_form.invoice_line_ids.edit(0) as line_form:
- line_form.product_id = self.product_b
- move_form.save()
- self.assertInvoiceValues(self.invoice, [
- {
- **self.product_line_vals_1,
- 'name': self.product_b.name,
- 'product_id': self.product_b.id,
- 'product_uom_id': self.product_b.uom_id.id,
- 'account_id': self.product_b.property_account_expense_id.id,
- 'price_unit': 160.0,
- 'price_subtotal': 160.0,
- 'price_total': 208.0,
- 'tax_ids': self.product_b.supplier_taxes_id.ids,
- 'amount_currency': -160.0,
- 'credit': 160.0,
- },
- self.product_line_vals_2,
- {
- **self.tax_line_vals_1,
- 'amount_currency': -48.0,
- 'credit': 48.0,
- },
- {
- **self.tax_line_vals_2,
- 'amount_currency': -48.0,
- 'credit': 48.0,
- },
- {
- **self.term_line_vals_1,
- 'amount_currency': 416.0,
- 'debit': 416.0,
- },
- ], {
- **self.move_vals,
- 'amount_untaxed': 320.0,
- 'amount_tax': 96.0,
- 'amount_total': 416.0,
- })
- def test_in_refund_line_onchange_business_fields_1(self):
- move_form = Form(self.invoice)
- with move_form.invoice_line_ids.edit(0) as line_form:
- # Current price_unit is 800.
- # We set quantity = 4, discount = 50%, price_unit = 400. The debit/credit fields don't change because (4 * 400) * 0.5 = 800.
- line_form.quantity = 4
- line_form.discount = 50
- line_form.price_unit = 400
- move_form.save()
- self.assertInvoiceValues(self.invoice, [
- {
- **self.product_line_vals_1,
- 'quantity': 4,
- 'discount': 50.0,
- 'price_unit': 400.0,
- },
- self.product_line_vals_2,
- self.tax_line_vals_1,
- self.tax_line_vals_2,
- self.term_line_vals_1,
- ], self.move_vals)
- move_form = Form(self.invoice)
- with move_form.invoice_line_ids.edit(0) as line_form:
- # Reset field except the discount that becomes 100%.
- # /!\ The modification is made on the accounting tab.
- line_form.quantity = 1
- line_form.discount = 100
- line_form.price_unit = 800
- move_form.save()
- self.assertInvoiceValues(self.invoice, [
- {
- **self.product_line_vals_1,
- 'discount': 100.0,
- 'price_subtotal': 0.0,
- 'price_total': 0.0,
- 'amount_currency': 0.0,
- 'credit': 0.0,
- },
- self.product_line_vals_2,
- {
- **self.tax_line_vals_1,
- 'amount_currency': -24.0,
- 'credit': 24.0,
- },
- self.tax_line_vals_2,
- {
- **self.term_line_vals_1,
- 'amount_currency': 208.0,
- 'debit': 208.0,
- },
- ], {
- **self.move_vals,
- 'amount_untaxed': 160.0,
- 'amount_tax': 48.0,
- 'amount_total': 208.0,
- })
- def test_in_refund_line_onchange_partner_1(self):
- move_form = Form(self.invoice)
- move_form.partner_id = self.partner_b
- move_form.payment_reference = 'turlututu'
- move_form.save()
- self.assertInvoiceValues(self.invoice, [
- {
- **self.product_line_vals_1,
- 'partner_id': self.partner_b.id,
- },
- {
- **self.product_line_vals_2,
- 'partner_id': self.partner_b.id,
- },
- {
- **self.tax_line_vals_1,
- 'partner_id': self.partner_b.id,
- },
- {
- **self.tax_line_vals_2,
- 'partner_id': self.partner_b.id,
- },
- {
- **self.term_line_vals_1,
- 'name': 'turlututu',
- 'partner_id': self.partner_b.id,
- 'account_id': self.partner_b.property_account_payable_id.id,
- 'amount_currency': 338.4,
- 'debit': 338.4,
- },
- {
- **self.term_line_vals_1,
- 'name': 'turlututu',
- 'partner_id': self.partner_b.id,
- 'account_id': self.partner_b.property_account_payable_id.id,
- 'amount_currency': 789.6,
- 'debit': 789.6,
- 'date_maturity': fields.Date.from_string('2019-02-28'),
- },
- ], {
- **self.move_vals,
- 'partner_id': self.partner_b.id,
- 'payment_reference': 'turlututu',
- 'fiscal_position_id': self.fiscal_pos_a.id,
- 'invoice_payment_term_id': self.pay_terms_b.id,
- 'amount_untaxed': 960.0,
- 'amount_tax': 168.0,
- 'amount_total': 1128.0,
- })
- # Remove lines and recreate them to apply the fiscal position.
- move_form = Form(self.invoice)
- move_form.invoice_line_ids.remove(0)
- move_form.invoice_line_ids.remove(0)
- with move_form.invoice_line_ids.new() as line_form:
- line_form.product_id = self.product_a
- with move_form.invoice_line_ids.new() as line_form:
- line_form.product_id = self.product_b
- move_form.save()
- self.assertInvoiceValues(self.invoice, [
- {
- **self.product_line_vals_1,
- 'account_id': self.product_b.property_account_expense_id.id,
- 'partner_id': self.partner_b.id,
- 'tax_ids': self.tax_purchase_b.ids,
- },
- {
- **self.product_line_vals_2,
- 'partner_id': self.partner_b.id,
- 'price_total': 184.0,
- 'tax_ids': self.tax_purchase_b.ids,
- },
- {
- **self.tax_line_vals_1,
- 'name': self.tax_purchase_b.name,
- 'partner_id': self.partner_b.id,
- 'tax_line_id': self.tax_purchase_b.id,
- },
- {
- **self.term_line_vals_1,
- 'name': 'turlututu',
- 'account_id': self.partner_b.property_account_payable_id.id,
- 'partner_id': self.partner_b.id,
- 'amount_currency': 331.2,
- 'debit': 331.2,
- },
- {
- **self.term_line_vals_1,
- 'name': 'turlututu',
- 'account_id': self.partner_b.property_account_payable_id.id,
- 'partner_id': self.partner_b.id,
- 'amount_currency': 772.8,
- 'debit': 772.8,
- 'date_maturity': fields.Date.from_string('2019-02-28'),
- },
- ], {
- **self.move_vals,
- 'partner_id': self.partner_b.id,
- 'payment_reference': 'turlututu',
- 'fiscal_position_id': self.fiscal_pos_a.id,
- 'invoice_payment_term_id': self.pay_terms_b.id,
- 'amount_untaxed': 960.0,
- 'amount_tax': 144.0,
- 'amount_total': 1104.0,
- })
- def test_in_refund_line_onchange_taxes_1(self):
- move_form = Form(self.invoice)
- with move_form.invoice_line_ids.edit(0) as line_form:
- line_form.price_unit = 960
- line_form.tax_ids.add(self.tax_armageddon)
- move_form.save()
- child_tax_1 = self.tax_armageddon.children_tax_ids[0]
- child_tax_2 = self.tax_armageddon.children_tax_ids[1]
- self.assertInvoiceValues(self.invoice, [
- {
- **self.product_line_vals_1,
- 'price_unit': 960.0,
- 'price_subtotal': 800.0,
- 'price_total': 1176.0,
- 'tax_ids': (self.tax_purchase_a + self.tax_armageddon).ids,
- },
- self.product_line_vals_2,
- self.tax_line_vals_1,
- self.tax_line_vals_2,
- {
- 'name': child_tax_1.name,
- 'product_id': False,
- 'account_id': self.company_data['default_account_expense'].id,
- 'partner_id': self.partner_a.id,
- 'product_uom_id': False,
- 'quantity': False,
- 'discount': 0.0,
- 'price_unit': 0.0,
- 'price_subtotal': 0.0,
- 'price_total': 0.0,
- 'tax_ids': child_tax_2.ids,
- 'tax_line_id': child_tax_1.id,
- 'currency_id': self.company_data['currency'].id,
- 'amount_currency': -96.0,
- 'debit': 0.0,
- 'credit': 96.0,
- 'date_maturity': False,
- },
- {
- 'name': child_tax_1.name,
- 'product_id': False,
- 'account_id': self.company_data['default_account_tax_sale'].id,
- 'partner_id': self.partner_a.id,
- 'product_uom_id': False,
- 'quantity': False,
- 'discount': 0.0,
- 'price_unit': 0.0,
- 'price_subtotal': 0.0,
- 'price_total': 0.0,
- 'tax_ids': child_tax_2.ids,
- 'tax_line_id': child_tax_1.id,
- 'currency_id': self.company_data['currency'].id,
- 'amount_currency': -64.0,
- 'debit': 0.0,
- 'credit': 64.0,
- 'date_maturity': False,
- },
- {
- 'name': child_tax_2.name,
- 'product_id': False,
- 'account_id': child_tax_2.cash_basis_transition_account_id.id,
- 'partner_id': self.partner_a.id,
- 'product_uom_id': False,
- 'quantity': False,
- 'discount': 0.0,
- 'price_unit': 0.0,
- 'price_subtotal': 0.0,
- 'price_total': 0.0,
- 'tax_ids': [],
- 'tax_line_id': child_tax_2.id,
- 'currency_id': self.company_data['currency'].id,
- 'amount_currency': -96.0,
- 'debit': 0.0,
- 'credit': 96.0,
- 'date_maturity': False,
- },
- {
- **self.term_line_vals_1,
- 'price_unit': 0.0,
- 'price_subtotal': 0.0,
- 'price_total': 0.0,
- 'amount_currency': 1384.0,
- 'debit': 1384.0,
- },
- ], {
- **self.move_vals,
- 'amount_untaxed': 960.0,
- 'amount_tax': 424.0,
- 'amount_total': 1384.0,
- })
- def test_in_refund_line_onchange_cash_rounding_1(self):
- # Required for `invoice_cash_rounding_id` to be visible in the view
- self.env.user.groups_id += self.env.ref('account.group_cash_rounding')
- # Test 'add_invoice_line' rounding
- move_form = Form(self.invoice)
- # Add a cash rounding having 'add_invoice_line'.
- move_form.invoice_cash_rounding_id = self.cash_rounding_a
- move_form.save()
- # The cash rounding does nothing as the total is already rounded.
- self.assertInvoiceValues(self.invoice, [
- self.product_line_vals_1,
- self.product_line_vals_2,
- self.tax_line_vals_1,
- self.tax_line_vals_2,
- self.term_line_vals_1,
- ], self.move_vals)
- move_form = Form(self.invoice)
- with move_form.invoice_line_ids.edit(0) as line_form:
- line_form.price_unit = 799.99
- move_form.save()
- self.assertInvoiceValues(self.invoice, [
- {
- **self.product_line_vals_1,
- 'price_unit': 799.99,
- 'price_subtotal': 799.99,
- 'price_total': 919.99,
- 'amount_currency': -799.99,
- 'credit': 799.99,
- },
- self.product_line_vals_2,
- self.tax_line_vals_1,
- self.tax_line_vals_2,
- {
- 'name': 'add_invoice_line',
- 'product_id': False,
- 'account_id': self.cash_rounding_a.profit_account_id.id,
- 'partner_id': self.partner_a.id,
- 'product_uom_id': False,
- 'quantity': False,
- 'discount': 0.0,
- 'price_unit': 0.0,
- 'price_subtotal': 0.0,
- 'price_total': 0.0,
- 'tax_ids': [],
- 'tax_line_id': False,
- 'currency_id': self.company_data['currency'].id,
- 'amount_currency': -0.01,
- 'debit': 0.0,
- 'credit': 0.01,
- 'date_maturity': False,
- },
- self.term_line_vals_1,
- ], self.move_vals)
- # Test 'biggest_tax' rounding
- self.company_data['company'].country_id = self.env.ref('base.us')
- # Add a tag to product_a's default tax
- tax_line_tag = self.env['account.account.tag'].create({
- 'name': "Tax tag",
- 'applicability': 'taxes',
- 'country_id': self.company_data['company'].country_id.id,
- })
- repartition_line = self.tax_purchase_a.refund_repartition_line_ids.filtered(lambda x: x.repartition_type == 'tax')
- repartition_line.write({'tag_ids': [(4, tax_line_tag.id, 0)]})
- # Create the invoice
- biggest_tax_invoice = self.env['account.move'].create({
- 'move_type': 'in_refund',
- 'invoice_date': '2019-01-01',
- 'partner_id': self.partner_a.id,
- 'invoice_cash_rounding_id': self.cash_rounding_b.id,
- 'invoice_payment_term_id': self.pay_terms_a.id,
- 'invoice_line_ids': [
- (0, 0, {
- 'product_id': self.product_a.id,
- 'price_unit': 799.99,
- 'tax_ids': [(6, 0, self.product_a.supplier_taxes_id.ids)],
- 'product_uom_id': self.product_a.uom_id.id,
- }),
- (0, 0, {
- 'product_id': self.product_b.id,
- 'price_unit': self.product_b.standard_price,
- 'tax_ids': [(6, 0, self.product_b.supplier_taxes_id.ids)],
- 'product_uom_id': self.product_b.uom_id.id,
- }),
- ],
- })
- self.assertInvoiceValues(biggest_tax_invoice, [
- {
- **self.product_line_vals_1,
- 'price_unit': 799.99,
- 'price_subtotal': 799.99,
- 'price_total': 919.99,
- 'amount_currency': -799.99,
- 'credit': 799.99,
- 'tax_repartition_line_id': None,
- 'tax_tag_ids': [],
- },
- {
- **self.product_line_vals_2,
- 'tax_repartition_line_id': None,
- 'tax_tag_ids': [],
- },
- {
- **self.tax_line_vals_1,
- 'tax_repartition_line_id': repartition_line.id,
- 'tax_tag_ids': tax_line_tag.ids,
- },
- {
- **self.tax_line_vals_2,
- 'tax_repartition_line_id': self.tax_purchase_b.refund_repartition_line_ids.filtered(lambda x: x.repartition_type == 'tax').id,
- 'tax_tag_ids': [],
- },
- {
- 'name': '%s (rounding)' % self.tax_purchase_a.name,
- 'product_id': False,
- 'account_id': self.company_data['default_account_tax_purchase'].id,
- 'partner_id': self.partner_a.id,
- 'product_uom_id': False,
- 'quantity': False,
- 'discount': 0.0,
- 'price_unit': 0.0,
- 'price_subtotal': 0.0,
- 'price_total': 0.0,
- 'tax_ids': [],
- 'tax_line_id': self.tax_purchase_a.id,
- 'tax_repartition_line_id': repartition_line.id,
- 'tax_tag_ids': tax_line_tag.ids,
- 'currency_id': self.company_data['currency'].id,
- 'amount_currency': 0.04,
- 'debit': 0.04,
- 'credit': 0.0,
- 'date_maturity': False,
- },
- {
- **self.term_line_vals_1,
- 'price_unit': 0.0,
- 'price_subtotal': 0.0,
- 'price_total': 0.0,
- 'amount_currency': 1127.95,
- 'debit': 1127.95,
- 'tax_repartition_line_id': None,
- 'tax_tag_ids': [],
- },
- ], {
- **self.move_vals,
- 'amount_untaxed': 959.99,
- 'amount_tax': 167.96,
- 'amount_total': 1127.95,
- })
- def test_in_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': -800.0,
- 'credit': 400.0,
- },
- {
- **self.product_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -160.0,
- 'credit': 80.0,
- },
- {
- **self.tax_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -144.0,
- 'credit': 72.0,
- },
- {
- **self.tax_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -24.0,
- 'credit': 12.0,
- },
- {
- **self.term_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': 1128.0,
- 'debit': 564.0,
- },
- ], {
- **self.move_vals,
- 'currency_id': self.currency_data['currency'].id,
- })
- # Change the date to get another rate: 1/3 instead of 1/2.
- with Form(self.invoice) as move_form:
- move_form.invoice_date = fields.Date.from_string('2016-01-01')
- move_form.date = fields.Date.from_string('2016-01-01')
- self.assertInvoiceValues(self.invoice, [
- {
- **self.product_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -800.0,
- 'credit': 266.67,
- },
- {
- **self.product_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -160.0,
- 'credit': 53.33,
- },
- {
- **self.tax_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -144.0,
- 'credit': 48.0,
- },
- {
- **self.tax_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -24.0,
- 'credit': 8.0,
- },
- {
- **self.term_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': 1128.0,
- 'debit': 376.0,
- 'date_maturity': fields.Date.from_string('2016-01-01'),
- },
- ], {
- **self.move_vals,
- 'currency_id': self.currency_data['currency'].id,
- 'date': fields.Date.from_string('2016-01-01'),
- 'invoice_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,
- 'credit': 0.0,
- },
- {
- **self.product_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -160.0,
- 'credit': 53.33,
- },
- {
- **self.tax_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -24.001,
- 'credit': 8.0,
- },
- {
- **self.tax_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -24.0,
- 'credit': 8.0,
- },
- {
- **self.term_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': 208.006,
- 'debit': 69.33,
- 'date_maturity': fields.Date.from_string('2016-01-01'),
- },
- ], {
- **self.move_vals,
- 'currency_id': self.currency_data['currency'].id,
- 'date': fields.Date.from_string('2016-01-01'),
- 'invoice_date': fields.Date.from_string('2016-01-01'),
- 'amount_untaxed': 160.005,
- 'amount_tax': 48.001,
- 'amount_total': 208.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,
- 'credit': 0.01,
- },
- self.product_line_vals_2,
- {
- **self.tax_line_vals_1,
- 'amount_currency': -24.0,
- 'credit': 24.0,
- },
- self.tax_line_vals_2,
- {
- **self.term_line_vals_1,
- 'amount_currency': 208.01,
- 'debit': 208.01,
- 'date_maturity': fields.Date.from_string('2016-01-01'),
- },
- ], {
- **self.move_vals,
- 'currency_id': self.company_data['currency'].id,
- 'date': fields.Date.from_string('2016-01-01'),
- 'invoice_date': fields.Date.from_string('2016-01-01'),
- 'amount_untaxed': 160.01,
- 'amount_tax': 48.0,
- 'amount_total': 208.01,
- })
- def test_in_refund_onchange_past_invoice_1(self):
- copy_invoice = self.invoice.copy()
- if self.env.ref('purchase.group_purchase_manager', raise_if_not_found=False):
- # `purchase` adds a view which makes `invoice_vendor_bill_id` invisible
- # for purchase users
- # https://github.com/odoo/odoo/blob/385884afd31f25d61e99d139ecd4c574d99a1863/addons/purchase/views/account_move_views.xml#L26
- self.env.user.groups_id -= self.env.ref('purchase.group_purchase_manager')
- self.env.user.groups_id -= self.env.ref('purchase.group_purchase_user')
- # 'invisible': ['|', ('state', '!=', 'draft'), ('move_type', '!=', 'in_invoice')]
- # This is an in_refund invoice, `invoice_vendor_bill_id` is not supposed to be visible
- # and therefore not supposed to be changed.
- view = self.env.ref('account.view_move_form')
- tree = etree.fromstring(view.arch)
- for node in tree.xpath('//field[@name="invoice_vendor_bill_id"]'):
- del node.attrib['attrs']
- view.arch = etree.tostring(tree)
- move_form = Form(self.invoice)
- move_form.invoice_line_ids.remove(0)
- move_form.invoice_line_ids.remove(0)
- move_form.invoice_vendor_bill_id = copy_invoice
- move_form.save()
- self.assertInvoiceValues(self.invoice, [
- self.product_line_vals_1,
- self.product_line_vals_2,
- self.tax_line_vals_1,
- self.tax_line_vals_2,
- self.term_line_vals_1,
- ], self.move_vals)
- def test_in_refund_create_1(self):
- # Test creating an account_move with the least information.
- move = self.env['account.move'].create({
- 'move_type': 'in_refund',
- 'partner_id': self.partner_a.id,
- 'invoice_date': fields.Date.from_string('2019-01-01'),
- 'currency_id': self.currency_data['currency'].id,
- 'invoice_payment_term_id': self.pay_terms_a.id,
- 'invoice_line_ids': [
- Command.create({
- 'product_id': self.product_line_vals_1['product_id'],
- 'product_uom_id': self.product_line_vals_1['product_uom_id'],
- 'price_unit': self.product_line_vals_1['price_unit'],
- 'tax_ids': [Command.set(self.product_line_vals_1['tax_ids'])],
- }),
- Command.create({
- 'product_id': self.product_line_vals_2['product_id'],
- 'product_uom_id': self.product_line_vals_2['product_uom_id'],
- 'price_unit': self.product_line_vals_2['price_unit'],
- 'tax_ids': [Command.set(self.product_line_vals_2['tax_ids'])],
- }),
- ],
- })
- self.assertInvoiceValues(move, [
- {
- **self.product_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -800.0,
- 'credit': 400.0,
- },
- {
- **self.product_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -160.0,
- 'credit': 80.0,
- },
- {
- **self.tax_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -144.0,
- 'credit': 72.0,
- },
- {
- **self.tax_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -24.0,
- 'credit': 12.0,
- },
- {
- **self.term_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': 1128.0,
- 'debit': 564.0,
- },
- ], {
- **self.move_vals,
- 'currency_id': self.currency_data['currency'].id,
- })
- def test_in_refund_write_1(self):
- # Test creating an account_move with the least information.
- move = self.env['account.move'].create({
- 'move_type': 'in_refund',
- 'partner_id': self.partner_a.id,
- 'invoice_date': fields.Date.from_string('2019-01-01'),
- 'currency_id': self.currency_data['currency'].id,
- 'invoice_payment_term_id': self.pay_terms_a.id,
- 'invoice_line_ids': [
- Command.create({
- 'product_id': self.product_line_vals_1['product_id'],
- 'product_uom_id': self.product_line_vals_1['product_uom_id'],
- 'price_unit': self.product_line_vals_1['price_unit'],
- 'tax_ids': [Command.set(self.product_line_vals_1['tax_ids'])],
- }),
- ],
- })
- move.write({
- 'invoice_line_ids': [
- Command.create({
- 'product_id': self.product_line_vals_2['product_id'],
- 'product_uom_id': self.product_line_vals_2['product_uom_id'],
- 'price_unit': self.product_line_vals_2['price_unit'],
- 'tax_ids': [Command.set(self.product_line_vals_2['tax_ids'])],
- }),
- ],
- })
- self.assertInvoiceValues(move, [
- {
- **self.product_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -800.0,
- 'credit': 400.0,
- },
- {
- **self.product_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -160.0,
- 'credit': 80.0,
- },
- {
- **self.tax_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -144.0,
- 'credit': 72.0,
- },
- {
- **self.tax_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -24.0,
- 'credit': 12.0,
- },
- {
- **self.term_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': 1128.0,
- 'debit': 564.0,
- },
- ], {
- **self.move_vals,
- 'currency_id': self.currency_data['currency'].id,
- })
- def test_in_refund_create_storno(self):
- # Test creating an account_move refund (credit note)
- # with multiple lines while in Storno accounting
- self.env.company.account_storno = True
- move = self.env['account.move'].create({
- 'move_type': 'in_refund',
- 'partner_id': self.partner_a.id,
- 'invoice_date': fields.Date.from_string('2019-01-01'),
- 'currency_id': self.currency_data['currency'].id,
- 'invoice_payment_term_id': self.pay_terms_a.id,
- 'invoice_line_ids': [
- Command.create({
- 'product_id': self.product_line_vals_1['product_id'],
- 'product_uom_id': self.product_line_vals_1['product_uom_id'],
- 'price_unit': self.product_line_vals_1['price_unit'],
- 'tax_ids': [Command.set(self.product_line_vals_1['tax_ids'])],
- }),
- Command.create({
- 'product_id': self.product_line_vals_2['product_id'],
- 'product_uom_id': self.product_line_vals_2['product_uom_id'],
- 'price_unit': self.product_line_vals_2['price_unit'],
- 'tax_ids': [Command.set(self.product_line_vals_2['tax_ids'])],
- }),
- ]
- })
- self.assertInvoiceValues(move, [
- {
- **self.product_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -800.0,
- 'balance': -400.0,
- 'debit': -400.0,
- 'credit': 0.0,
- },
- {
- **self.product_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -160.0,
- 'balance': -80.0,
- 'debit': -80.0,
- 'credit': 0.0,
- },
- {
- **self.tax_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -144.0,
- 'balance': -72.0,
- 'debit': -72.0,
- 'credit': 0.0,
- },
- {
- **self.tax_line_vals_2,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': -24.0,
- 'balance': -12.0,
- 'debit': -12.0,
- 'credit': 0.0,
- },
- {
- **self.term_line_vals_1,
- 'currency_id': self.currency_data['currency'].id,
- 'amount_currency': 1128.0,
- 'balance': 564.0,
- 'debit': 0.0,
- 'credit': -564.0,
- },
- ], {
- **self.move_vals,
- 'currency_id': self.currency_data['currency'].id,
- })
- def test_in_refund_reverse_caba(self):
- tax_waiting_account = self.env['account.account'].create({
- 'name': 'TAX_WAIT',
- 'code': 'TWAIT',
- 'account_type': 'liability_current',
- 'reconcile': True,
- 'company_id': self.company_data['company'].id,
- })
- tax_final_account = self.env['account.account'].create({
- 'name': 'TAX_TO_DEDUCT',
- 'code': 'TDEDUCT',
- 'account_type': 'asset_current',
- 'company_id': self.company_data['company'].id,
- })
- tax_base_amount_account = self.env['account.account'].create({
- 'name': 'TAX_BASE',
- 'code': 'TBASE',
- 'account_type': 'asset_current',
- 'company_id': self.company_data['company'].id,
- })
- self.env.company.account_cash_basis_base_account_id = tax_base_amount_account
- self.env.company.tax_exigibility = True
- tax_tags = defaultdict(dict)
- for line_type, repartition_type in [(l, r) for l in ('invoice', 'refund') for r in ('base', 'tax')]:
- tax_tags[line_type][repartition_type] = self.env['account.account.tag'].create({
- 'name': '%s %s tag' % (line_type, repartition_type),
- 'applicability': 'taxes',
- 'country_id': self.env.ref('base.us').id,
- })
- tax = self.env['account.tax'].create({
- 'name': 'cash basis 10%',
- 'type_tax_use': 'purchase',
- 'amount': 10,
- 'tax_exigibility': 'on_payment',
- 'cash_basis_transition_account_id': tax_waiting_account.id,
- 'invoice_repartition_line_ids': [
- (0, 0, {
- 'repartition_type': 'base',
- 'tag_ids': [(6, 0, tax_tags['invoice']['base'].ids)],
- }),
- (0, 0, {
- 'repartition_type': 'tax',
- 'account_id': tax_final_account.id,
- 'tag_ids': [(6, 0, tax_tags['invoice']['tax'].ids)],
- }),
- ],
- 'refund_repartition_line_ids': [
- (0, 0, {
- 'repartition_type': 'base',
- 'tag_ids': [(6, 0, tax_tags['refund']['base'].ids)],
- }),
- (0, 0, {
- 'repartition_type': 'tax',
- 'account_id': tax_final_account.id,
- 'tag_ids': [(6, 0, tax_tags['refund']['tax'].ids)],
- }),
- ],
- })
- # create invoice
- move_form = Form(self.env['account.move'].with_context(default_move_type='in_refund'))
- move_form.partner_id = self.partner_a
- move_form.invoice_date = fields.Date.from_string('2017-01-01')
- with move_form.invoice_line_ids.new() as line_form:
- line_form.product_id = self.product_a
- line_form.tax_ids.clear()
- line_form.tax_ids.add(tax)
- invoice = move_form.save()
- invoice.action_post()
- # make payment
- self.env['account.payment.register'].with_context(active_model='account.move', active_ids=invoice.ids).create({
- 'payment_date': invoice.date,
- })._create_payments()
- # check caba move
- partial_rec = invoice.mapped('line_ids.matched_credit_ids')
- caba_move = self.env['account.move'].search([('tax_cash_basis_rec_id', '=', partial_rec.id)])
- expected_values = [
- {
- 'tax_line_id': False,
- 'tax_repartition_line_id': False,
- 'tax_ids': [],
- 'tax_tag_ids': [],
- 'account_id': tax_base_amount_account.id,
- 'debit': 800.0,
- 'credit': 0.0,
- },
- {
- 'tax_line_id': False,
- 'tax_repartition_line_id': False,
- 'tax_ids': tax.ids,
- 'tax_tag_ids': tax_tags['refund']['base'].ids,
- 'account_id': tax_base_amount_account.id,
- 'debit': 0.0,
- 'credit': 800.0,
- },
- {
- 'tax_line_id': False,
- 'tax_repartition_line_id': False,
- 'tax_ids': [],
- 'tax_tag_ids': [],
- 'account_id': tax_waiting_account.id,
- 'debit': 80.0,
- 'credit': 0.0,
- },
- {
- 'tax_line_id': tax.id,
- 'tax_repartition_line_id': tax.refund_repartition_line_ids.filtered(lambda x: x.repartition_type == 'tax').id,
- 'tax_ids': [],
- 'tax_tag_ids': tax_tags['refund']['tax'].ids,
- 'account_id': tax_final_account.id,
- 'debit': 0.0,
- 'credit': 80.0,
- },
- ]
- self.assertRecordValues(caba_move.line_ids, expected_values)
- # unreconcile
- debit_aml = invoice.line_ids.filtered('debit')
- debit_aml.remove_move_reconcile()
- # check caba move reverse is same as caba move with only debit/credit inverted
- reversed_caba_move = self.env['account.move'].search([('reversed_entry_id', '=', caba_move.id)])
- for value in expected_values:
- value.update({
- 'debit': value['credit'],
- 'credit': value['debit'],
- })
- self.assertRecordValues(reversed_caba_move.line_ids, expected_values)
|