diff --git a/stock_account_operating_unit/model/stock_move.py b/stock_account_operating_unit/model/stock_move.py index f52722be15..a6b7d3bb82 100644 --- a/stock_account_operating_unit/model/stock_move.py +++ b/stock_account_operating_unit/model/stock_move.py @@ -3,7 +3,7 @@ # - Jordi Ballester Alomar # © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from openerp import _, api, exceptions, models +from odoo import _, api, exceptions, models class StockMove(models.Model): @@ -17,6 +17,10 @@ def _prepare_account_move_line(self, qty, cost, credit_account_id, if res: debit_line_vals = res[0][2] credit_line_vals = res[1][2] + if len(res) == 3: + price_diff_line = res[2][2] + else: + price_diff_line = {} if ( self.operating_unit_id and self.operating_unit_dest_id and @@ -28,12 +32,23 @@ def _prepare_account_move_line(self, qty, cost, credit_account_id, ' and destination accounts related to different ' 'operating units.') ) + if (not self.operating_unit_dest_id + and not self.operating_unit_id.id): + ou_id = self.picking_id.picking_type_id.warehouse_id.\ + operating_unit_id.id + else: + ou_id = False - debit_line_vals['operating_unit_id'] = ( + debit_line_vals['operating_unit_id'] = ou_id or \ self.operating_unit_dest_id.id or self.operating_unit_id.id - ) - credit_line_vals['operating_unit_id'] = ( + credit_line_vals['operating_unit_id'] = ou_id or \ self.operating_unit_id.id or self.operating_unit_dest_id.id - ) - return [(0, 0, debit_line_vals), (0, 0, credit_line_vals)] + + rslt = [(0, 0, debit_line_vals), (0, 0, credit_line_vals)] + if price_diff_line: + price_diff_line['operating_unit_id'] = ou_id \ + or self.operating_unit_id.id or \ + self.operating_unit_dest_id.id + rslt.extend([(0, 0, price_diff_line)]) + return rslt return res diff --git a/stock_account_operating_unit/model/stock_quant.py b/stock_account_operating_unit/model/stock_quant.py index 5026113852..cd25f5903e 100644 --- a/stock_account_operating_unit/model/stock_quant.py +++ b/stock_account_operating_unit/model/stock_quant.py @@ -3,7 +3,7 @@ # - Jordi Ballester Alomar # © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from openerp import api, models +from odoo import api, models class StockQuant(models.Model): @@ -22,11 +22,10 @@ def _account_entry_move(self, move): if move.product_id.valuation == 'real_time': # Inter-operating unit moves do not accept to # from/to non-internal location - if ( + if (move.location_id.company_id and move.location_id.company_id == move.location_dest_id.company_id and - move.operating_unit_id != move.operating_unit_dest_id - ): + move.operating_unit_id != move.operating_unit_dest_id): src_company_ctx = dict( force_company=move.location_id.company_id.id ) @@ -45,10 +44,11 @@ def _account_entry_move(self, move): move_lines = move._prepare_account_move_line(qty, cost, acc_valuation, acc_valuation) - move_obj.with_context(company_ctx).create({ + val_move = move_obj.with_context(company_ctx).create({ 'journal_id': journal_id, 'line_ids': move_lines, 'company_id': move.company_id.id, 'ref': move.picking_id and move.picking_id.name, }) + val_move.post() return res