From 833b08dc233a25764a7ffb719fbc3f6fa64de128 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 24 Apr 2018 13:22:37 +0200 Subject: [PATCH] [IMP] contract_variable_quantity: Recompute price when changing qty If you have contract lines with automatic price and your pricelist contains different prices per quantity, the price is not changed when computing quantity. This PR fixes this. --- contract/__manifest__.py | 4 ++-- contract/models/account_analytic_invoice_line.py | 6 ++++-- contract_variable_quantity/__manifest__.py | 4 ++-- contract_variable_quantity/models/contract.py | 4 ++++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/contract/__manifest__.py b/contract/__manifest__.py index b5343ee7..94cbb977 100644 --- a/contract/__manifest__.py +++ b/contract/__manifest__.py @@ -1,5 +1,5 @@ # Copyright 2004-2010 OpenERP SA -# Copyright 2014-2017 Tecnativa - Pedro M. Baeza +# Copyright 2014-2018 Tecnativa - Pedro M. Baeza # Copyright 2015 Domatix # Copyright 2016-2018 Tecnativa - Carlos Dauden # Copyright 2017 Tecnativa - Vicent Cubells @@ -8,7 +8,7 @@ { 'name': 'Contracts Management - Recurring', - 'version': '11.0.2.0.1', + 'version': '11.0.2.0.2', 'category': 'Contract Management', 'license': 'AGPL-3', 'author': "OpenERP SA, " diff --git a/contract/models/account_analytic_invoice_line.py b/contract/models/account_analytic_invoice_line.py index 75fd22df..8f547aaf 100644 --- a/contract/models/account_analytic_invoice_line.py +++ b/contract/models/account_analytic_invoice_line.py @@ -3,7 +3,7 @@ # Copyright 2014 Angel Moya # Copyright 2016 Carlos Dauden # Copyright 2016-2017 LasLabs Inc. -# Copyright 2015-2017 Tecnativa - Pedro M. Baeza +# Copyright 2015-2018 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from dateutil.relativedelta import relativedelta @@ -98,7 +98,9 @@ class AccountAnalyticInvoiceLine(models.Model): for line in self: if line.automatic_price: product = line.product_id.with_context( - quantity=line.quantity, + quantity=line.env.context.get( + 'contract_line_qty', line.quantity, + ), pricelist=line.analytic_account_id.pricelist_id.id, partner=line.analytic_account_id.partner_id.id, date=line.env.context.get('old_date', fields.Date.today()), diff --git a/contract_variable_quantity/__manifest__.py b/contract_variable_quantity/__manifest__.py index de10a337..325b64a4 100644 --- a/contract_variable_quantity/__manifest__.py +++ b/contract_variable_quantity/__manifest__.py @@ -1,10 +1,10 @@ -# Copyright 2016 Tecnativa - Pedro M. Baeza +# Copyright 2016-2018 Tecnativa - Pedro M. Baeza # Copyright 2018 Tecnativa - Carlos Dauden # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Variable quantity in contract recurrent invoicing', - 'version': '11.0.1.2.0', + 'version': '11.0.1.2.1', 'category': 'Contract Management', 'license': 'AGPL-3', 'author': "Tecnativa," diff --git a/contract_variable_quantity/models/contract.py b/contract_variable_quantity/models/contract.py index d4de2a6c..1d25df93 100644 --- a/contract_variable_quantity/models/contract.py +++ b/contract_variable_quantity/models/contract.py @@ -38,6 +38,10 @@ class AccountAnalyticAccount(models.Model): vals = {} else: vals['quantity'] = qty + # Re-evaluate price with this new quantity + vals['price_unit'] = line.with_context( + contract_line_qty=qty, + ).price_unit return vals