From 95dd2c1f2557a5ba4cea2655156a18f3c12b954f Mon Sep 17 00:00:00 2001 From: Swapnesh Date: Wed, 1 Jan 2020 22:14:20 +0530 Subject: [PATCH] [ADD]Added _recurring_create_invoice --- contract_line_invoice_by_average/__init__.py | 2 +- .../models/__init__.py | 4 ++-- .../models/contract_line.py | 24 ++++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/contract_line_invoice_by_average/__init__.py b/contract_line_invoice_by_average/__init__.py index 7b945476..69f7babd 100644 --- a/contract_line_invoice_by_average/__init__.py +++ b/contract_line_invoice_by_average/__init__.py @@ -1,3 +1,3 @@ - # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import models diff --git a/contract_line_invoice_by_average/models/__init__.py b/contract_line_invoice_by_average/models/__init__.py index ecc2efb3..767c863a 100644 --- a/contract_line_invoice_by_average/models/__init__.py +++ b/contract_line_invoice_by_average/models/__init__.py @@ -1,3 +1,3 @@ - # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from . import contract_line diff --git a/contract_line_invoice_by_average/models/contract_line.py b/contract_line_invoice_by_average/models/contract_line.py index 16a6b032..03d10b47 100644 --- a/contract_line_invoice_by_average/models/contract_line.py +++ b/contract_line_invoice_by_average/models/contract_line.py @@ -1,6 +1,28 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models + + +class ContractContract(models.Model): + _inherit = 'contract.contract' + + @api.multi + def _recurring_create_invoice(self, date_ref=False): + invoices = super()._recurring_create_invoice(date_ref) + for contract_to_invoice in self: + product_avg_qty_dict = {} + for each_contract_line in contract_to_invoice.contract_line_ids.filtered(lambda l: l.products_invoiced_by_avg_ids): + for each_avg_product in each_contract_line.products_invoiced_by_avg_ids: + product_avg_qty_dict.update( + {each_avg_product.id: each_contract_line.quantity}) + for each_invoice in invoices: + for each_inv_line in each_invoice.invoice_line_ids: + if each_inv_line.product_id.id in list(product_avg_qty_dict.keys()): + qty = product_avg_qty_dict.get( + each_inv_line.product_id.id) / each_inv_line.quantity + each_inv_line.quantity = round(qty) + each_inv_line._onchange_product_id_account_invoice_pricelist() + return invoices class ContractLine(models.Model):