Skip to content

Commit

Permalink
[IMP] mrp_production_estimated_cost: Adaptation to OCA
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobaeza committed Dec 10, 2015
1 parent d8078c7 commit dca2533
Show file tree
Hide file tree
Showing 35 changed files with 675 additions and 691 deletions.
96 changes: 96 additions & 0 deletions mrp_production_estimated_cost/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=======================================
Estimated costs in manufacturing orders
=======================================

Thanks to this module, you can estimate the cost of your manufacturing orders
order, split as followed:

* Raw Material cost: an analytic line is generated for each material to
be consumed in the order with the product cost.
* Operators time: one line will be generated for the time recorded by the
operators on each operation, so that the number of lines will be equal to
the number of operators in the operation.
* Machine time: one analytic line for each operation will be created in the
associated routing, taking the hourly cost or if missing, the cost per cycle.

This module also allows to create a virtual manufacturing order for estimating
costs of a manufactured product.

Installation
============

This module depends on the module *product_variant_cost_price*, that is
available in:

https://github.com/OCA/product-variant

Usage
=====

When the manufacturing order is confirmed, analytic lines
are automatically generated in order to estimate the costs of the production

A new menu is available "Virtual Manufacturing Orders for cost estimation"
where the user can managed virtual MO:

* When a new MO is created and the new field "active" is false, the MO will be
considered virtual. It is only used for cost estimation and can not be
confirmed.
* To estimate the cost of the MO, the user has to press the button "Compute
data" in the tab "Work Orders".
* These virtual MO have a separate sequence number.
* The user can create a virtual MO directly from the product form.


