Permalink
Browse files

[MERGE] forward port branch 10.0 up to b131658

  • Loading branch information...
KangOl committed Jan 10, 2019
2 parents cdb0c08 + b131658 commit 390d8594b08ba8dccf51450ec5d00e4d39884cee
Showing with 66 additions and 1 deletion.
  1. +3 −1 addons/account/models/account_invoice.py
  2. +63 −0 addons/account/tests/test_account_customer_invoice.py
@@ -642,6 +642,7 @@ def _prepare_tax_line_vals(self, line, tax):
@api.multi
def get_taxes_values(self):
tax_grouped = {}
round_curr = self.currency_id.round
for line in self.invoice_line_ids:
price_unit = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
taxes = line.invoice_line_tax_ids.compute_all(price_unit, self.currency_id, line.quantity, line.product_id, self.partner_id)['taxes']
@@ -651,9 +652,10 @@ def get_taxes_values(self):

if key not in tax_grouped:
tax_grouped[key] = val
tax_grouped[key]['base'] = round_curr(val['base'])
else:
tax_grouped[key]['amount'] += val['amount']
tax_grouped[key]['base'] += val['base']
tax_grouped[key]['base'] += round_curr(val['base'])
return tax_grouped

@api.multi
@@ -107,3 +107,66 @@ def test_customer_invoice(self):

# I clicked on refund button.
self.account_invoice_refund_0.invoice_refund()

def test_customer_invoice_tax(self):

self.env.user.company_id.tax_calculation_rounding_method = 'round_globally'

payment_term = self.env.ref('account.account_payment_term_advance')
journalrec = self.env['account.journal'].search([('type', '=', 'sale')])[0]
partner3 = self.env.ref('base.res_partner_3')
account_id = self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id

tax = self.env['account.tax'].create({
'name': 'Tax 15.0',
'amount': 15.0,
'amount_type': 'percent',
'type_tax_use': 'sale',
})

invoice_line_data = [
(0, 0,
{
'product_id': self.env.ref('product.product_product_1').id,
'quantity': 40.0,
'account_id': account_id,
'name': 'product test 1',
'discount' : 10.00,
'price_unit': 2.27,
'invoice_line_tax_ids': [(6, 0, [tax.id])],
}
),
(0, 0,
{
'product_id': self.env.ref('product.product_product_2').id,
'quantity': 21.0,
'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id,
'name': 'product test 2',
'discount' : 10.00,
'price_unit': 2.77,
'invoice_line_tax_ids': [(6, 0, [tax.id])],
}
),
(0, 0,
{
'product_id': self.env.ref('product.product_product_3').id,
'quantity': 21.0,
'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id,
'name': 'product test 3',
'discount' : 10.00,
'price_unit': 2.77,
'invoice_line_tax_ids': [(6, 0, [tax.id])],
}
)
]

invoice = self.env['account.invoice'].create(dict(
name="Test Customer Invoice",
reference_type="none",
payment_term_id=payment_term.id,
journal_id=journalrec.id,
partner_id=partner3.id,
invoice_line_ids=invoice_line_data
))

self.assertEquals(invoice.amount_untaxed, sum([x.base for x in invoice.tax_line_ids]))

0 comments on commit 390d859

Please sign in to comment.