diff --git a/addons/website_payment/models/__init__.py b/addons/website_payment/models/__init__.py index 0a02268206c..0f8a4704786 100644 --- a/addons/website_payment/models/__init__.py +++ b/addons/website_payment/models/__init__.py @@ -1,3 +1,4 @@ import res_config import payment import website +import sale diff --git a/addons/website_payment/models/payment.py b/addons/website_payment/models/payment.py index 7231bda4147..d79c0f77b5a 100644 --- a/addons/website_payment/models/payment.py +++ b/addons/website_payment/models/payment.py @@ -18,6 +18,8 @@ class PaymentTransaction(models.Model): sale_order_id = fields.Many2one('sale.order', string='Sale Order') def _generate_and_pay_invoice(self, tx, acquirer_name): + tx.sale_order_id._force_lines_to_invoice_policy_order() + created_invoice = tx.sale_order_id.action_invoice_create() created_invoice = self.env['account.invoice'].browse(created_invoice) diff --git a/addons/website_payment/models/sale.py b/addons/website_payment/models/sale.py new file mode 100644 index 00000000000..ffe46c2236d --- /dev/null +++ b/addons/website_payment/models/sale.py @@ -0,0 +1,14 @@ +# coding: utf-8 +# Part of Odoo. See LICENSE file for full copyright and licensing details. +import logging +from odoo import api, fields, models + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + def _force_lines_to_invoice_policy_order(self): + for line in self.order_line: + if self.state in ['sale', 'done']: + line.qty_to_invoice = line.product_uom_qty - line.qty_invoiced + else: + line.qty_to_invoice = 0