From a8076bd513b807b4dc3c91c38c2c444122bb2fcd Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Wed, 19 May 2021 13:19:28 +0000 Subject: [PATCH] [MOV] sale: move/split account files (3) --- addons/sale/models/account_move.py | 21 ++++++++++++++++++++- addons/sale/models/account_move_line.py | 22 ---------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/addons/sale/models/account_move.py b/addons/sale/models/account_move.py index 9ffe13e56d9..e5e9e84379d 100644 --- a/addons/sale/models/account_move.py +++ b/addons/sale/models/account_move.py @@ -2,7 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import api, fields, models, _ - +from odoo.exceptions import UserError class AccountMove(models.Model): _name = 'account.move' @@ -74,6 +74,25 @@ class AccountMove(models.Model): }) return super()._reverse_moves(default_values_list=default_values_list, cancel=cancel) + def action_post(self): + #inherit of the function from account.move to validate a new tax and the priceunit of a downpayment + res = super(AccountMove, self).action_post() + line_ids = self.mapped('line_ids').filtered(lambda line: line.sale_line_ids.is_downpayment) + for line in line_ids: + try: + line.sale_line_ids.tax_id = line.tax_ids + if all(line.tax_ids.mapped('price_include')): + line.sale_line_ids.price_unit = line.price_unit + else: + #To keep positive amount on the sale order and to have the right price for the invoice + #We need the - before our untaxed_amount_to_invoice + line.sale_line_ids.price_unit = -line.sale_line_ids.untaxed_amount_to_invoice + except UserError: + # a UserError here means the SO was locked, which prevents changing the taxes + # just ignore the error - this is a nice to have feature and should not be blocking + pass + return res + def _post(self, soft=True): # OVERRIDE # Auto-reconcile the invoice with payments coming from transactions. diff --git a/addons/sale/models/account_move_line.py b/addons/sale/models/account_move_line.py index caae347ee13..a0565c23326 100644 --- a/addons/sale/models/account_move_line.py +++ b/addons/sale/models/account_move_line.py @@ -6,28 +6,6 @@ from odoo.exceptions import UserError from odoo.tools import float_compare, float_is_zero -class AccountMove(models.Model): - _inherit = 'account.move' - - def action_post(self): - #inherit of the function from account.move to validate a new tax and the priceunit of a downpayment - res = super(AccountMove, self).action_post() - line_ids = self.mapped('line_ids').filtered(lambda line: line.sale_line_ids.is_downpayment) - for line in line_ids: - try: - line.sale_line_ids.tax_id = line.tax_ids - if all(line.tax_ids.mapped('price_include')): - line.sale_line_ids.price_unit = line.price_unit - else: - #To keep positive amount on the sale order and to have the right price for the invoice - #We need the - before our untaxed_amount_to_invoice - line.sale_line_ids.price_unit = -line.sale_line_ids.untaxed_amount_to_invoice - except UserError: - # a UserError here means the SO was locked, which prevents changing the taxes - # just ignore the error - this is a nice to have feature and should not be blocking - pass - return res - class AccountMoveLine(models.Model): _inherit = 'account.move.line'