[IMP] (mrp,stock)_account: using correct account when unbuild a MO
Currently when unbuild a MO, we create journal entries the same as receiving components (add credit to input account) and deliver finished product (add debit to output account). But since the unbuild is just a revesal of the MO, the journal entries should alse be revesals. In this commit, when unbuild a MO, for the journal entry about the component change, we add credit to the output account, and for the journal entry of the finished product change, we add debit to input account make sure the journal entries are also reversals. Task 2312828 PR #58150 closes odoo/odoo#60730 X-original-commit: 83a3230706e1e2f4eaf9718156647821341d192b Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
This commit is contained in:
@@ -3,3 +3,4 @@
|
||||
from . import mrp_workcenter
|
||||
from . import mrp_production
|
||||
from . import product
|
||||
from . import stock_move
|
||||
|
||||
@@ -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)
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user