diff --git a/addons/mrp_account/models/__init__.py b/addons/mrp_account/models/__init__.py index 348a288235b..520901ce500 100644 --- a/addons/mrp_account/models/__init__.py +++ b/addons/mrp_account/models/__init__.py @@ -3,3 +3,4 @@ from . import mrp_workcenter from . import mrp_production from . import product +from . import stock_move diff --git a/addons/mrp_account/models/stock_move.py b/addons/mrp_account/models/stock_move.py new file mode 100644 index 00000000000..f5c7f9be12b --- /dev/null +++ b/addons/mrp_account/models/stock_move.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo import api, fields, models, _ + + +class StockMove(models.Model): + _inherit = "stock.move" + + def _is_returned(self, valued_type): + if self.unbuild_id and self.unbuild_id.mo_id: # unbuilding a MO + return True + return super()._is_returned(valued_type) diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py index 6f9c34c49b5..cb11e71fd57 100644 --- a/addons/stock_account/models/stock_move.py +++ b/addons/stock_account/models/stock_move.py @@ -473,11 +473,11 @@ class StockMove(models.Model): company_from = self._is_out() and self.mapped('move_line_ids.location_id.company_id') or False company_to = self._is_in() and self.mapped('move_line_ids.location_dest_id.company_id') or False + journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation() # Create Journal Entry for products arriving in the company; in case of routes making the link between several # warehouse of the same company, the transit location belongs to this company, so we don't need to create accounting entries if self._is_in(): - journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation() - if location_from and location_from.usage == 'customer': # goods returned from customer + if self._is_returned(valued_type='in'): self.with_company(company_to)._create_account_move_line(acc_dest, acc_valuation, journal_id, qty, description, svl_id, cost) else: self.with_company(company_to)._create_account_move_line(acc_src, acc_valuation, journal_id, qty, description, svl_id, cost) @@ -485,15 +485,13 @@ class StockMove(models.Model): # Create Journal Entry for products leaving the company if self._is_out(): cost = -1 * cost - journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation() - if location_to and location_to.usage == 'supplier': # goods returned to supplier + if self._is_returned(valued_type='out'): self.with_company(company_from)._create_account_move_line(acc_valuation, acc_src, journal_id, qty, description, svl_id, cost) else: self.with_company(company_from)._create_account_move_line(acc_valuation, acc_dest, journal_id, qty, description, svl_id, cost) if self.company_id.anglo_saxon_accounting: # Creates an account entry from stock_input to stock_output on a dropship move. https://github.com/odoo/odoo/issues/12687 - journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation() if self._is_dropshipped(): if cost > 0: self.with_company(self.company_id)._create_account_move_line(acc_src, acc_valuation, journal_id, qty, description, svl_id, cost) @@ -516,3 +514,10 @@ class StockMove(models.Model): to the way they mix stock moves with invoices. """ return self.env['account.move'] + + def _is_returned(self, valued_type): + self.ensure_one() + if valued_type == 'in': + return self.location_id and self.location_id.usage == 'customer' # goods returned from customer + if valued_type == 'out': + return self.location_dest_id and self.location_dest_id.usage == 'supplier' # goods returned to supplier