openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #03377
[Merge] lp:~openerp-dev/openobject-addons/trunk-bug-715470-ksa into lp:openobject-addons
Kirti Savalia(OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-bug-715470-ksa into lp:openobject-addons.
Requested reviews:
OpenERP Core Team (openerp)
Related bugs:
#715470 [PS] sale margin module : wrong computation
https://bugs.launchpad.net/bugs/715470
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-715470-ksa/+merge/51075
https://bugs.launchpad.net/openobject-addons/+bug/715470
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-715470-ksa/+merge/51075
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-bug-715470-ksa.
=== modified file 'sale_margin/sale_margin.py'
--- sale_margin/sale_margin.py 2011-01-14 00:11:01 +0000
+++ sale_margin/sale_margin.py 2011-02-24 06:19:56 +0000
@@ -26,30 +26,21 @@
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False):
+ product_obj = self.pool.get('product.product')
+ currency_obj = self.pool.get('res.currency')
res = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty=qty,
uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id,
lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag)
frm_cur = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id
to_cur = self.pool.get('res.partner').browse(cr, uid, partner_id).property_product_pricelist.currency_id.id
if product:
- purchase_price = self.pool.get('product.product').browse(cr, uid, product).standard_price
- price = self.pool.get('res.currency').compute(cr, uid, frm_cur, to_cur, purchase_price, round=False)
- res['value'].update({'purchase_price': price})
- return res
-
- def _product_margin(self, cr, uid, ids, field_name, arg, context=None):
- res = {}
- for line in self.browse(cr, uid, ids, context=context):
- res[line.id] = 0
- if line.product_id:
- if line.purchase_price:
- res[line.id] = round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.purchase_price*line.product_uos_qty), 2)
- else:
- res[line.id] = round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.product_id.standard_price*line.product_uos_qty), 2)
+ price = product_obj.read(cr, uid, product, ['standard_price','list_price'])
+ purchase_price = currency_obj.compute(cr, uid, frm_cur, to_cur, price, round=False)
+ res['value'].update({'purchase_price': price['standard_price'], 'margin': price['list_price'] - price['standard_price']})
return res
_columns = {
- 'margin': fields.function(_product_margin, method=True, string='Margin', store=True),
+ 'margin': fields.float('margin', digits=(16,2)),
'purchase_price': fields.float('Cost Price', digits=(16,2))
}
@@ -58,7 +49,15 @@
class sale_order(osv.osv):
_inherit = "sale.order"
+ def _get_order(self, cr, uid, ids, context=None):
+ result = {}
+ for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context):
+ result[line.order_id.id] = True
+ return result.keys()
+
def _product_margin(self, cr, uid, ids, field_name, arg, context=None):
+ if context is None:
+ context = {}
result = {}
for sale in self.browse(cr, uid, ids, context=context):
result[sale.id] = 0.0
@@ -67,7 +66,8 @@
return result
_columns = {
- 'margin': fields.function(_product_margin, method=True, string='Margin', store=True, help="It gives profitability by calculating the difference between the Unit Price and Cost Price."),
+ 'margin': fields.function(_product_margin, method=True, string='Margin',
+ store = {'sale.order.line': (_get_order, [],10)}, help="It gives profitability by calculating the difference between the Unit Price and Cost Price."),
}
sale_order()
=== modified file 'sale_margin/sale_margin_view.xml'
--- sale_margin/sale_margin_view.xml 2011-01-14 00:11:01 +0000
+++ sale_margin/sale_margin_view.xml 2011-02-24 06:19:56 +0000
@@ -37,7 +37,19 @@
</xpath>
</field>
</record>
-
+
+ <record model="ir.ui.view" id="view_order_form_inherit2">
+ <field name="name">sale.order.form.inherit2</field>
+ <field name="model">sale.order</field>
+ <field name="type">form</field>
+ <field name="inherit_id" ref="sale.view_order_form"/>
+ <field name="arch" type="xml">
+ <xpath expr="/form/notebook/page/field[@name='order_line']/form/notebook/page/field[@name='product_id']" position="after">
+ <field name="margin"/>
+ </xpath>
+ </field>
+ </record>
+
<record model="ir.ui.view" id="sale_margin_sale_order_tree">
<field name="name">sale.order.margin.view.tree</field>
<field name="type">tree</field>
Follow ups