Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] contract: Allow to single invoice a contract by users #1005

Open
wants to merge 4 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion contract/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Recurring - Contracts Management
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:124a989ae63b390105b95256e33dd7e90ea48cf66aca810d17ac432c21a016a1
!! source digest: sha256:f53574252f22b82e46f2bd0b62383509e616a3ad9353583b41c11cef519546fe
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
Expand Down Expand Up @@ -128,6 +128,9 @@ Contributors
* Víctor Martínez
* Iván Antón <ozono@ozonomultimedia.com>
* Eric Antones <eantones@nuobit.com>
* `Dixmit <https://www.dixmit.com>`_:

* Enric Tobella

Maintainers
~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions contract/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
47 changes: 43 additions & 4 deletions contract/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,33 @@
res = super(ContractContract, self).write(vals)
return res

def generate_invoices_manually(self, date=None):
if date is None:
date = fields.Date.today()

Check warning on line 172 in contract/models/contract.py

View check run for this annotation

Codecov / codecov/patch

contract/models/contract.py#L172

Added line #L172 was not covered by tests

while (
self.recurring_next_date
and self.recurring_next_date <= date
and (not self.date_end or self.recurring_next_date <= self.date_end)
):
result = self.with_company(self.company_id.id)._cron_recurring_create(
self.recurring_next_date,
create_type=self.generation_type,
domain=[("id", "=", self.id)],
)
for record_list in result:
for record in record_list:
self.message_post(
body=_(
"Contract manually generated: "
'<a href="#" data-oe-model="%s" data-oe-id="%s">'
"%s"
"</a>"
)
% (record._name, record.id, record.display_name)
)
return True

@api.model
def _set_start_contract_modification(self):
subtype_id = self.env.ref("contract.mail_message_subtype_contract_modification")
Expand Down Expand Up @@ -574,6 +601,10 @@
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(
Expand Down Expand Up @@ -633,17 +664,24 @@
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,
Expand All @@ -652,14 +690,15 @@
)
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):
Expand Down
3 changes: 3 additions & 0 deletions contract/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
* Víctor Martínez
* Iván Antón <ozono@ozonomultimedia.com>
* Eric Antones <eantones@nuobit.com>
* `Dixmit <https://www.dixmit.com>`_:

* Enric Tobella
1 change: 1 addition & 0 deletions contract/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion contract/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Recurring - Contracts Management</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:124a989ae63b390105b95256e33dd7e90ea48cf66aca810d17ac432c21a016a1
!! source digest: sha256:f53574252f22b82e46f2bd0b62383509e616a3ad9353583b41c11cef519546fe
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/contract/tree/14.0/contract"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/contract-14-0/contract-14-0-contract"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/contract&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module enables contracts management with recurring
Expand Down Expand Up @@ -486,6 +487,13 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
</li>
<li><p class="first">Eric Antones &lt;<a class="reference external" href="mailto:eantones&#64;nuobit.com">eantones&#64;nuobit.com</a>&gt;</p>
</li>
<li><p class="first"><a class="reference external" href="https://www.dixmit.com">Dixmit</a>:</p>
<blockquote>
<ul class="simple">
<li>Enric Tobella</li>
</ul>
</blockquote>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Loading
Loading