Skip to content

Commit

Permalink
IMP] stock_analytic: make analytic distribution consistent between mo…
Browse files Browse the repository at this point in the history
…ve and move line
  • Loading branch information
AungKoKoLin1997 committed Jul 8, 2024
1 parent 125391f commit f7e9deb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit f7e9deb

Please sign in to comment.