.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/129/8.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/manufacture/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed `feedback
<https://github.com/OCA/
manufacture/issues/new?body=module:%20
mrp_production_estimated_cost%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Credits
=======

Contributors
------------

* Alfredo de la Fuente <alfredodelafuente@avanzosc.es>
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Ana Juaristi <ajuaristio@gmail.com>
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
* Ainara Galdona <agaldona@avanzosc.es>

Images
------

* Original Odoo MRP icon
* Thanks to https://openclipart.org/detail/120511/budget

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
7 changes: 7 additions & 0 deletions mrp_production_estimated_cost/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# (c) 2014-2015 Avanzosc
# (c) 2014-2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import models
from . import wizard
37 changes: 37 additions & 0 deletions mrp_production_estimated_cost/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# (c) 2014-2015 Avanzosc
# (c) 2014-2015 Pedro M. Baeza
# (c) 2015 Antiun Ingeniería
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
"name": "Estimated costs in manufacturing orders",
"version": "8.0.1.0.0",
"category": "Manufacturing",
"author": "OdooMRP team, "
"AvanzOSC, "
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
"Antiun Ingenería S.L.,"
"Odoo Community Association (OCA)",
"website": "http://www.odoomrp.com",
"contributors": [
"Alfredo de la Fuente <alfredodelafuente@avanzosc.es>",
"Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>",
"Ana Juaristi <ajuaristio@gmail.com>",
"Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>",
],
"depends": [
"mrp_project",
"product_variant_cost_price",
],
"data": [
"data/analytic_journal_data.xml",
"data/fictitious_mrp_production_sequence.xml",
"wizard/wiz_create_fictitious_of_view.xml",
"views/account_analytic_line_view.xml",
"views/mrp_production_view.xml",
"views/product_view.xml",
],
"installable": True,
"license": "AGPL-3",
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ msgstr ""
"Language: es\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#. module: mrp_production_project_estimated_cost
#: code:addons/mrp_production_project_estimated_cost/models/mrp_production.py:207
#, python-format
msgid "%s-%s"
msgstr "%s-%s"

#. module: mrp_production_project_estimated_cost
#: code:addons/mrp_production_project_estimated_cost/models/mrp_production.py:240
#, python-format
Expand All @@ -35,12 +29,6 @@ msgstr "%s-%s Post-operación"
msgid "%s-%s Pre-operation"
msgstr "%s-%s Pre-operación"

#. module: mrp_production_project_estimated_cost
#: code:addons/mrp_production_project_estimated_cost/models/mrp_production.py:292
#, python-format
msgid "%s-%s-%s"
msgstr "%s-%s-%s"

#. module: mrp_production_project_estimated_cost
#: code:addons/mrp_production_project_estimated_cost/models/mrp_production.py:256
#, python-format
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions mrp_production_estimated_cost/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
# (c) 2014-2015 Avanzosc
# (c) 2014-2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import account_analytic_line
from . import mrp_production
from . import product
16 changes: 16 additions & 0 deletions mrp_production_estimated_cost/models/account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# (c) 2014-2015 Avanzosc
# (c) 2014-2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, fields
import openerp.addons.decimal_precision as dp


class AccountAnalyticLine(models.Model):
_inherit = 'account.analytic.line'

estim_std_cost = fields.Float(string='Estimated Standard Cost',
digits=dp.get_precision('Product Price'))
estim_avg_cost = fields.Float(string='Estimated Average Cost',
digits=dp.get_precision('Product Price'))
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
##############################################################################
from openerp import models, fields, api, exceptions, _
# -*- coding: utf-8 -*-
# (c) 2014-2015 Avanzosc
# (c) 2014-2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, exceptions, fields, models, _


class MrpProduction(models.Model):
Expand All @@ -24,46 +12,44 @@ class MrpProduction(models.Model):
@api.one
@api.depends('analytic_line_ids', 'analytic_line_ids.estim_std_cost',
'product_qty')
def get_unit_std_cost(self):
self.std_cost = -(sum([line.estim_std_cost for line in
self.analytic_line_ids]))
def _compute_unit_std_cost(self):
self.std_cost = -sum(self.analytic_line_ids.mapped('estim_std_cost'))
self.unit_std_cost = self.std_cost / self.product_qty

@api.one
@api.depends('analytic_line_ids', 'analytic_line_ids.estim_avg_cost',
'product_qty')
def get_unit_avg_cost(self):
self.avg_cost = -(sum([line.estim_avg_cost for line in
self.analytic_line_ids]))
def _compute_unit_avg_cost(self):
self.avg_cost = -sum(self.analytic_line_ids.mapped('estim_avg_cost'))
self.unit_avg_cost = self.avg_cost / self.product_qty

@api.one
def _count_created_estimated_cost(self):
analytic_line_obj = self.env['account.analytic.line']
cond = [('mrp_production_id', '=', self.id),
('task_id', '=', False)]
analytic_lines = analytic_line_obj.search(cond)
self.created_estimated_cost = len(analytic_lines)
self.created_estimated_cost = len(analytic_line_obj.search(cond))

active = fields.Boolean(
'Active', default=lambda self: self.env.context.get('default_active',
True))
active = fields.Boolean(string='Active', default=True)
name = fields.Char(default="/")
created_estimated_cost = fields.Integer(
compute="_count_created_estimated_cost", string="Estimated Costs")
std_cost = fields.Float(string="Estimated Standard Cost",
compute="get_unit_std_cost", store=True)
avg_cost = fields.Float(string="Estimated Average Cost",
compute="get_unit_avg_cost", store=True)
unit_std_cost = fields.Float(string="Estimated Standard Unit Cost",
compute="get_unit_std_cost", store=True)
std_cost = fields.Float(
string="Estimated Standard Cost", compute="_compute_unit_std_cost",
store=True)
avg_cost = fields.Float(
string="Estimated Average Cost", compute="_compute_unit_avg_cost",
store=True)
unit_std_cost = fields.Float(
string="Estimated Standard Unit Cost",
compute="_compute_unit_std_cost", store=True)
unit_avg_cost = fields.Float(string="Estimated Average Unit Cost",
compute="get_unit_avg_cost", store=True)
compute="_compute_unit_avg_cost", store=True)
product_manual_cost = fields.Float(
string="Product Manual Cost",
related="product_id.manual_standard_cost")
product_cost = fields.Float(
string="Product Cost", related="product_id.cost_price")
string="Product Cost", related="product_id.standard_price")
analytic_line_ids = fields.One2many(
comodel_name="account.analytic.line", inverse_name="mrp_production_id",
string="Cost Lines")
Expand All @@ -79,19 +65,6 @@ def create(self, values):
values['name'] = sequence_obj.get('fictitious.mrp.production')
return super(MrpProduction, self).create(values)

@api.multi
def unlink(self):
analytic_line_obj = self.env['account.analytic.line']
for production in self:
cond = [('mrp_production_id', '=', production.id)]
analytic_line_obj.search(cond).unlink()
if production.project_id.automatic_creation:
analytic_lines = analytic_line_obj.search(
[('account_id', '=', production.analytic_account_id.id)])
if not analytic_lines:
production.analytic_account_id.unlink()
return super(MrpProduction, self).unlink()

@api.multi
def action_confirm(self):
res = super(MrpProduction, self).action_confirm()
Expand Down Expand Up @@ -173,7 +146,7 @@ def _prepare_estimated_cost_analytic_line(
'general_account_id': general_account.id,
'estim_std_cost': -qty * (std_cost or
product.manual_standard_cost),
'estim_avg_cost': -qty * (avg_cost or product.cost_price),
'estim_avg_cost': -qty * (avg_cost or product.standard_price),
}

@api.model
Expand All @@ -182,7 +155,7 @@ def _create_material_estimated_cost(self, prod, product_line):
raise exceptions.Warning(
_("One consume line has no product assigned."))
journal = self.env.ref('mrp.analytic_journal_materials', False)
name = _('%s-%s' % (prod.name, product_line.work_order.name or ''))
name = '%s-%s' % (prod.name, product_line.work_order.name or '')
product = product_line.product_id
qty = product_line.product_qty
vals = self._prepare_estimated_cost_analytic_line(
Expand Down Expand Up @@ -267,7 +240,7 @@ def _create_operators_estimated_cost(self, prod, wc, workorder):
_("There is at least this workcenter without "
"product: %s") % workorder.workcenter_id.name)
journal = self.env.ref('mrp.analytic_journal_operators', False)
name = (_('%s-%s-%s') %
name = ('%s-%s-%s' %
(prod.name, workorder.routing_wc_line.operation.code,
product.name))
cost = wc.op_avg_cost
Expand Down Expand Up @@ -302,10 +275,10 @@ def calculate_production_estimated_cost(self):

@api.multi
def load_product_std_price(self):
for record in self:
product = record.product_id
if record.unit_std_cost:
product.manual_standard_cost = record.unit_std_cost
for production in self:
if production.unit_std_cost:
production.product_id.manual_standard_cost = (
production.unit_std_cost)

@api.multi
def _get_min_qty_for_production(self, routing=False):
Expand Down
15 changes: 15 additions & 0 deletions mrp_production_estimated_cost/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# (c) 2014-2015 Avanzosc
# (c) 2014-2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, fields
import openerp.addons.decimal_precision as dp


class ProductTemplate(models.Model):
_inherit = 'product.template'

manual_standard_cost = fields.Float(
string='Manual Standard Cost', digits=dp.get_precision('Product Price')
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dca2533

Please sign in to comment.