-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
150 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 |
---|---|---|
@@ -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> |
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,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 |
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,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, | ||
} |
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,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 |
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,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) |
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,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 |
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,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') |
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,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','<=',0)]"/> | ||
<filter string="Manual margin negative" name="manual_negative" domain="[('manual_margin','<=',0)]"/> | ||
<filter string="Manual cost != Cost price" name="manual_different_standard" domain="[('cost','!=',0)]"/> | ||
</field> | ||
</field> | ||
</record> | ||
</data> | ||
</openerp> |