From a4d46ec55c09b0d54260dacfe756bbb78b40b44e Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 5 Feb 2020 10:19:48 +0000 Subject: [PATCH] [FIX] account, sale: Default payment term when creating an invoice Steps to reproduce the bug: - Let's consider a partner P without property_payment_term_id - Create a SO for P, confirm it and create an invoice I - In debug mode, on the SO click on the smart button 'invoice' - On I, click on the 'Set Default' in the debug menu - Set a payment term PT as default value (ir.default) for all users - From this view, create a new invoice Bug: The default payment term PT was not set on the new invoice opw:2184367 closes odoo/odoo#44781 X-original-commit: c258b8a0427bd5aface891ed1f4420174f4afde4 Signed-off-by: Nicolas Martinelli (nim) --- addons/account/models/account_move.py | 4 ++-- addons/sale/models/sale.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index e574515ce37..7d1fa221644 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -323,9 +323,9 @@ class AccountMove(models.Model): return {'warning': warning} for line in self.line_ids: line.partner_id = self.partner_id.commercial_partner_id - if self.is_sale_document(include_receipts=True): + if self.is_sale_document(include_receipts=True) and self.partner_id.property_payment_term_id: self.invoice_payment_term_id = self.partner_id.property_payment_term_id - elif self.is_purchase_document(include_receipts=True): + elif self.is_purchase_document(include_receipts=True) and self.partner_id.property_supplier_payment_term_id: self.invoice_payment_term_id = self.partner_id.property_supplier_payment_term_id self._compute_bank_partner_id() diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index cd0049cc23c..a316b9ff4ec 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -565,7 +565,7 @@ class SaleOrder(models.Model): context.update({ 'default_partner_id': self.partner_id.id, 'default_partner_shipping_id': self.partner_shipping_id.id, - 'default_invoice_payment_term_id': self.payment_term_id.id, + 'default_invoice_payment_term_id': self.payment_term_id.id or self.partner_id.property_payment_term_id.id or self.env['ir.default'].sudo().get('account.move', 'invoice_payment_term_id', company_id=self.env.company.id), 'default_invoice_origin': self.mapped('name'), 'default_user_id': self.user_id.id, })