mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
Merge pull request #83 from ddico/submit_add_cost_per_cycle
[ADD] mrp_production_real_cost - add cost per cycle
This commit is contained in:
@@ -34,8 +34,27 @@ created when:
|
||||
* Also, together with *project_timesheet* module, users time is also translated
|
||||
to costs in the linked analytic account.
|
||||
|
||||
The sum of all these analytic entries is the real cost.
|
||||
The sum of all these analytic entries is the real cost:
|
||||
|
||||
.. figure:: mrp_production_real_cost/static/description/mrp_real_cost.png
|
||||
:alt: MRP Real Cost Details
|
||||
|
||||
Cost/cycle = all overhead costs associated with running one work centre cycle
|
||||
(where a cycle is the Number of Cycles as calculated in the Work Order).
|
||||
|
||||
Cost/hr = calculated as all overhead costs associated with running the work
|
||||
centre (excluding any costs covered in the cost per cycle) / the number of
|
||||
hours the work centre is operating.
|
||||
|
||||
Pre-operation cost = Time before prod. x cost of the Pre-operation costing
|
||||
product
|
||||
|
||||
Post-operation cost = Time after prod. x cost of the Post-operation costing
|
||||
product
|
||||
|
||||
It’s up to the user to determine overhead costs as accurately as possible
|
||||
and use all, some or none of them in order to reflect their manufacturing
|
||||
process.
|
||||
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"stock_account",
|
||||
],
|
||||
'license': 'AGPL-3',
|
||||
"images": [],
|
||||
"author": "OdooMRP team, "
|
||||
"AvanzOSC, "
|
||||
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
|
||||
|
||||
@@ -55,6 +55,38 @@ class MrpProductionWorkcenterLine(models.Model):
|
||||
analytic_vals['ref'] = workcenter.costs_hour_account_id.name
|
||||
analytic_line_obj.create(analytic_vals)
|
||||
|
||||
@api.multi
|
||||
def _create_analytic_line_cycle(self):
|
||||
self.ensure_one()
|
||||
analytic_line_obj = self.env['account.analytic.line']
|
||||
task_obj = self.env['project.task']
|
||||
if self.workcenter_id.costs_cycle > 0.0:
|
||||
operation_line = self.operation_time_lines[-1]
|
||||
production = self.production_id
|
||||
workcenter = self.workcenter_id
|
||||
product = workcenter.product_id
|
||||
journal_id = workcenter.costs_journal_id or self.env.ref(
|
||||
'mrp.analytic_journal_machines', False)
|
||||
general_acc = workcenter.costs_general_account_id or False
|
||||
name = "-".join([production.name or '',
|
||||
workcenter.code or '',
|
||||
self.routing_wc_line.routing_id.code or '',
|
||||
product.default_code or '',
|
||||
_('CYCLE')])
|
||||
price = -(workcenter.costs_cycle * self.cycle)
|
||||
if price:
|
||||
analytic_vals = production._prepare_real_cost_analytic_line(
|
||||
journal_id, name, production, product,
|
||||
general_account=general_acc, workorder=self,
|
||||
qty=operation_line.uptime, amount=price)
|
||||
task = task_obj.search(
|
||||
[('mrp_production_id', '=', production.id),
|
||||
('workorder', '=', self.id)])
|
||||
analytic_vals['task_id'] = task and task[0].id or False
|
||||
analytic_vals['product_uom_id'] = production.product_uom.id
|
||||
analytic_vals['ref'] = workcenter.costs_cycle_account_id.name
|
||||
analytic_line_obj.create(analytic_vals)
|
||||
|
||||
@api.multi
|
||||
def _create_pre_post_cost_lines(self, cost_type='pre'):
|
||||
self.ensure_one()
|
||||
@@ -108,6 +140,7 @@ class MrpProductionWorkcenterLine(models.Model):
|
||||
|
||||
@api.multi
|
||||
def action_done(self):
|
||||
self._create_analytic_line_cycle()
|
||||
self._create_pre_post_cost_lines(cost_type='post')
|
||||
return super(MrpProductionWorkcenterLine, self).action_done()
|
||||
|
||||
|
||||
BIN
mrp_production_real_cost/static/description/mrp_real_cost.png
Normal file
BIN
mrp_production_real_cost/static/description/mrp_real_cost.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 157 KiB |
@@ -40,8 +40,9 @@ class TestMrpProductionRealCost(common.TransactionCase):
|
||||
self.start_date - timedelta(hours=2))
|
||||
line.signal_workflow('button_done')
|
||||
analytic_lines = self.production.analytic_line_ids.filtered('amount')
|
||||
# This should have the pre- cost, uptime line and post- cost
|
||||
self.assertEqual(len(analytic_lines), 3)
|
||||
# This should have the pre- cost, cycle cost, uptime line and
|
||||
# post- cost
|
||||
self.assertEqual(len(analytic_lines), 4)
|
||||
self.assertNotEqual(analytic_lines[-1].amount, prev_amount)
|
||||
prev_amount = analytic_lines[-1].amount
|
||||
# Change manually an uptime to see if costs change
|
||||
@@ -63,8 +64,10 @@ class TestMrpProductionRealCost(common.TransactionCase):
|
||||
line.operation_time_lines[-1].start_date = self.start_date
|
||||
self.production.action_produce(
|
||||
self.production.id, self.production.product_qty, 'consume_produce')
|
||||
# This should have 2 materials and 2 workorders each with cycle and
|
||||
# uptime cost
|
||||
self.assertEqual(
|
||||
len(self.production.analytic_line_ids.filtered('amount')), 4)
|
||||
len(self.production.analytic_line_ids.filtered('amount')), 6)
|
||||
self.assertNotEqual(
|
||||
initial_price, self.production.product_id.standard_price)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user