From 0f1ebf585d09843a0b56a7e76065115d93ab1246 Mon Sep 17 00:00:00 2001 From: Damien Crier Date: Mon, 19 Feb 2024 17:02:59 +0100 Subject: [PATCH] [IMP] contract: Set a function for wizard functionality --- contract/README.rst | 5 ++- contract/models/contract.py | 27 ++++++++++++++++ contract/static/description/index.html | 10 +++++- .../contract_manually_single_invoice.py | 32 ++----------------- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/contract/README.rst b/contract/README.rst index 668cf7efd1..00a8ec1ebb 100644 --- a/contract/README.rst +++ b/contract/README.rst @@ -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 @@ -128,6 +128,9 @@ Contributors * Víctor Martínez * Iván Antón * Eric Antones +* `Dixmit `_: + + * Enric Tobella Maintainers ~~~~~~~~~~~ diff --git a/contract/models/contract.py b/contract/models/contract.py index 2c2fd85af8..cacb5bb7f7 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -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() + + 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: " + '' + "%s" + "" + ) + % (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") diff --git a/contract/static/description/index.html b/contract/static/description/index.html index 051f39ee86..c164dc527b 100644 --- a/contract/static/description/index.html +++ b/contract/static/description/index.html @@ -1,3 +1,4 @@ + @@ -366,7 +367,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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Production/Stable License: AGPL-3 OCA/contract Translate me on Weblate Try me on Runboat

This module enables contracts management with recurring @@ -486,6 +487,13 @@

Contributors

  • Eric Antones <eantones@nuobit.com>

  • +
  • Dixmit:

    +
    +
      +
    • Enric Tobella
    • +
    +
    +
  • diff --git a/contract/wizards/contract_manually_single_invoice.py b/contract/wizards/contract_manually_single_invoice.py index b6793f9c11..8b3b6d6fec 100644 --- a/contract/wizards/contract_manually_single_invoice.py +++ b/contract/wizards/contract_manually_single_invoice.py @@ -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): @@ -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: " - '' - "%s" - "" - ) - % (record._name, record.id, record.display_name) - ) - return True + return self.contract_id.generate_invoices_manually(date=self.date)