From 928ec712401def480d1f3e95dc1bb6e6b987658b Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Wed, 11 Oct 2023 11:30:10 +0200 Subject: [PATCH 1/4] [IMP] contract: Allow to single invoice a contract by users in a more controlled way It should allow you to process sale orders and other kinds Remove the extra button not necessary any more --- contract/__manifest__.py | 1 + contract/models/contract.py | 20 ++- contract/readme/CONTRIBUTORS.rst | 3 + contract/security/ir.model.access.csv | 1 + contract/tests/test_contract.py | 151 +++++++++++++----- .../test_contract_manually_create_invoice.py | 25 +++ contract/views/contract.xml | 10 +- contract/wizards/__init__.py | 1 + .../contract_manually_single_invoice.py | 42 +++++ .../contract_manually_single_invoice.xml | 41 +++++ 10 files changed, 249 insertions(+), 46 deletions(-) create mode 100644 contract/wizards/contract_manually_single_invoice.py create mode 100644 contract/wizards/contract_manually_single_invoice.xml diff --git a/contract/__manifest__.py b/contract/__manifest__.py index a32ca9f23e..93163ce817 100644 --- a/contract/__manifest__.py +++ b/contract/__manifest__.py @@ -35,6 +35,7 @@ "wizards/contract_line_wizard.xml", "wizards/contract_manually_create_invoice.xml", "wizards/contract_contract_terminate.xml", + "wizards/contract_manually_single_invoice.xml", "views/contract_tag.xml", "views/account_move_views.xml", "views/assets.xml", diff --git a/contract/models/contract.py b/contract/models/contract.py index 520684ed67..2c2fd85af8 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -574,6 +574,10 @@ def recurring_create_invoice(self): This method triggers the creation of the next invoices of the contracts even if their next invoicing date is in the future. """ + _logger.warning( + "recurring_create_invoice is deprecated in favor of " + "_recurring_create_invoice instead" + ) invoices = self._recurring_create_invoice() for invoice in invoices: self.message_post( @@ -633,17 +637,24 @@ def _get_recurring_create_func(self, create_type="invoice"): return self.__class__._recurring_create_invoice @api.model - def _cron_recurring_create(self, date_ref=False, create_type="invoice"): + def _cron_recurring_create( + self, date_ref=False, create_type="invoice", domain=None + ): """ The cron function in order to create recurrent documents from contracts. + The domain is used to add an extra filter """ + if domain is None: + domain = [] _recurring_create_func = self._get_recurring_create_func( create_type=create_type ) if not date_ref: date_ref = fields.Date.context_today(self) - domain = self._get_contracts_to_invoice_domain(date_ref) + domain = expression.AND( + [domain, self._get_contracts_to_invoice_domain(date_ref)] + ) domain = expression.AND( [ domain, @@ -652,14 +663,15 @@ def _cron_recurring_create(self, date_ref=False, create_type="invoice"): ) contracts = self.search(domain) companies = set(contracts.mapped("company_id")) + result = [] # Invoice by companies, so assignation emails get correct context for company in companies: contracts_to_invoice = contracts.filtered( lambda c: c.company_id == company and (not c.date_end or c.recurring_next_date <= c.date_end) ).with_company(company) - _recurring_create_func(contracts_to_invoice, date_ref) - return True + result.append(_recurring_create_func(contracts_to_invoice, date_ref)) + return result @api.model def cron_recurring_create_invoice(self, date_ref=None): diff --git a/contract/readme/CONTRIBUTORS.rst b/contract/readme/CONTRIBUTORS.rst index 1d303c64da..c4b14576ae 100644 --- a/contract/readme/CONTRIBUTORS.rst +++ b/contract/readme/CONTRIBUTORS.rst @@ -15,3 +15,6 @@ * Víctor Martínez * Iván Antón * Eric Antones +* `Dixmit `_: + + * Enric Tobella diff --git a/contract/security/ir.model.access.csv b/contract/security/ir.model.access.csv index 63b7beaf76..2707753629 100644 --- a/contract/security/ir.model.access.csv +++ b/contract/security/ir.model.access.csv @@ -14,3 +14,4 @@ "contract_line_wizard","contract_line_wizard","model_contract_line_wizard","account.group_account_manager",1,1,1,1 "contract_manually_create_invoice_wizard","contract_manually_create_invoice_wizard","model_contract_manually_create_invoice","account.group_account_invoice",1,1,1,1 "contract_contract_terminate_wizard","contract_contract_terminate_wizard","model_contract_contract_terminate","contract.can_terminate_contract",1,1,1,1 +"contract_manually_single_invoice_wizard","contract_manually_single_process_wizard","model_contract_manually_single_invoice","account.group_account_invoice",1,1,1,1 diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index 5ea558f0c7..7fe653fa25 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -279,7 +279,9 @@ def test_contract(self): self.acct_line._onchange_product_id() self.acct_line.price_unit = 100.0 self.contract.partner_id = self.partner.id - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() self.invoice_monthly = self.contract._get_related_invoices() self.assertTrue(self.invoice_monthly) self.assertEqual(self.acct_line.recurring_next_date, to_date("2018-02-15")) @@ -298,7 +300,9 @@ def test_contract_daily(self): self.acct_line.recurring_next_date = "2018-02-22" self.acct_line.recurring_rule_type = "daily" self.contract.pricelist_id = False - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoice_daily = self.contract._get_related_invoices() self.assertTrue(invoice_daily) self.assertEqual(self.acct_line.recurring_next_date, recurring_next_date) @@ -317,7 +321,9 @@ def test_contract_invoice_followers(self): self.contract.message_subscribe( partner_ids=self.contract.partner_id.ids, subtype_ids=subtype_ids ) - self.contract._recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoice_daily = self.contract._get_related_invoices() self.assertTrue(invoice_daily) self.assertTrue(self.contract.partner_id in invoice_daily.message_partner_ids) @@ -329,7 +335,9 @@ def test_contract_invoice_salesperson(self): {"name": "Some Salesperson", "login": "salesperson_test"} ) self.contract.user_id = new_salesperson - self.contract._recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoice_daily = self.contract._get_related_invoices() self.assertTrue(invoice_daily) self.assertEqual(self.contract.user_id, invoice_daily.user_id) @@ -341,7 +349,9 @@ def test_contract_weekly_post_paid(self): self.acct_line.recurring_next_date = "2018-02-22" self.acct_line.recurring_rule_type = "weekly" self.acct_line.recurring_invoicing_type = "post-paid" - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoices_weekly = self.contract._get_related_invoices() self.assertTrue(invoices_weekly) self.assertEqual(self.acct_line.recurring_next_date, recurring_next_date) @@ -353,7 +363,9 @@ def test_contract_weekly_pre_paid(self): self.acct_line.recurring_next_date = "2018-02-22" self.acct_line.recurring_rule_type = "weekly" self.acct_line.recurring_invoicing_type = "pre-paid" - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoices_weekly = self.contract._get_related_invoices() self.assertTrue(invoices_weekly) self.assertEqual(self.acct_line.recurring_next_date, recurring_next_date) @@ -365,7 +377,9 @@ def test_contract_yearly_post_paid(self): self.acct_line.recurring_next_date = "2018-02-22" self.acct_line.recurring_rule_type = "yearly" self.acct_line.recurring_invoicing_type = "post-paid" - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoices_weekly = self.contract._get_related_invoices() self.assertTrue(invoices_weekly) self.assertEqual(self.acct_line.recurring_next_date, recurring_next_date) @@ -378,7 +392,9 @@ def test_contract_yearly_pre_paid(self): self.acct_line.recurring_next_date = "2018-02-22" self.acct_line.recurring_rule_type = "yearly" self.acct_line.recurring_invoicing_type = "pre-paid" - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoices_weekly = self.contract._get_related_invoices() self.assertTrue(invoices_weekly) self.assertEqual(self.acct_line.recurring_next_date, recurring_next_date) @@ -390,7 +406,9 @@ def test_contract_monthly_lastday(self): self.acct_line.recurring_next_date = "2018-02-22" self.acct_line.recurring_invoicing_type = "post-paid" self.acct_line.recurring_rule_type = "monthlylastday" - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoices_monthly_lastday = self.contract._get_related_invoices() self.assertTrue(invoices_monthly_lastday) self.assertEqual(self.acct_line.recurring_next_date, recurring_next_date) @@ -403,7 +421,9 @@ def test_contract_quarterly_pre_paid(self): self.acct_line.recurring_next_date = "2018-02-22" self.acct_line.recurring_rule_type = "quarterly" self.acct_line.recurring_invoicing_type = "pre-paid" - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoices_weekly = self.contract._get_related_invoices() self.assertTrue(invoices_weekly) self.assertEqual(self.acct_line.recurring_next_date, recurring_next_date) @@ -416,7 +436,9 @@ def test_contract_quarterly_post_paid(self): self.acct_line.recurring_next_date = "2018-02-22" self.acct_line.recurring_rule_type = "quarterly" self.acct_line.recurring_invoicing_type = "post-paid" - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoices_weekly = self.contract._get_related_invoices() self.assertTrue(invoices_weekly) self.assertEqual(self.acct_line.recurring_next_date, recurring_next_date) @@ -429,7 +451,9 @@ def test_contract_semesterly_pre_paid(self): self.acct_line.recurring_next_date = "2018-02-22" self.acct_line.recurring_rule_type = "semesterly" self.acct_line.recurring_invoicing_type = "pre-paid" - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoices_weekly = self.contract._get_related_invoices() self.assertTrue(invoices_weekly) self.assertEqual(self.acct_line.recurring_next_date, recurring_next_date) @@ -442,7 +466,9 @@ def test_contract_semesterly_post_paid(self): self.acct_line.recurring_next_date = "2018-02-22" self.acct_line.recurring_rule_type = "semesterly" self.acct_line.recurring_invoicing_type = "post-paid" - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() invoices_weekly = self.contract._get_related_invoices() self.assertTrue(invoices_weekly) self.assertEqual(self.acct_line.recurring_next_date, recurring_next_date) @@ -481,13 +507,19 @@ def test_last_invoice_pre_paid(self): self.assertTrue(self.acct_line.create_invoice_visibility) self.assertEqual(self.acct_line.recurring_next_date, to_date("2018-01-01")) self.assertFalse(self.acct_line.last_date_invoiced) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() self.assertEqual(self.acct_line.recurring_next_date, to_date("2018-02-01")) self.assertEqual(self.acct_line.last_date_invoiced, to_date("2018-01-31")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() self.assertEqual(self.acct_line.last_date_invoiced, to_date("2018-02-28")) self.assertEqual(self.acct_line.last_date_invoiced, to_date("2018-02-28")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() self.assertEqual(self.acct_line.last_date_invoiced, to_date("2018-03-15")) self.assertFalse(self.acct_line.recurring_next_date) self.assertFalse(self.acct_line.create_invoice_visibility) @@ -541,7 +573,12 @@ def test_check_journal(self): journal = self.env["account.journal"].search([("type", "=", "sale")]) journal.write({"type": "general"}) with self.assertRaises(ValidationError): - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + { + "date": self.contract.recurring_next_date, + "contract_id": self.contract.id, + } + ).create_invoice() def test_check_date_end(self): with self.assertRaises(ValidationError): @@ -1132,7 +1169,9 @@ def _error_message( def test_recurring_next_date(self): """recurring next date for a contract is the min for all lines""" - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() self.assertEqual( self.contract.recurring_next_date, min(self.contract.contract_line_ids.mapped("recurring_next_date")), @@ -1788,14 +1827,18 @@ def test_get_period_to_invoice_monthlylastday_postpaid(self): ) self.assertEqual(first, to_date("2018-01-05")) self.assertEqual(last, to_date("2018-01-31")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, ) self.assertEqual(first, to_date("2018-02-01")) self.assertEqual(last, to_date("2018-02-28")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, @@ -1817,7 +1860,9 @@ def test_get_period_to_invoice_monthlylastday_prepaid(self): self.assertEqual(last, to_date("2018-01-31")) self.assertEqual(recurring_next_date, to_date("2018-01-05")) self.assertEqual(self.acct_line.recurring_next_date, to_date("2018-01-05")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, @@ -1827,7 +1872,9 @@ def test_get_period_to_invoice_monthlylastday_prepaid(self): self.assertEqual(recurring_next_date, to_date("2018-02-01")) self.assertEqual(self.acct_line.recurring_next_date, to_date("2018-02-01")) self.assertEqual(self.acct_line.last_date_invoiced, to_date("2018-01-31")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, @@ -1837,7 +1884,9 @@ def test_get_period_to_invoice_monthlylastday_prepaid(self): self.assertEqual(recurring_next_date, to_date("2018-03-01")) self.assertEqual(self.acct_line.recurring_next_date, to_date("2018-03-01")) self.assertEqual(self.acct_line.last_date_invoiced, to_date("2018-02-28")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, @@ -1873,7 +1922,9 @@ def test_get_period_to_invoice_monthly_post_paid_2(self): self.acct_line.recurring_invoicing_type = "post-paid" self.acct_line.recurring_rule_type = "monthly" self.acct_line.date_end = "2018-08-15" - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, @@ -1899,14 +1950,18 @@ def test_get_period_to_invoice_monthly_post_paid(self): ) self.assertEqual(first, to_date("2018-01-05")) self.assertEqual(last, to_date("2018-02-04")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, ) self.assertEqual(first, to_date("2018-02-05")) self.assertEqual(last, to_date("2018-03-04")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, @@ -1925,14 +1980,18 @@ def test_get_period_to_invoice_monthly_pre_paid(self): ) self.assertEqual(first, to_date("2018-01-05")) self.assertEqual(last, to_date("2018-02-04")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, ) self.assertEqual(first, to_date("2018-02-05")) self.assertEqual(last, to_date("2018-03-04")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, @@ -1951,14 +2010,18 @@ def test_get_period_to_invoice_yearly_post_paid(self): ) self.assertEqual(first, to_date("2018-01-05")) self.assertEqual(last, to_date("2019-01-04")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, ) self.assertEqual(first, to_date("2019-01-05")) self.assertEqual(last, to_date("2020-01-04")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, @@ -1977,14 +2040,18 @@ def test_get_period_to_invoice_yearly_pre_paid(self): ) self.assertEqual(first, to_date("2018-01-05")) self.assertEqual(last, to_date("2019-01-04")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, ) self.assertEqual(first, to_date("2019-01-05")) self.assertEqual(last, to_date("2020-01-04")) - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() first, last, recurring_next_date = self.acct_line._get_period_to_invoice( self.acct_line.last_date_invoiced, self.acct_line.recurring_next_date, @@ -2239,9 +2306,15 @@ def test_sale_fields_view_get(self): self.assertEqual(view["view_id"], sale_form_view.id) def test_contract_count_invoice(self): - self.contract.recurring_create_invoice() - self.contract.recurring_create_invoice() - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() self.contract._compute_invoice_count() self.assertEqual(self.contract.invoice_count, 3) @@ -2280,7 +2353,9 @@ def test_invoice_contract_without_lines(self): self.assertFalse(self.contract.recurring_create_invoice()) def test_stop_at_last_date_invoiced(self): - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() self.assertTrue(self.acct_line.recurring_next_date) self.acct_line.stop(self.acct_line.last_date_invoiced) self.assertFalse(self.acct_line.recurring_next_date) @@ -2373,7 +2448,9 @@ def test_action_terminate_contract_check_recurring_dates(self): self.assertFalse(self.contract3.recurring_next_date) def test_terminate_date_before_last_date_invoiced(self): - self.contract.recurring_create_invoice() + self.env["contract.manually.single.invoice"].create( + {"date": self.contract.recurring_next_date, "contract_id": self.contract.id} + ).create_invoice() self.assertEqual(self.acct_line.last_date_invoiced, to_date("2018-02-14")) group_can_terminate_contract = self.env.ref("contract.can_terminate_contract") group_can_terminate_contract.users |= self.env.user diff --git a/contract/tests/test_contract_manually_create_invoice.py b/contract/tests/test_contract_manually_create_invoice.py index fb13bdd4a9..7f403e8168 100644 --- a/contract/tests/test_contract_manually_create_invoice.py +++ b/contract/tests/test_contract_manually_create_invoice.py @@ -48,6 +48,31 @@ def test_contract_manually_create_invoice(self): self.assertFalse(invoice_lines.mapped("move_id") - invoices) self.assertEqual(len(invoices), contract_to_invoice_count) + def test_contract_manually_single_contract(self): + contracts = self.env["contract.contract"] + for _i in range(10): + contracts |= self.contract.copy() + wizard = self.env["contract.manually.single.invoice"].create( + {"date": self.today, "contract_id": self.contract.id} + ) + wizard.create_invoice() + invoice_lines = self.env["account.move.line"].search( + [("contract_line_id", "in", contracts.mapped("contract_line_ids").ids)] + ) + self.assertEqual( + 0, + len(invoice_lines), + ) + invoice_lines = self.env["account.move.line"].search( + [("contract_line_id", "in", self.contract.mapped("contract_line_ids").ids)] + ) + self.assertEqual( + 2, + len(invoice_lines), + ) + # Two invoices are available from to 2018-1-1 2018-3-15. + # We are invoicing at the end of the month + def test_contract_manually_create_invoice_with_usererror(self): contracts = self.contract diff --git a/contract/views/contract.xml b/contract/views/contract.xml index 1e9ddebe04..3e0b2a764a 100644 --- a/contract/views/contract.xml +++ b/contract/views/contract.xml @@ -38,11 +38,11 @@ groups="base.group_user" />