Skip to content

Commit

Permalink
Merge 3bdca46 into 1e6e0d7
Browse files Browse the repository at this point in the history
  • Loading branch information
Esther Martín Menéndez committed Jun 8, 2016
2 parents 1e6e0d7 + 3bdca46 commit 26537e6
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 0 deletions.
20 changes: 20 additions & 0 deletions product_cost_utilities/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. 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

======================
Product Cost Utilities
======================

* This module shows adds two new fields on products: "average margin" and
"manual margin".


Credits
=======


Contributors
------------
* Esther Martín <esthermartin@avanzosc.es>
* Ana Juaristi <ajuaristio@gmail.com>
5 changes: 5 additions & 0 deletions product_cost_utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 Esther Martín - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import models
25 changes: 25 additions & 0 deletions product_cost_utilities/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © 2015 Esther Martín - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
"name": "Product Cost Utilities",
"version": "8.0.1.0.0",
"category": "Custom Module",
"license": "AGPL-3",
"author": "OdooMRP team,"
"AvanzOSC",
"website": "http://www.odoomrp.com",
"contributors": [
"Esther Martín <esthermartin@avanzosc.es>",
"Ana Juaristi <anajuaristi@avanzosc.es>",
],
"depends": [
"mrp_production_estimated_cost",
"product_variant_cost",
],
"data": [
"views/product_view.xml",
],
"installable": True,
}
5 changes: 5 additions & 0 deletions product_cost_utilities/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 Esther Martín - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import product
40 changes: 40 additions & 0 deletions product_cost_utilities/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# © 2015 Esther Martín - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

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


class ProductProduct(models.Model):
_inherit = 'product.product'

@api.multi
@api.depends('list_price', 'cost_price')
def _compute_average_margin(self):
for product in self:
product.average_margin = product.list_price - product.cost_price

@api.multi
@api.depends('list_price', 'manual_standard_cost')
def _compute_manual_margin(self):
for product in self:
product.manual_margin = \
product.list_price - product.manual_standard_cost

@api.multi
@api.depends('cost_price', 'manual_standard_cost')
def _compute_cost(self):
for product in self:
product.cost = \
product.manual_standard_cost - product.cost_price

average_margin = fields.Float(
digits=dp.get_precision('Product Price'),
compute='_compute_average_margin', store=True)
manual_margin = fields.Float(
digits=dp.get_precision('Product Price'),
compute='_compute_manual_margin', store=True)
cost = fields.Float(
digits=dp.get_precision('Product Price'),
compute='_compute_cost', store=True)
5 changes: 5 additions & 0 deletions product_cost_utilities/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 Esther Martín - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import test_product_cost
21 changes: 21 additions & 0 deletions product_cost_utilities/tests/test_product_cost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# © 2015 Esther Martín - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import openerp.tests.common as common


class TestProductCost(common.TransactionCase):

def setUp(self):
super(TestProductCost, self).setUp()
self.product = self.env.ref('product.product_product_6')

def test_compute_average_manual_margin(self):
average_margin = self.product.list_price - self.product.cost_price
self.assertEqual(self.product.average_margin, average_margin,
'Average margin doesn\'t match')
manual_margin = \
self.product.list_price - self.product.manual_standard_cost
self.assertEqual(self.product.manual_margin, manual_margin,
'Manual margin doesn\'t match')
29 changes: 29 additions & 0 deletions product_cost_utilities/views/product_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="product_product_cost_view_tree" model="ir.ui.view">
<field name="name">product.product.cost.tree</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_product_tree_view"/>
<field name="arch" type="xml">
<field name="product_tmpl_id" position="after">
<field name="average_margin"/>
<field name="manual_margin"/>
<field name="cost"/>
</field>
</field>
</record>
<record id="product_product_cost_view_search" model="ir.ui.view">
<field name="name">product.product.cost.search</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_search_form_view"/>
<field name="arch" type="xml">
<field name="attribute_value_ids" position="after">
<filter string="Average margin negative" name="average_negative" domain="[('average_margin','&lt;=',0)]"/>
<filter string="Manual margin negative" name="manual_negative" domain="[('manual_margin','&lt;=',0)]"/>
<filter string="Manual cost != Cost price" name="manual_different_standard" domain="[('cost','!=',0)]"/>
</field>
</field>
</record>
</data>
</openerp>

0 comments on commit 26537e6

Please sign in to comment.