forked from OCA/account-analytic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] mrp_stock_analytic: add analytic to new raw lines
Also add analytic distribution when manually adding raw lines to an MO with an analytic distribution set.
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import mrp_production | ||
from . import stock_move |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters