diff --git a/contract.py b/contract.py index 8fc5657..68317c2 100644 --- a/contract.py +++ b/contract.py @@ -871,12 +871,6 @@ class ContractConsumption(ModelSQL, ModelView): product=invoice_line.product.rec_name)) start_date, end_date = self._get_start_end_date() - invoice_line.description = '[%(start)s - %(end)s] %(name)s' % { - 'start': start_date, - 'end': end_date, - 'name': self.contract_line.description, - } - invoice_line.quantity = 1 if self.end_period_date == self.init_period_date: rate = Decimal(0) else: @@ -889,6 +883,24 @@ class ContractConsumption(ModelSQL, ModelView): (self.end_period_date + datetime.timedelta(days=1) - self.init_period_date).total_seconds()) + invoice_line.quantity = 1 + invoice_line.on_change_product() + + # set unit_price from service in case on_change_product calculate price + # from the product or from party price list + unit_price = round_price(self.contract_line.unit_price * rate) + if hasattr(InvoiceLine, 'gross_unit_price'): + invoice_line.gross_unit_price = unit_price + invoice_line.update_prices() + else: + invoice_line.unit_price = unit_price + + invoice_line.description = '[%(start)s - %(end)s] %(name)s' % { + 'start': start_date, + 'end': end_date, + 'name': self.contract_line.description, + } + if invoice_line.product: if not invoice_line.account: raise UserError(gettext( @@ -906,8 +918,6 @@ class ContractConsumption(ModelSQL, ModelView): 'contract.missing_account_revenue_property', contract_line=self.contract_line.rec_name)) - invoice_line.unit_price = round_price(self.contract_line.unit_price * rate) - if AnalyticAccountEntry and hasattr(InvoiceLine, 'analytic_accounts'): invoice_line.analytic_accounts = AnalyticAccountEntry.copy( self.contract_line.analytic_accounts, default={ diff --git a/tryton.cfg b/tryton.cfg index 150781f..b7f8dc4 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -11,6 +11,7 @@ depends: extras_depends: analytic_account analytic_invoice + account_invoice_discount xml: contract.xml analytic_contract.xml