From 65b1220008992df62cb794b4c1c3adb2d9df590a Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Tue, 31 May 2016 09:56:55 +0200 Subject: [PATCH] [IMP] website_payment: when invoicing always ignore invoice policy Sale orders created through the website that have to be automatically invoiced should ignore the delivery invoicing policy. Otherwise you can end up with either an invoice not being generated at all. This means the user has to manually generate and add the payment to it. Even worse is if only some purchased products have invoice policy delivery. In this case a partial invoice would be generated to which the payment would be added, leading to a mismatch between invoice total and payment amount. --- addons/website_payment/models/__init__.py | 1 + addons/website_payment/models/payment.py | 2 ++ addons/website_payment/models/sale.py | 14 ++++++++++++++ 3 files changed, 17 insertions(+) create mode 100644 addons/website_payment/models/sale.py 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