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

[ADD] Added WIP modules from MIT + Adjusted according to Cab #40

Merged
merged 2 commits into from
Jan 24, 2025
Merged
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
9 changes: 5 additions & 4 deletions mrp_account_analytic/models/mrp_workorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ def generate_mrp_work_analytic_line(self):

@api.model_create_multi
def create(self, vals_list):
timelog = super().create(vals_list)
timelog_with_date_end = timelog.filtered("date_end")
timelog_with_date_end.generate_mrp_work_analytic_line()
return timelog
timelogs = super().create(vals_list)
for i, timelog in enumerate(timelogs):
if vals_list[i].get("date_end"):
timelog.generate_mrp_work_analytic_line()
return timelogs

def write(self, vals):
res = super().write(vals)
Expand Down
23 changes: 13 additions & 10 deletions mrp_account_analytic/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,27 @@ def write(self, vals):
@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
sm_has_qty_done = res.filtered("quantity_done")
sm_has_qty_done.generate_mrp_raw_analytic_line()
for i, move in enumerate(res):
if vals_list[i].get("quantity_done"):
move.generate_mrp_raw_analytic_line()
return res


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

def write(self, vals):
qty_done = vals.get("qty_done")
res = super().write(vals)
if qty_done:
self.mapped("move_id").generate_mrp_raw_analytic_line()
return res
# def write(self, vals):
# qty_done = vals.get("qty_done")
# for rec in self:
# if qty_done:
# rec.mapped("move_id").generate_mrp_raw_analytic_line()
# res = super().write(vals)
# return res

@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
sml_has_qty_done = res.filtered("qty_done")
sml_has_qty_done.mapped("move_id").generate_mrp_raw_analytic_line()
for i, line in enumerate(res):
if vals_list[i].get("qty_done"):
line.mapped("move_id").generate_mrp_raw_analytic_line()
return res
1 change: 1 addition & 0 deletions mrp_account_analytic_wip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
# from . import wizards
2 changes: 2 additions & 0 deletions mrp_account_analytic_wip/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"depends": [
"mrp_account_analytic",
"account_analytic_wip",
# TODO: abusive dependency, modularity should be improved
# "stock_inventory_revaluation_mrp",
],
"data": [
"views/mrp_production_views.xml",
Expand Down
4 changes: 2 additions & 2 deletions mrp_account_analytic_wip/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from . import account_analytic_line
from . import account_analytic_tracking
from . import mrp_bom
#from . import mrp_bom
from . import mrp_production
from . import mrp_workcenter
from . import mrp_workorder
from . import stock_move
from . import stock_location
from . import product
#from . import product
8 changes: 7 additions & 1 deletion mrp_account_analytic_wip/models/account_analytic_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,26 @@ def _get_unit_cost(self):
"product_id.standard_price",
"actual_stock_move_ids",
"actual_workorder_ids",
"stock_move_id"
)
def _compute_actual_amount(self):
currency = self.env.company.currency_id
for item in self:
if item.state == "cancel" or item.child_ids:
item.actual_amount = 0.0
elif item.state == "done":
elif item.state == 'done':
return
elif not item.production_id:
super(AnalyticTrackingItem, item)._compute_actual_amount()
else:
# Specific Actuals calculation on MOs, using current cost
# instead of the historical cost stored in Anaytic Items
unit_cost = item.product_id.standard_price
if item.stock_move_id.product_id.tracking=='serial' and \
item.stock_move_id.raw_material_production_id:
# Calculate actual cost based on real price of SN instead of standard.
unit_cost = sum(item.stock_move_id.mapped("move_line_ids").mapped("lot_id").mapped("real_price"))
workcenter = item.workcenter_id or item.workorder_id.workcenter_id
items = item | item.parent_id
raw_qty = sum(items.actual_stock_move_ids.mapped("quantity_done"))
ops_qty = sum(items.actual_workorder_ids.mapped("duration")) / 60
Expand Down
15 changes: 7 additions & 8 deletions mrp_account_analytic_wip/models/mrp_bom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (C) 2023 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

## this can be deleted. not needed with FIFO

from odoo import api, fields, models

Expand All @@ -14,8 +15,8 @@ def _prepare_raw_tracking_item_values(self, product_uom_qty):
self.ensure_one()
product = self.product_tmpl_id or self.product_id
bom_qty = self.product_uom_id._compute_quantity(
self.product_qty, product.uom_id
)
self.product_qty, product.uom_id
)
factor = product_uom_qty / bom_qty
# Each distinct Product will be one Tracking Item
# So multiple BOM lines for the same Product need to be aggregated
Expand All @@ -25,8 +26,7 @@ def _prepare_raw_tracking_item_values(self, product_uom_qty):
"product_id": product.id,
"planned_qty": sum(
x.product_qty for x in lines if x.product_id == product
)
* factor,
) * factor,
}
for product in lines.product_id
]
Expand All @@ -37,8 +37,8 @@ def _prepare_ops_tracking_item_values(self, product_uom_qty):
# So multiple BOM lines for the same Work Center need to be aggregated
product = self.product_tmpl_id or self.product_id
bom_qty = self.product_uom_id._compute_quantity(
self.product_qty, product.uom_id
)
self.product_qty, product.uom_id
)
factor = product_uom_qty / bom_qty
lines = self.operation_ids
return [
Expand All @@ -47,8 +47,7 @@ def _prepare_ops_tracking_item_values(self, product_uom_qty):
"workcenter_id": workcenter.id,
"planned_qty": sum(
x.time_cycle for x in lines if x.workcenter_id == workcenter
)
* factor
) * factor
/ 60,
}
for workcenter in lines.workcenter_id
Expand Down
Loading