Skip to content

Commit

Permalink
[IMP] contract: Set a function for wizard functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
damdam-s authored and etobella committed Feb 21, 2024
1 parent af58549 commit 441d767
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 32 deletions.
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
27 changes: 27 additions & 0 deletions contract/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,33 @@ def write(self, vals):
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
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
32 changes: 2 additions & 30 deletions contract/wizards/contract_manually_single_invoice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2023 Dixmit
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, fields, models
from odoo import fields, models


class ContractManuallySingleInvoice(models.TransientModel):
Expand All @@ -12,32 +12,4 @@ class ContractManuallySingleInvoice(models.TransientModel):
date = fields.Date(required=True, default=lambda r: fields.Date.today())

def create_invoice(self):
while (
self.contract_id.recurring_next_date
and self.contract_id.recurring_next_date <= self.date
and (
not self.contract_id.date_end
or self.contract_id.recurring_next_date <= self.contract_id.date_end
)
):
result = (
self.env["contract.contract"]
.with_company(self.contract_id.company_id.id)
._cron_recurring_create(
self.contract_id.recurring_next_date,
create_type=self.contract_id.generation_type,
domain=[("id", "=", self.contract_id.id)],
)
)
for list in result:
for record in list:
self.contract_id.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
return self.contract_id.generate_invoices_manually(date=self.date)

0 comments on commit 441d767

Please sign in to comment.