diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/stock_account/models/stock_move_line.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/stock_account/models/stock_move_line.py')
| -rw-r--r-- | addons/stock_account/models/stock_move_line.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/addons/stock_account/models/stock_move_line.py b/addons/stock_account/models/stock_move_line.py new file mode 100644 index 00000000..4187f201 --- /dev/null +++ b/addons/stock_account/models/stock_move_line.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models +from odoo.tools import float_is_zero + + +class StockMoveLine(models.Model): + _inherit = 'stock.move.line' + + # ------------------------------------------------------------------------- + # CRUD + # ------------------------------------------------------------------------- + @api.model_create_multi + def create(self, vals_list): + move_lines = super(StockMoveLine, self).create(vals_list) + for move_line in move_lines: + if move_line.state != 'done': + continue + move = move_line.move_id + rounding = move.product_id.uom_id.rounding + diff = move_line.qty_done + if float_is_zero(diff, precision_rounding=rounding): + continue + self._create_correction_svl(move, diff) + return move_lines + + def write(self, vals): + if 'qty_done' in vals: + for move_line in self: + if move_line.state != 'done': + continue + move = move_line.move_id + rounding = move.product_id.uom_id.rounding + diff = vals['qty_done'] - move_line.qty_done + if float_is_zero(diff, precision_rounding=rounding): + continue + self._create_correction_svl(move, diff) + return super(StockMoveLine, self).write(vals) + + # ------------------------------------------------------------------------- + # SVL creation helpers + # ------------------------------------------------------------------------- + @api.model + def _create_correction_svl(self, move, diff): + stock_valuation_layers = self.env['stock.valuation.layer'] + if move._is_in() and diff > 0 or move._is_out() and diff < 0: + move.product_price_update_before_done(forced_qty=diff) + stock_valuation_layers |= move._create_in_svl(forced_quantity=abs(diff)) + if move.product_id.cost_method in ('average', 'fifo'): + move.product_id._run_fifo_vacuum(move.company_id) + elif move._is_in() and diff < 0 or move._is_out() and diff > 0: + stock_valuation_layers |= move._create_out_svl(forced_quantity=abs(diff)) + elif move._is_dropshipped() and diff > 0 or move._is_dropshipped_returned() and diff < 0: + stock_valuation_layers |= move._create_dropshipped_svl(forced_quantity=abs(diff)) + elif move._is_dropshipped() and diff < 0 or move._is_dropshipped_returned() and diff > 0: + stock_valuation_layers |= move._create_dropshipped_returned_svl(forced_quantity=abs(diff)) + + for svl in stock_valuation_layers: + if not svl.product_id.valuation == 'real_time': + continue + svl.stock_move_id._account_entry_move(svl.quantity, svl.description, svl.id, svl.value) |
