Browse Source

Merge PR #315 into 10.0

Signed-off-by pedrobaeza
pull/277/merge
OCA-git-bot 5 years ago
parent
commit
6c1a5d1d42
  1. 3
      contract/models/account_analytic_contract.py
  2. 12
      contract_show_invoice/models/account_analytic_account.py
  3. 32
      contract_show_invoice/test/test_contract_show_invoice.py
  4. 0
      contract_show_invoice/tests/__init__.py
  5. 68
      contract_show_invoice/tests/test_contract_show_invoice.py
  6. 13
      contract_show_invoice/views/contract_view.xml

3
contract/models/account_analytic_contract.py

@ -80,4 +80,5 @@ class AccountAnalyticContract(models.Model):
domain = [
('type', '=', 'sale'),
('company_id', '=', company_id)]
return self.env['account.journal'].search(domain, limit=1)
return self.env['account.journal'].search(
domain, order='sequence asc', limit=1)

12
contract_show_invoice/models/account_analytic_account.py

@ -10,13 +10,15 @@ class AccountAnalyticAccount(models.Model):
@api.multi
def _compute_total_invoiced(self):
invoice_model = self.env['account.invoice']
invoice_line_model = self.env['account.invoice.line']
for analytic in self:
fetch_data = invoice_model.read_group(
[('invoice_line_ids.account_analytic_id', '=', analytic.id)],
['amount_total'], [],
fetch_data = invoice_line_model.read_group(
[('account_analytic_id', '=', analytic.id),
('invoice_id.state', 'in', ['open', 'paid']),
('invoice_id.type', 'in', ['out_invoice', 'out_refund'])],
['price_subtotal_signed'], [],
)
analytic.total_invoiced = fetch_data[0]['amount_total']
analytic.total_invoiced = fetch_data[0]['price_subtotal_signed']
total_invoiced = fields.Float(string="Total Invoiced",
compute='_compute_total_invoiced')

32
contract_show_invoice/test/test_contract_show_invoice.py

@ -1,32 +0,0 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.tests.common import TransactionCase
class TestContractShowInvoice(TransactionCase):
def setUp(self):
super(TestContractShowInvoice, self).setUp()
self.analytic_account = self.env['account.analytic.account'].create({
'name': 'Test contract show invoice',
})
self.invoice = self.env['account.invoice'].create(
{'partner_id': self.env.ref('base.res_partner_2').id,
'type': 'out_invoice',
})
self.invoice._onchange_partner_id()
self.invoice_line = self.env['account.invoice.line'].create(
{'product_id': self.env.ref('product.product_product_2').id,
'quantity': 1.0,
'invoice_id': self.invoice.id,
'account_analytic_id': self.analytic_account.id,
})
self.invoice_line._onchange_product_id()
def test_contract_show_invoice(self):
self.assertEqual(len(self.analytic_account.analytic_account_ids), 1)
def test_contract_total_invoiced(self):
self.assertEqual(self.invoice.amount_total,
self.analytic_account.total_invoiced)

0
contract_show_invoice/test/__init__.py → contract_show_invoice/tests/__init__.py

68
contract_show_invoice/tests/test_contract_show_invoice.py

@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.tests.common import TransactionCase
class TestContractShowInvoice(TransactionCase):
def setUp(self):
super(TestContractShowInvoice, self).setUp()
self.analytic_account = self.env['account.analytic.account'].create({
'name': 'Test contract show invoice',
})
self.invoice = self.env['account.invoice'].create(
{'partner_id': self.env.ref('base.res_partner_2').id,
'type': 'out_invoice',
})
self.invoice.journal_id.update_posted = True
self.invoice._onchange_partner_id()
self.a_sale = self.env['account.account'].search([
('user_type_id', '=',
self.env.ref('account.data_account_type_revenue').id)
], limit=1)
self.invoice_line = self.env['account.invoice.line'].create(
{'product_id': self.env.ref('product.product_product_2').id,
'quantity': 1.0,
'invoice_id': self.invoice.id,
'account_analytic_id': self.analytic_account.id,
'account_id': self.a_sale.id,
'price_unit': 50.0,
'name': 'Invoice line with analytic account',
'invoice_line_tax_ids': [(4, self.env['account.tax'].search(
[('type_tax_use', '=', 'sale')], limit=1).id, 0)]
})
self.invoice.compute_taxes()
self.invoice.action_invoice_open()
def test_invoice_two_line(self):
self.assertEqual(
self.analytic_account.total_invoiced,
self.invoice_line.price_subtotal,
msg="Amount invoiced is different from single invoice line wich "
"has analytic account")
self.invoice.action_invoice_cancel()
self.invoice.action_invoice_draft()
self.invoice_line1 = self.env['account.invoice.line'].create(
{'product_id': self.env.ref('product.product_product_2').id,
'quantity': 2.0,
'invoice_id': self.invoice.id,
'account_analytic_id': False,
'account_id': self.a_sale.id,
'price_unit': 100.0,
'name': 'Invoice line without analytic account',
'invoice_line_tax_ids': [(4, self.env['account.tax'].search(
[('type_tax_use', '=', 'sale')], limit=1).id, 0)]
})
self.invoice.compute_taxes()
self.invoice.action_invoice_open()
self.assertFalse(self.invoice_line1.account_analytic_id,
msg="Invoice line has analytic account")
self.assertEqual(len(self.invoice.analytic_account_ids), 1,
msg="Invoice lines with analytic account are more "
"than one")
self.assertEqual(
self.analytic_account.total_invoiced,
self.invoice_line.price_subtotal,
msg="Amount invoiced is different from invoice lines wich "
"has analytic account")

13
contract_show_invoice/views/contract_view.xml

@ -6,7 +6,7 @@
[active_id], 'default_analytic_account_ids': [active_id]}</field>
<field name="name">Invoices</field>
<field name="res_model">account.invoice</field>
<field name="domain">[('analytic_account_ids','=',active_id)]</field>
<field name="domain">[('analytic_account_ids','=',active_id), ('type','in', ['out_invoice', 'out_refund']), ('state', 'not in', ['draft', 'cancel'])]</field>
<field name="search_view_id" ref="account.view_account_invoice_filter" />
</record>
@ -24,6 +24,17 @@
<field name="act_window_id" ref="act_analytic_invoices"/>
</record>
<record id="invoice_tree_show_total_untaxed" model="ir.ui.view">
<field name="name">account.invoice.tree.show.total.untaxed</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_tree"/>
<field name="arch" type="xml">
<field name="amount_total_signed" position="after">
<field name="amount_untaxed_signed" sum="Total Untaxed"/>
</field>
</field>
</record>
<record id="account_analytic_account_button_invoice" model="ir.ui.view">
<field name="name">account.analytic.account.button.invoice
</field>

Loading…
Cancel
Save