Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] stock_analytic: make analytic distribution consistent between move and move line #653

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stock_analytic/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def _prepare_move_line_vals(self, quantity=None, reserved_quant=None):

def _action_done(self, cancel_backorder=False):
for move in self:
move.move_line_ids.analytic_distribution = move.analytic_distribution
# Validate analytic distribution only for outgoing moves.
if move.location_id.usage not in (
"internal",
Expand Down Expand Up @@ -89,3 +90,8 @@ def _prepare_stock_move_vals(self):
if self.analytic_distribution:
res.update({"analytic_distribution": self.analytic_distribution})
return res

def write(self, vals):
if "analytic_distribution" in vals:
self.move_id.analytic_distribution = vals["analytic_distribution"]
return super().write(vals)
9 changes: 9 additions & 0 deletions stock_analytic/tests/test_stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ def _check_no_analytic_account(self, picking):
line_count = self.env["account.move.line"].search_count(criteria2)
self.assertEqual(line_count, 0)

def _check_analytic_consistency(self, picking):
for move_line in picking.move_line_ids:
self.assertEqual(
move_line.analytic_distribution, move_line.move_id.analytic_distribution
)

def test_outgoing_picking_with_analytic(self):
picking = self._create_picking(
self.location,
Expand All @@ -170,6 +176,7 @@ def test_outgoing_picking_with_analytic(self):
self._picking_done_no_error(picking)
self._check_account_move_no_error(picking)
self._check_analytic_account_no_error(picking)
self._check_analytic_consistency(picking)

def test_outgoing_picking_without_analytic_optional(self):
picking = self._create_picking(
Expand All @@ -182,6 +189,7 @@ def test_outgoing_picking_without_analytic_optional(self):
self._picking_done_no_error(picking)
self._check_account_move_no_error(picking)
self._check_no_analytic_account(picking)
self._check_analytic_consistency(picking)

def test_outgoing_picking_without_analytic_mandatory(self):
self.analytic_applicability.write({"applicability": "mandatory"})
Expand All @@ -207,6 +215,7 @@ def test_incoming_picking_with_analytic(self):
self._picking_done_no_error(picking)
self._check_account_move_no_error(picking)
self._check_analytic_account_no_error(picking)
self._check_analytic_consistency(picking)

def test_picking_add_extra_move_line(self):
picking = self._create_picking(
Expand Down
Loading