openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #00431
[Merge] lp:~camptocamp/ocb-addons/7.0-fix-1238525-jge into lp:ocb-addons
Joël Grand-Guillaume @ camptocamp has proposed merging lp:~camptocamp/ocb-addons/7.0-fix-1238525-jge into lp:ocb-addons.
Requested reviews:
OpenERP Community Backports Team (ocb)
Related bugs:
Bug #1238525 in OpenERP Community Backports (Addons): "[7.0] Wrong average cost computation when price type currency is different from company currency"
https://bugs.launchpad.net/ocb-addons/+bug/1238525
For more details, see:
https://code.launchpad.net/~camptocamp/ocb-addons/7.0-fix-1238525-jge/+merge/190575
Hi,
This branch fix the bug (https://bugs.launchpad.net/ocb-addons/+bug/1238525) related to the average price computation when using price on product form in other currency than the company one.
* Fix the trouble in do_partial method to convert to proper currency once new average price computed
* Adds test to avoid that in the future
Thanks for review,
Regards,
Joël
--
https://code.launchpad.net/~camptocamp/ocb-addons/7.0-fix-1238525-jge/+merge/190575
Your team OpenERP Community Backports Team is requested to review the proposed merge of lp:~camptocamp/ocb-addons/7.0-fix-1238525-jge into lp:ocb-addons.
=== modified file 'purchase/__openerp__.py'
--- purchase/__openerp__.py 2012-10-23 16:05:04 +0000
+++ purchase/__openerp__.py 2013-10-11 10:06:07 +0000
@@ -77,6 +77,9 @@
'test/ui/print_report.yml',
'test/ui/duplicate_order.yml',
'test/ui/delete_order.yml',
+ 'test/process/average_price_multicurrency_company.yml',
+ 'test/process/average_price_multicurrency_pricetype.yml',
+ 'test/process/average_price_multicurrency_pricelist.yml',
],
'demo': [
'purchase_order_demo.yml',
=== added file 'purchase/test/process/average_price_multicurrency_company.yml'
--- purchase/test/process/average_price_multicurrency_company.yml 1970-01-01 00:00:00 +0000
+++ purchase/test/process/average_price_multicurrency_company.yml 2013-10-11 10:06:07 +0000
@@ -0,0 +1,184 @@
+-
+ Setup the Company as CHF (rate 1.3086) while keeping pricelist and price_type as EUR
+-
+ !record {model: res.currency.rate, id: base.rateCHF}:
+ rate: 1.3086
+ currency_id: base.CHF
+ name: !eval time.strftime('%Y-01-01')
+-
+ !record {model: res.currency.rate, id: base.rateEUR}:
+ rate: 1.0
+ currency_id: base.EUR
+ name: !eval time.strftime('%Y-01-01')
+-
+ !record {model: res.company, id: base.main_company}:
+ currency_id: base.CHF
+-
+ !record {model: product.price.type, id: product.standard_price}:
+ currency_id: base.EUR
+-
+ !record {model: product.pricelist, id: purchase.list0}:
+ currency_id: base.EUR
+-
+ Affect the admin user to the main company
+-
+ !record {model: res.users, id: base.user_root}:
+ company_id: base.main_company
+-
+ Create a stock location for the test
+-
+ !record {model: stock.location, id: location_stock_01}:
+ name: Stock for PO
+ usage: internal
+-
+ Create a warehouse for the test
+-
+ !record {model: stock.warehouse, id: wh_stock_01}:
+ name: Warehouse for PO
+ lot_output_id: location_stock_01
+ lot_stock_id: location_stock_01
+ lot_input_id: location_stock_01
+ company_id: base.main_company
+-
+ Create a Supplier for PO
+-
+ !record {model: res.partner, id: res_partner_supplier_01}:
+ name: Supplier 1
+ supplier: 1
+-
+ Create a wine product H with an avg price of 100
+-
+ !record {model: product.product, id: product_product_h_avg_01}:
+ categ_id: product.product_category_1
+ cost_method: standard
+ name: Wine H
+ standard_price: 100.0
+ list_price: 150.0
+ type: product
+ cost_method: average
+ uom_id: product.product_uom_unit
+ uom_po_id: product.product_uom_unit
+-
+ Create a wine product I with an avg price of 200
+-
+ !record {model: product.product, id: product_product_i_avg_01}:
+ categ_id: product.product_category_1
+ cost_method: standard
+ name: Wine I
+ standard_price: 200.0
+ list_price: 250.0
+ type: product
+ cost_method: average
+ uom_id: product.product_uom_unit
+ uom_po_id: product.product_uom_unit
+-
+ Create a purchase order with two lines
+-
+ !record {model: purchase.order, id: purchase_order_lcost_05}:
+ partner_id: res_partner_supplier_01
+ invoice_method: order
+ location_id: location_stock_01
+ pricelist_id: purchase.list0
+ order_line:
+ - product_id: product_product_h_avg_01
+ price_unit: 100
+ product_qty: 15.0
+ - product_id: product_product_i_avg_01
+ price_unit: 200
+ product_qty: 5.0
+-
+ I confirm the order where invoice control is 'Bases on order'.
+-
+ !workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_lcost_05}
+-
+ Reception is ready for process, make it and check moves value
+-
+ !python {model: stock.partial.picking}: |
+ pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lcost_05")).picking_ids
+ partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
+ self.do_partial(cr, uid, [partial_id])
+ picking = self.pool.get('stock.picking').browse(cr, uid, [pick_ids[0].id])[0]
+ for move in picking.move_lines:
+ if move.product_id.name == 'Wine H':
+ assert move.price_unit == 100.0,"Technical field price_unit of Wine H stock move should record the purchase price"
+ elif move.product_id.name == 'Wine I':
+ assert move.price_unit == 200.0,"Technical field price_unit_net of Wine I stock move should record the purchase price"
+-
+ I check that purchase order is shipped.
+-
+ !python {model: purchase.order}: |
+ assert self.browse(cr, uid, ref("purchase_order_lcost_05")).shipped == True,"Purchase order should be delivered"
+-
+ I check that avg price of products is computed correctly
+-
+ !python {model: product.product}: |
+ # computed as : 100 * 15 / 15
+ value_a = 100.0
+ # computed as : 200 * 5 / 5
+ value_b = 200.0
+
+ print "computed"
+ print value_a
+ print value_b
+ print "found"
+ print self.browse(cr, uid, ref("product_product_h_avg_01")).standard_price
+ print self.browse(cr, uid, ref("product_product_i_avg_01")).standard_price
+ assert self.browse(cr, uid, ref("product_product_h_avg_01")).standard_price == value_a,"Avg price for product Wine H is wrongly computed"
+ assert self.browse(cr, uid, ref("product_product_i_avg_01")).standard_price == value_b,"Avg price for product Wine I is wrongly computed"
+-
+ Create a purchase order with two lines
+-
+ !record {model: purchase.order, id: purchase_order_lcost_05bis}:
+ partner_id: res_partner_supplier_01
+ invoice_method: order
+ location_id: location_stock_01
+ pricelist_id: purchase.list0
+ order_line:
+ - product_id: product_product_h_avg_01
+ price_unit: 200
+ product_qty: 15.0
+ - product_id: product_product_i_avg_01
+ price_unit: 400
+ product_qty: 5.0
+-
+ I confirm the order where invoice control is 'Bases on order'.
+-
+ !workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_lcost_05bis}
+-
+ Reception is ready for process, make it and check moves value
+-
+ !python {model: stock.partial.picking}: |
+ pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lcost_05bis")).picking_ids
+ partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
+ self.do_partial(cr, uid, [partial_id])
+ picking = self.pool.get('stock.picking').browse(cr, uid, [pick_ids[0].id])[0]
+ for move in picking.move_lines:
+ if move.product_id.name == 'Wine H':
+ assert move.price_unit == 200.0,"Technical field price_unit of Wine H stock move should record the purchase price"
+ elif move.product_id.name == 'Wine I':
+ assert move.price_unit == 400.0,"Technical field price_unit_net of Wine I stock move should record the purchase price"
+-
+ I check that purchase order is shipped.
+-
+ !python {model: purchase.order}: |
+ assert self.browse(cr, uid, ref("purchase_order_lcost_05")).shipped == True,"Purchase order should be delivered"
+-
+ I check that avg price of products is computed correctly
+-
+ !python {model: product.product}: |
+ xchg_rate_chf = 1.3086
+ # Value in stock in EUR
+ value_a = 100.0
+ value_b = 200.0
+ # computed as : (value_a * 15 + (200) * 15) / 30
+ value_abis = round((value_a * 15 + (200) * 15) / 30, 2)
+ # computed as : (value_b * 5 + (400) * 5) / 10
+ value_bbis = round((value_b * 5 + (400) * 5) / 10, 2)
+ print "computed"
+ print value_abis
+ print value_bbis
+ print "found"
+ print self.browse(cr, uid, ref("product_product_h_avg_01")).standard_price
+ print self.browse(cr, uid, ref("product_product_i_avg_01")).standard_price
+ assert self.browse(cr, uid, ref("product_product_h_avg_01")).standard_price == value_abis,"Avg price for product Wine H is wrongly computed"
+ assert self.browse(cr, uid, ref("product_product_i_avg_01")).standard_price == value_bbis,"Avg price for product Wine I is wrongly computed"
=== added file 'purchase/test/process/average_price_multicurrency_pricelist.yml'
--- purchase/test/process/average_price_multicurrency_pricelist.yml 1970-01-01 00:00:00 +0000
+++ purchase/test/process/average_price_multicurrency_pricelist.yml 2013-10-11 10:06:07 +0000
@@ -0,0 +1,176 @@
+-
+ Setup the pricelist as CHF (rate 1.3086) while keeping company and price_type as EUR
+-
+ !record {model: res.currency.rate, id: base.rateCHF}:
+ rate: 1.3086
+ currency_id: base.CHF
+ name: !eval time.strftime('%Y-01-01')
+-
+ !record {model: res.currency.rate, id: base.rateEUR}:
+ rate: 1.0
+ currency_id: base.EUR
+ name: !eval time.strftime('%Y-01-01')
+-
+ !record {model: res.company, id: base.main_company}:
+ currency_id: base.EUR
+-
+ !record {model: product.price.type, id: product.standard_price}:
+ currency_id: base.EUR
+-
+ !record {model: product.pricelist, id: purchase.list0}:
+ currency_id: base.CHF
+-
+ Affect the admin user to the main company
+-
+ !record {model: res.users, id: base.user_root}:
+ company_id: base.main_company
+-
+ Create a stock location for the test
+-
+ !record {model: stock.location, id: location_stock_01}:
+ name: Stock for PO
+ usage: internal
+-
+ Create a warehouse for the test
+-
+ !record {model: stock.warehouse, id: wh_stock_01}:
+ name: Warehouse for PO
+ lot_output_id: location_stock_01
+ lot_stock_id: location_stock_01
+ lot_input_id: location_stock_01
+ company_id: base.main_company
+-
+ Create a Supplier for PO
+-
+ !record {model: res.partner, id: res_partner_supplier_01}:
+ name: Supplier 1
+ supplier: 1
+-
+ Create a wine product F with an avg price of 100
+-
+ !record {model: product.product, id: product_product_f_avg_01}:
+ categ_id: product.product_category_1
+ cost_method: standard
+ name: Wine F
+ standard_price: 100.0
+ list_price: 150.0
+ type: product
+ cost_method: average
+ uom_id: product.product_uom_unit
+ uom_po_id: product.product_uom_unit
+-
+ Create a wine product G with an avg price of 200
+-
+ !record {model: product.product, id: product_product_g_avg_01}:
+ categ_id: product.product_category_1
+ cost_method: standard
+ name: Wine G
+ standard_price: 200.0
+ list_price: 250.0
+ type: product
+ cost_method: average
+ uom_id: product.product_uom_unit
+ uom_po_id: product.product_uom_unit
+-
+ Create a purchase order with two lines
+-
+ !record {model: purchase.order, id: purchase_order_lcost_04}:
+ partner_id: res_partner_supplier_01
+ invoice_method: order
+ location_id: location_stock_01
+ pricelist_id: purchase.list0
+ order_line:
+ - product_id: product_product_f_avg_01
+ price_unit: 100
+ product_qty: 15.0
+ - product_id: product_product_g_avg_01
+ price_unit: 200
+ product_qty: 5.0
+-
+ I confirm the order where invoice control is 'Bases on order'.
+-
+ !workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_lcost_04}
+-
+ Reception is ready for process, make it and check moves value
+-
+ !python {model: stock.partial.picking}: |
+ pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lcost_04")).picking_ids
+ partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
+ self.do_partial(cr, uid, [partial_id])
+ picking = self.pool.get('stock.picking').browse(cr, uid, [pick_ids[0].id])[0]
+ for move in picking.move_lines:
+ if move.product_id.name == 'Wine A':
+ assert move.price_unit == 100.0,"Technical field price_unit of Wine F stock move should record the purchase price"
+ elif move.product_id.name == 'Wine B':
+ assert move.price_unit == 200.0,"Technical field price_unit_net of Wine G stock move should record the purchase price"
+-
+ I check that purchase order is shipped.
+-
+ !python {model: purchase.order}: |
+ assert self.browse(cr, uid, ref("purchase_order_lcost_04")).shipped == True,"Purchase order should be delivered"
+-
+ I check that avg price of products is computed correctly
+-
+ !python {model: product.product}: |
+ xchg_rate_chf = 1.3086
+ # computed as : (100 * 15 / 15) / exchange rate of 1.3086
+ # => because we store price in EUR and 100 is CHF
+ value_a = round(100.0 / xchg_rate_chf, 2)
+ print self.browse(cr, uid, ref("product_product_f_avg_01")).standard_price
+ print self.browse(cr, uid, ref("product_product_f_avg_01")).qty_available
+ # computed as : (200 * 5 / 5) / exchange rate of 1.3086
+ # => because we store price in EUR and 200 is CHF
+ value_b = round(200.0 / xchg_rate_chf, 2)
+ assert self.browse(cr, uid, ref("product_product_f_avg_01")).standard_price == value_a,"Avg price for product Wine F is wrongly computed"
+ assert self.browse(cr, uid, ref("product_product_g_avg_01")).standard_price == value_b,"Avg price for product Wine G is wrongly computed"
+-
+ Create a purchase order with two lines
+-
+ !record {model: purchase.order, id: purchase_order_lcost_04bis}:
+ partner_id: res_partner_supplier_01
+ invoice_method: order
+ location_id: location_stock_01
+ pricelist_id: purchase.list0
+ order_line:
+ - product_id: product_product_f_avg_01
+ price_unit: 200
+ product_qty: 15.0
+ - product_id: product_product_g_avg_01
+ price_unit: 400
+ product_qty: 5.0
+-
+ I confirm the order where invoice control is 'Bases on order'.
+-
+ !workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_lcost_04bis}
+-
+ Reception is ready for process, make it and check moves value
+-
+ !python {model: stock.partial.picking}: |
+ pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lcost_04bis")).picking_ids
+ partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
+ self.do_partial(cr, uid, [partial_id])
+ picking = self.pool.get('stock.picking').browse(cr, uid, [pick_ids[0].id])[0]
+ for move in picking.move_lines:
+ if move.product_id.name == 'Wine A':
+ assert move.price_unit == 200.0,"Technical field price_unit of Wine F stock move should record the purchase price"
+ elif move.product_id.name == 'Wine B':
+ assert move.price_unit == 400.0,"Technical field price_unit_net of Wine G stock move should record the purchase price"
+-
+ I check that purchase order is shipped.
+-
+ !python {model: purchase.order}: |
+ assert self.browse(cr, uid, ref("purchase_order_lcost_04bis")).shipped == True,"Purchase order should be delivered"
+-
+ I check that avg price of products is computed correctly
+-
+ !python {model: product.product}: |
+ xchg_rate_chf = 1.3086
+ # Value in stock in EUR
+ value_a = round(100.0 / xchg_rate_chf, 2)
+ value_b = round(200.0 / xchg_rate_chf, 2)
+ # computed as : (value_a * 15 + (200 / xchg_rate_chf) * 15) / 30
+ value_abis = round((value_a * 15 + (200 / xchg_rate_chf) * 15) / 30, 2)
+ # computed as : (value_b * 5 + (400 / xchg_rate_chf) * 5) / 10
+ value_bbis = round((value_b * 5 + (400 / xchg_rate_chf) * 5) / 10, 2)
+ assert self.browse(cr, uid, ref("product_product_f_avg_01")).standard_price == value_abis,"Avg price for product Wine F is wrongly computed"
+ assert self.browse(cr, uid, ref("product_product_g_avg_01")).standard_price == value_bbis,"Avg price for product Wine G is wrongly computed"
=== added file 'purchase/test/process/average_price_multicurrency_pricetype.yml'
--- purchase/test/process/average_price_multicurrency_pricetype.yml 1970-01-01 00:00:00 +0000
+++ purchase/test/process/average_price_multicurrency_pricetype.yml 2013-10-11 10:06:07 +0000
@@ -0,0 +1,180 @@
+-
+ Setup the Company as CHF (rate 1.3086) while keeping pricelist and price_type as EUR
+-
+ !record {model: res.currency.rate, id: base.rateCHF}:
+ rate: 1.3086
+ currency_id: base.CHF
+ name: !eval time.strftime('%Y-01-01')
+-
+ !record {model: res.currency.rate, id: base.rateEUR}:
+ rate: 1.0
+ currency_id: base.EUR
+ name: !eval time.strftime('%Y-01-01')
+-
+ !record {model: res.company, id: base.main_company}:
+ currency_id: base.EUR
+-
+ !record {model: product.price.type, id: product.standard_price}:
+ currency_id: base.CHF
+-
+ !record {model: product.pricelist, id: purchase.list0}:
+ currency_id: base.EUR
+-
+ Affect the admin user to the main company
+-
+ !record {model: res.users, id: base.user_root}:
+ company_id: base.main_company
+-
+ Create a stock location for the test
+-
+ !record {model: stock.location, id: location_stock_01}:
+ name: Stock for PO
+ usage: internal
+-
+ Create a warehouse for the test
+-
+ !record {model: stock.warehouse, id: wh_stock_01}:
+ name: Warehouse for PO
+ lot_output_id: location_stock_01
+ lot_stock_id: location_stock_01
+ lot_input_id: location_stock_01
+ company_id: base.main_company
+-
+ Create a Supplier for PO
+-
+ !record {model: res.partner, id: res_partner_supplier_01}:
+ name: Supplier 1
+ supplier: 1
+-
+ Create a wine product J with an avg price of 100
+-
+ !record {model: product.product, id: product_product_j_avg_01}:
+ categ_id: product.product_category_1
+ cost_method: standard
+ name: Wine J
+ standard_price: 100.0
+ list_price: 150.0
+ type: product
+ cost_method: average
+ uom_id: product.product_uom_unit
+ uom_po_id: product.product_uom_unit
+-
+ Create a wine product K with an avg price of 200
+-
+ !record {model: product.product, id: product_product_k_avg_01}:
+ categ_id: product.product_category_1
+ cost_method: standard
+ name: Wine K
+ standard_price: 200.0
+ list_price: 250.0
+ type: product
+ cost_method: average
+ uom_id: product.product_uom_unit
+ uom_po_id: product.product_uom_unit
+-
+ Create a purchase order with two lines
+-
+ !record {model: purchase.order, id: purchase_order_lcost_06}:
+ partner_id: res_partner_supplier_01
+ invoice_method: order
+ location_id: location_stock_01
+ pricelist_id: purchase.list0
+ order_line:
+ - product_id: product_product_j_avg_01
+ price_unit: 100
+ product_qty: 15.0
+ - product_id: product_product_k_avg_01
+ price_unit: 200
+ product_qty: 5.0
+-
+ I confirm the order where invoice control is 'Bases on order'.
+-
+ !workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_lcost_06}
+-
+ Reception is ready for process, make it and check moves value
+-
+ !python {model: stock.partial.picking}: |
+ pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lcost_06")).picking_ids
+ partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
+ self.do_partial(cr, uid, [partial_id])
+ picking = self.pool.get('stock.picking').browse(cr, uid, [pick_ids[0].id])[0]
+ for move in picking.move_lines:
+ if move.product_id.name == 'Wine J':
+ assert move.price_unit == 100.0,"Technical field price_unit of Wine J stock move should record the purchase price"
+ elif move.product_id.name == 'Wine K':
+ assert move.price_unit == 200.0,"Technical field price_unit_net of Wine K stock move should record the purchase price"
+-
+ I check that purchase order is shipped.
+-
+ !python {model: purchase.order}: |
+ assert self.browse(cr, uid, ref("purchase_order_lcost_06")).shipped == True,"Purchase order should be delivered"
+-
+ I check that avg price of products is computed correctly
+-
+ !python {model: product.product}: |
+ xchg_rate_chf = 1.3086
+ # computed as : (100 * 15 / 15) * Exchnge rate of 1.3086
+ value_a = round(100.0 * xchg_rate_chf, 2)
+ # computed as : (200 * 5 / 5) * Exchnge rate of 1.3086
+ value_b = round(200.0 * xchg_rate_chf, 2)
+ print self.browse(cr, uid, ref("product_product_j_avg_01")).standard_price
+ print self.browse(cr, uid, ref("product_product_k_avg_01")).standard_price
+ assert self.browse(cr, uid, ref("product_product_j_avg_01")).standard_price == value_a,"Avg price for product Wine J is wrongly computed"
+ assert self.browse(cr, uid, ref("product_product_k_avg_01")).standard_price == value_b,"Avg price for product Wine K is wrongly computed"
+-
+ Create a purchase order with two lines
+-
+ !record {model: purchase.order, id: purchase_order_lcost_06bis}:
+ partner_id: res_partner_supplier_01
+ invoice_method: order
+ location_id: location_stock_01
+ pricelist_id: purchase.list0
+ order_line:
+ - product_id: product_product_j_avg_01
+ price_unit: 200
+ product_qty: 15.0
+ - product_id: product_product_k_avg_01
+ price_unit: 400
+ product_qty: 5.0
+-
+ I confirm the order where invoice control is 'Bases on order'.
+-
+ !workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_lcost_06bis}
+-
+ Reception is ready for process, make it and check moves value
+-
+ !python {model: stock.partial.picking}: |
+ pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lcost_06bis")).picking_ids
+ partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
+ self.do_partial(cr, uid, [partial_id])
+ picking = self.pool.get('stock.picking').browse(cr, uid, [pick_ids[0].id])[0]
+ for move in picking.move_lines:
+ if move.product_id.name == 'Wine J':
+ assert move.price_unit == 200.0,"Technical field price_unit of Wine J stock move should record the purchase price"
+ elif move.product_id.name == 'Wine K':
+ assert move.price_unit == 400.0,"Technical field price_unit_net of Wine K stock move should record the purchase price"
+-
+ I check that purchase order is shipped.
+-
+ !python {model: purchase.order}: |
+ assert self.browse(cr, uid, ref("purchase_order_lcost_06bis")).shipped == True,"Purchase order should be delivered"
+-
+ I check that avg price of products is computed correctly
+-
+ !python {model: product.product}: |
+ xchg_rate_chf = 1.3086
+ # Value in stock in CHF
+ value_a = round(100.0 * xchg_rate_chf, 2)
+ value_b = round(200.0 * xchg_rate_chf, 2)
+ # computed as : (value_a * 15 + (200 * xchg_rate_chf) * 15) / 30
+ value_abis = round((value_a * 15 + (200 * xchg_rate_chf) * 15) / 30, 2)
+ # computed as : (value_b * 5 + (400 * xchg_rate_chf) * 5) / 10
+ value_bbis = round((value_b * 5 + (400 * xchg_rate_chf) * 5) / 10, 2)
+ print "computed"
+ print value_abis
+ print value_bbis
+ print "found"
+ print self.browse(cr, uid, ref("product_product_j_avg_01")).standard_price
+ print self.browse(cr, uid, ref("product_product_k_avg_01")).standard_price
+ assert self.browse(cr, uid, ref("product_product_j_avg_01")).standard_price == value_abis,"Avg price for product Wine J is wrongly computed"
+ assert self.browse(cr, uid, ref("product_product_k_avg_01")).standard_price == value_bbis,"Avg price for product Wine K is wrongly computed"
=== modified file 'stock/stock.py'
--- stock/stock.py 2013-10-04 12:22:57 +0000
+++ stock/stock.py 2013-10-11 10:06:07 +0000
@@ -1236,6 +1236,7 @@
product_obj = self.pool.get('product.product')
currency_obj = self.pool.get('res.currency')
uom_obj = self.pool.get('product.uom')
+ pricetype_obj = self.pool.get('product.price.type')
sequence_obj = self.pool.get('ir.sequence')
wf_service = netsvc.LocalService("workflow")
for pick in self.browse(cr, uid, ids, context=context):
@@ -1268,13 +1269,15 @@
move_currency_id = move.company_id.currency_id.id
context['currency_id'] = move_currency_id
qty = uom_obj._compute_qty(cr, uid, product_uom, product_qty, product.uom_id.id)
-
+ price_type_id = pricetype_obj.search(cr, uid, [('field','=','standard_price')])[0]
+ price_type_currency_id = pricetype_obj.browse(cr,uid,price_type_id).currency_id.id
if product.id in product_avail:
product_avail[product.id] += qty
else:
product_avail[product.id] = product.qty_available
if qty > 0:
+ # New price in company currency
new_price = currency_obj.compute(cr, uid, product_currency,
move_currency_id, product_price)
new_price = uom_obj._compute_price(cr, uid, product_uom, new_price,
@@ -1284,8 +1287,14 @@
else:
# Get the standard price
amount_unit = product.price_get('standard_price', context=context)[product.id]
+ # Here we must convert the new price computed in the currency of the price_type
+ # of the product (e.g. company currency: EUR, price_type: USD)
+ # The current value is still in company currency at this stage
new_std_price = ((amount_unit * product_avail[product.id])\
+ (new_price * qty))/(product_avail[product.id] + qty)
+ # Convert the price in price_type currency
+ new_std_price = currency_obj.compute(cr, uid, move_currency_id,
+ price_type_currency_id, new_std_price)
# Write the field according to price type field
product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price})
@@ -2669,6 +2678,7 @@
picking_obj = self.pool.get('stock.picking')
product_obj = self.pool.get('product.product')
currency_obj = self.pool.get('res.currency')
+ pricetype_obj = self.pool.get('product.price.type')
uom_obj = self.pool.get('product.uom')
wf_service = netsvc.LocalService("workflow")
@@ -2702,6 +2712,8 @@
move_currency_id = move.company_id.currency_id.id
context['currency_id'] = move_currency_id
qty = uom_obj._compute_qty(cr, uid, product_uom, product_qty, product.uom_id.id)
+ price_type_id = pricetype_obj.search(cr, uid, [('field','=','standard_price')])[0]
+ price_type_currency_id = pricetype_obj.browse(cr,uid,price_type_id).currency_id.id
if qty > 0:
new_price = currency_obj.compute(cr, uid, product_currency,
move_currency_id, product_price)
@@ -2712,9 +2724,15 @@
else:
# Get the standard price
amount_unit = product.price_get('standard_price', context=context)[product.id]
+ # Here we must convert the new price computed in the currency of the price_type
+ # of the product (e.g. company currency: EUR, price_type: USD)
+ # The current value is still in company currency at this stage
new_std_price = ((amount_unit * product.qty_available)\
+ (new_price * qty))/(product.qty_available + qty)
-
+ # Convert the price in price_type currency
+ new_std_price = currency_obj.compute(cr, uid, move_currency_id,
+ price_type_currency_id, new_std_price)
+ # Write the field according to price type field
product_obj.write(cr, uid, [product.id],{'standard_price': new_std_price})
# Record the values that were chosen in the wizard, so they can be
Follow ups