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

[FEAT] mrp_stock_analytic: add analytic to new raw lines #687

Open
wants to merge 1 commit into
base: 17.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
1 change: 1 addition & 0 deletions mrp_stock_analytic/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import mrp_production
from . import stock_move
24 changes: 24 additions & 0 deletions mrp_stock_analytic/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from odoo import api, models


class StockMove(models.Model):
_inherit = "stock.move"

@api.model_create_multi
def create(self, vals_list):
"""
Extend to copy the analytic distribution of the manufacturing order
if a move is added as a raw material move to it.
"""
for vals in vals_list:
if "analytic_distribution" in vals:
continue
raw_production = (
self.env["mrp.production"]
.browse(vals.get("raw_material_production_id"))
.exists()
)
if not raw_production.analytic_distribution:
continue
vals["analytic_distribution"] = raw_production.analytic_distribution
return super().create(vals_list)
35 changes: 35 additions & 0 deletions mrp_stock_analytic/tests/test_mrp_stock_analytic.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,38 @@ def test_analytic_propagation_backorder(self):
backorder.move_raw_ids.analytic_distribution,
backorder.analytic_distribution,
)

def _check_analytic_when_adding_new_line(self):
self.production.analytic_distribution = self.analytic_distribution
self.product_C = self.env["product.product"].create(
{
"name": "Product C",
"type": "product",
"categ_id": self.product_categ.id,
"standard_price": 50.0,
}
)
self.assertGreater(len(self.production.move_raw_ids), 0)
edit_production = Form(self.production)
with edit_production.move_raw_ids.new() as new_raw:
new_raw.product_id = self.product_C
production = edit_production.save()
for raw_line in production.move_raw_ids:
with self.subTest(
raw_move=raw_line.display_name,
raw_product=raw_line.product_id.display_name,
):
self.assertEqual(
raw_line.analytic_distribution,
self.analytic_distribution,
msg="When a new raw line is added to a draft production, "
"it should get the analytic distribution of the "
"production",
)

def test_analytic_added_to_new_lines_on_draft(self):
self._check_analytic_when_adding_new_line()

def test_analytic_added_to_new_lines_on_confirmed(self):
self.production.action_confirm()
self._check_analytic_when_adding_new_line()
Loading