openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #01706
[Merge] lp:~camptocamp/margin-analysis/7.0-pending-merge into lp:margin-analysis
Joël Grand-Guillaume @ camptocamp has proposed merging lp:~camptocamp/margin-analysis/7.0-pending-merge into lp:margin-analysis.
Requested reviews:
Margin Analysis Core Editors (margin-analysis-core-editors)
For more details, see:
https://code.launchpad.net/~camptocamp/margin-analysis/7.0-pending-merge/+merge/196921
* Improve logger
* Add a basic YML test case for product_historical_margin
--
https://code.launchpad.net/~camptocamp/margin-analysis/7.0-pending-merge/+merge/196921
Your team Margin Analysis Core Editors is requested to review the proposed merge of lp:~camptocamp/margin-analysis/7.0-pending-merge into lp:margin-analysis.
=== modified file 'product_cost_incl_bom/product_cost_incl_bom.py'
--- product_cost_incl_bom/product_cost_incl_bom.py 2013-10-10 12:11:41 +0000
+++ product_cost_incl_bom/product_cost_incl_bom.py 2013-11-27 15:05:50 +0000
@@ -22,6 +22,8 @@
from openerp.osv.orm import Model
from openerp.osv import fields
import decimal_precision as dp
+import logging
+_logger = logging.getLogger(__name__)
class Product(Model):
_inherit = 'product.product'
@@ -77,8 +79,9 @@
def _cost_price(self, cr, uid, ids, field_name, arg, context=None):
if context is None:
context = {}
-
res = self._compute_purchase_price(cr, uid, ids, context=context)
+ _logger.debug("get cost field _cost_price %s, arg: %s, context: %s, result:%s",
+ field_name, arg, context, res)
return res
_columns = {
=== modified file 'product_get_cost_field/product_get_cost_field.py'
--- product_get_cost_field/product_get_cost_field.py 2013-10-10 12:05:11 +0000
+++ product_get_cost_field/product_get_cost_field.py 2013-11-27 15:05:50 +0000
@@ -23,7 +23,7 @@
from openerp.osv.orm import Model
from openerp.osv import fields
import decimal_precision as dp
-
+_logger = logging.getLogger(__name__)
class Product(Model):
_inherit = 'product.product'
@@ -42,9 +42,9 @@
def _cost_price(self, cr, uid, ids, field_name, arg, context=None):
if context is None:
context = {}
- logger = logging.getLogger('product.get_cost_field')
- logger.debug("get cost field _cost_price %s, %s, %s", field_name, arg, context)
res = self._compute_purchase_price(cr, uid, ids, context=context)
+ _logger.debug("get cost field _cost_price %s, arg: %s, context: %s, result:%s",
+ field_name, arg, context, res)
return res
def get_cost_field(self, cr, uid, ids, context=None):
=== modified file 'product_historical_margin/__openerp__.py'
--- product_historical_margin/__openerp__.py 2013-10-17 14:55:52 +0000
+++ product_historical_margin/__openerp__.py 2013-11-27 15:05:50 +0000
@@ -57,7 +57,9 @@
"product_view.xml",
],
'demo_xml': [],
- 'tests': [],
+ 'test': [
+ 'test/basic_historical_margin.yml',
+ ],
'installable': True,
'auto_install': False,
'license': 'AGPL-3',
=== modified file 'product_historical_margin/invoice.py'
--- product_historical_margin/invoice.py 2013-11-25 10:38:14 +0000
+++ product_historical_margin/invoice.py 2013-11-27 15:05:50 +0000
@@ -22,6 +22,7 @@
from openerp.osv.orm import Model
from osv import fields
import decimal_precision as dp
+_logger = logging.getLogger(__name__)
class account_invoice(Model):
_inherit = 'account.invoice'
@@ -64,7 +65,7 @@
res = {}
if not ids:
return res
- logger = logging.getLogger('product_historical_margin')
+
user_obj = self.pool.get('res.users')
currency_obj = self.pool.get('res.currency')
@@ -116,7 +117,7 @@
'margin_absolute': margin_absolute,
'margin_relative': margin_relative,
}
- logger.debug("The following values has been computed for product ID %d: subtotal_cost_price=%f"
+ _logger.debug("The following values has been computed for product ID %d: subtotal_cost_price=%f"
"subtotal_cost_price_company=%f, subtotal_company=%f", product.id, subtotal_cost_price,
subtotal_cost_price_company, subtotal_company)
return res
=== modified file 'product_historical_margin/product_historical_margin.py'
--- product_historical_margin/product_historical_margin.py 2013-10-17 14:55:52 +0000
+++ product_historical_margin/product_historical_margin.py 2013-11-27 15:05:50 +0000
@@ -24,6 +24,7 @@
from osv import fields
import decimal_precision as dp
+_logger = logging.getLogger(__name__)
# Don't Forget to remove supplier (in_invoice et in_refund) from the product margin computation
# And remove out_refund from the computation
@@ -55,7 +56,7 @@
if not ids:
return res
user_obj = self.pool.get('res.users')
- logger = logging.getLogger('product_historical_margin')
+
company_id = user_obj.browse(cr, uid, uid, context=context).company_id.id
for product_id in ids:
res[product_id] = {'margin_absolute': 0, 'margin_relative': 0}
@@ -93,7 +94,7 @@
tot_sale[product_id] += sale
for product_id in tot_sale:
if tot_sale[product_id] == 0:
- logger.debug("Sale price for product ID %d is 0, cannot compute margin rate...", product_id)
+ _logger.debug("Sale price for product ID %d is 0, cannot compute margin rate...", product_id)
res[product_id]['margin_relative'] = 999.
else:
res[product_id]['margin_relative'] = (res[product_id]['margin_absolute'] / tot_sale[product_id]) * 100
=== added directory 'product_historical_margin/test'
=== added file 'product_historical_margin/test/basic_historical_margin.yml'
--- product_historical_margin/test/basic_historical_margin.yml 1970-01-01 00:00:00 +0000
+++ product_historical_margin/test/basic_historical_margin.yml 2013-11-27 15:05:50 +0000
@@ -0,0 +1,129 @@
+-
+ Create a Customer for SO
+-
+ !record {model: res.partner, id: res_partner_customer01}:
+ name: Customer 3
+ customer: 1
+-
+ Create a wine product A with an avg price of 100
+-
+ !record {model: product.product, id: product_product_a_avg_01}:
+ categ_id: product.product_category_1
+ cost_method: standard
+ name: Wine A
+ standard_price: 100.0
+ list_price: 150.0
+ cost_method: average
+ uom_id: product.product_uom_unit
+ uom_po_id: product.product_uom_unit
+-
+ Create a shop
+-
+ !record {model: sale.shop, id: default_shop}:
+ name: Default test shop
+ company_id: base.main_company
+ payment_default_id: account.account_payment_term_net
+-
+ In order to test process of the Sale Order, I create sale order
+-
+ !record {model: sale.order, id: sale_order_test1}:
+ partner_id: res_partner_customer01
+ note: Invoice Manual
+ order_policy: manual
+ pricelist_id: product.list0
+ shop_id: default_shop
+ order_line:
+ - product_id: product_product_a_avg_01
+ product_uom_qty: 10
+ price_unit: 150.0
+-
+ I confirm the Quotation with "Manual" order policy.
+-
+ !workflow {model: sale.order, action: order_confirm, ref: sale_order_test1}
+-
+ I check that Invoice should not created.
+-
+ !python {model: sale.order}: |
+ sale_order = self.browse(cr, uid, ref("sale_order_test1"))
+ assert len(sale_order.invoice_ids) == False, "Invoice should not created."
+-
+ I create advance invoice where type is 'Invoice all the Sale Order'.
+-
+ !python {model: sale.advance.payment.inv}: |
+ ctx = context.copy()
+ ctx.update({"active_model": 'sale.order', "active_ids": [ref("sale_order_test1")], "active_id":ref("sale_order_test1")})
+ pay_id = self.create(cr, uid, {'advance_payment_method': 'all'})
+ self.create_invoices(cr, uid, [pay_id], context=ctx)
+-
+ I check Invoice which made advance where type is 'Invoice all the Sale Order'.
+-
+ !python {model: sale.order}: |
+ order = self.browse(cr, uid, ref('sale_order_test1'))
+ assert order.invoice_ids, "Invoice should be created after make invoice where type is 'Invoice all the Sale Order'."
+-
+ I open the Invoice.
+-
+ !python {model: sale.order}: |
+ import netsvc
+ wf_service = netsvc.LocalService("workflow")
+ so = self.browse(cr, uid, ref("sale_order_test1"))
+ for invoice in so.invoice_ids:
+ wf_service.trg_validate(uid, 'account.invoice', invoice.id, 'invoice_open', cr)
+-
+ I check that margin of products is computed correctly
+-
+ !python {model: product.product}: |
+ value = 150 * 10 - 100 * 10
+ assert self.browse(cr, uid, ref("product_product_a_avg_01")).margin_absolute == value,"Margin for product Wine A is wrongly computed"
+-
+ In order to test process of the Sale Order, I create a second sale order
+-
+ !record {model: sale.order, id: sale_order_test2}:
+ partner_id: res_partner_customer01
+ note: Invoice Manual
+ order_policy: manual
+ pricelist_id: product.list0
+ shop_id: default_shop
+ order_line:
+ - product_id: product_product_a_avg_01
+ product_uom_qty: 10
+ price_unit: 200
+-
+ I confirm the Quotation with "Manual" order policy.
+-
+ !workflow {model: sale.order, action: order_confirm, ref: sale_order_test2}
+-
+ I check that Invoice should not created.
+-
+ !python {model: sale.order}: |
+ sale_order = self.browse(cr, uid, ref("sale_order_test2"))
+ assert len(sale_order.invoice_ids) == False, "Invoice should not created."
+-
+ I create advance invoice where type is 'Invoice all the Sale Order'.
+-
+ !python {model: sale.advance.payment.inv}: |
+ ctx = context.copy()
+ ctx.update({"active_model": 'sale.order', "active_ids": [ref("sale_order_test2")], "active_id":ref("sale_order_test2")})
+ pay_id = self.create(cr, uid, {'advance_payment_method': 'all'})
+ self.create_invoices(cr, uid, [pay_id], context=ctx)
+-
+ I check Invoice which made advance where type is 'Invoice all the Sale Order'.
+-
+ !python {model: sale.order}: |
+ order = self.browse(cr, uid, ref('sale_order_test2'))
+ assert order.invoice_ids, "Invoice should be created after make invoice where type is 'Invoice all the Sale Order'."
+-
+ I open the Invoice.
+-
+ !python {model: sale.order}: |
+ import netsvc
+ wf_service = netsvc.LocalService("workflow")
+ so = self.browse(cr, uid, ref("sale_order_test2"))
+ for invoice in so.invoice_ids:
+ wf_service.trg_validate(uid, 'account.invoice', invoice.id, 'invoice_open', cr)
+-
+ I check that margin of products is computed correctly
+-
+ !python {model: product.product}: |
+ value = ((150 - 100) * 10 + (200 - 100) * 10 )
+ assert self.browse(cr, uid, ref("product_product_a_avg_01")).margin_absolute == value,"Margin for product Wine A is wrongly computed"
=== modified file 'product_standard_margin/product_std_margin.py'
--- product_standard_margin/product_std_margin.py 2013-10-14 18:16:46 +0000
+++ product_standard_margin/product_std_margin.py 2013-11-27 15:05:50 +0000
@@ -24,7 +24,7 @@
from openerp.osv import orm, fields
import decimal_precision as dp
import logging
-
+_logger = logging.getLogger(__name__)
class Product(orm.Model):
_inherit = 'product.product'
@@ -67,7 +67,7 @@
'margin_relative': float}
}}
"""
- logger = logging.getLogger('product_standard_margin')
+
if context is None:
context = {}
res = {}
@@ -81,7 +81,7 @@
[product.id], context=context)[product.id]
res[product.id]['standard_margin'] = sale - cost
if sale == 0:
- logger.debug("Sale price for product ID %d is 0, cannot compute margin rate...", product.id)
+ _logger.debug("Sale price for product ID %d is 0, cannot compute margin rate...", product.id)
res[product.id]['standard_margin_rate'] = 999.
else:
res[product.id]['standard_margin_rate'] = (sale - cost) / sale * 100
Follow ups