← Back to team overview

openerp-community-reviewer team mailing list archive

lp:~camptocamp/margin-analysis/7.0-port-product_historical_margin-yvr into lp:margin-analysis

 

Yannick Vaucher @ Camptocamp has proposed merging lp:~camptocamp/margin-analysis/7.0-port-product_historical_margin-yvr into lp:margin-analysis with lp:~camptocamp/margin-analysis/7.0-port-product_historical_margin-xml-retab-yvr as a prerequisite.

Requested reviews:
  Margin Analysis Core Editors (margin-analysis-core-editors)

For more details, see:
https://code.launchpad.net/~camptocamp/margin-analysis/7.0-port-product_historical_margin-yvr/+merge/191660
-- 
https://code.launchpad.net/~camptocamp/margin-analysis/7.0-port-product_historical_margin-yvr/+merge/191660
Your team Margin Analysis Core Editors is requested to review the proposed merge of lp:~camptocamp/margin-analysis/7.0-port-product_historical_margin-yvr into lp:margin-analysis.
=== modified file 'product_historical_margin/__openerp__.py'
--- product_historical_margin/__openerp__.py	2013-09-11 08:08:22 +0000
+++ product_historical_margin/__openerp__.py	2013-10-17 14:57:20 +0000
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 ##############################################################################
 #
-#    Author:  Alexandre Fayolle, Joel Grand-Guillaume
+#    Author: Alexandre Fayolle, Joel Grand-Guillaume
 #    Copyright 2012 Camptocamp SA
 #
 #    This program is free software: you can redistribute it and/or modify
@@ -58,7 +58,7 @@
                 ],
  'demo_xml': [],
  'tests': [],
- 'installable': False,
+ 'installable': True,
  'auto_install': False,
  'license': 'AGPL-3',
  'application': False

=== modified file 'product_historical_margin/account_invoice_view.xml'
--- product_historical_margin/account_invoice_view.xml	2013-10-17 14:57:20 +0000
+++ product_historical_margin/account_invoice_view.xml	2013-10-17 14:57:20 +0000
@@ -5,10 +5,9 @@
     <record id="view_invoice_line_tree_from_product" model="ir.ui.view">
       <field name="name">account.invoice.line.from.product.tree</field>
       <field name="model">account.invoice.line</field>
-      <field name="type">tree</field>
       <field name="priority">20</field>
       <field name="arch" type="xml">
-        <tree string="Invoice Line">
+        <tree string="Invoice Line" create="false">
           <field name="invoice_type"/>
           <field name="partner_id"/>
           <field name="invoice_user_id"/>
@@ -36,7 +35,6 @@
     <record id="view_account_invoice_line_filter" model="ir.ui.view">
       <field name="name">account.invoice.line.select</field>
       <field name="model">account.invoice.line</field>
-      <field name="type">search</field>
       <field name="arch" type="xml">
         <search string="Search Invoice Line">
           <group>

=== modified file 'product_historical_margin/invoice.py'
--- product_historical_margin/invoice.py	2012-11-14 15:53:00 +0000
+++ product_historical_margin/invoice.py	2013-10-17 14:57:20 +0000
@@ -41,7 +41,7 @@
     """
     _inherit = 'account.invoice.line'
 
-    def _compute_line_values(self, cr, uid, ids, field_names,  arg, context=None):
+    def _compute_line_values(self, cr, uid, ids, field_names, arg, context=None):
         """
         Compute cost_price, cost_price in company currency and subtotal in company currency
         that will be used for margin analysis. This method is called by the function fields.
@@ -60,24 +60,24 @@
                     float margin_absolute
                     }}
         """
-        if context is None:
-            context = {}
         res = {}
         if not ids:
             return res
         logger = logging.getLogger('product_historical_margin')
         user_obj = self.pool.get('res.users')
-        company_currency_id = user_obj.browse(cr, uid, uid).company_id.currency_id.id
         currency_obj = self.pool.get('res.currency')
+
+        company_currency_id = user_obj.browse(cr, uid, uid, context=context).company_id.currency_id.id
+        fields = [
+                'subtotal_cost_price_company',
+                'subtotal_cost_price',
+                'subtotal_company',
+                'margin_absolute',
+                'margin_relative'
+                ]
         for line_id in ids:
-            res[line_id] = {
-                    'subtotal_cost_price_company': 0.0,
-                    'subtotal_cost_price': 0.0,
-                    'subtotal_company': 0.0,
-                    'margin_absolute': 0.0,
-                    'margin_relative': 0.0,
-                    }
-        for obj in self.browse(cr, uid, ids):
+            res[line_id] = dict.fromkeys(fields, 0.0)
+        for obj in self.browse(cr, uid, ids, context=context):
             product = obj.product_id
             if not product:
                 continue
@@ -114,7 +114,7 @@
                 'subtotal_company': subtotal_company,
                 'margin_absolute': margin_absolute,
                 'margin_relative': margin_relative,
-            }
+                }
             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)
@@ -124,8 +124,6 @@
         return ids
 
     def _recalc_margin_parent(self, cr, uid, ids, context=None):
-        if context is None:
-            context = {}
         res=[]
         for inv in self.browse(cr,uid,ids):
             for line in inv.invoice_line:

=== modified file 'product_historical_margin/product_historical_margin.py'
--- product_historical_margin/product_historical_margin.py	2012-11-14 15:53:00 +0000
+++ product_historical_margin/product_historical_margin.py	2013-10-17 14:57:20 +0000
@@ -30,7 +30,8 @@
 # et ne prendre que les factures paid.
 class product_product(Model):
     _inherit = 'product.product'
-    def _compute_margin(self, cr, uid, ids, field_names,  arg, context):
+
+    def _compute_margin(self, cr, uid, ids, field_names, arg, context=None):
         """
         Compute the absolute and relativ margin based on price without tax, and
         always in company currency. We exclude the (in_invoice, in_refund) from the
@@ -55,15 +56,16 @@
             return res
         user_obj = self.pool.get('res.users')
         logger = logging.getLogger('product_historical_margin')
-        company_id = user_obj.browse(cr, uid, uid).company_id.id
+        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}
             tot_sale[product_id] = 0
         # get information about invoice lines relative to our products
         # belonging to open or paid invoices in the considered period
-        query = '''SELECT product_id, type,
-                          SUM(subtotal_cost_price_company),
-                          SUM(subtotal_company)
+        query = '''
+        SELECT product_id, type,
+              SUM(subtotal_cost_price_company),
+              SUM(subtotal_company)
         FROM account_invoice_line AS line
         INNER JOIN account_invoice AS inv ON (inv.id = line.invoice_id)
         WHERE %s inv.state IN ('open', 'paid')
@@ -75,8 +77,10 @@
           AND SUM(subtotal_company) != 0
         '''
         substs = context.copy()
-        substs['product_ids'] = tuple(res)
-        substs['company_id'] = company_id
+        substs.update(
+            product_ids=tuple(res),
+            company_id=company_id
+            )
         date_clause = []
         if 'from_date' in substs:
             date_clause.append('inv.date_invoice >= %(from_date)s AND')
@@ -87,7 +91,7 @@
         for product_id, inv_type, cost, sale in cr.fetchall():
             res[product_id]['margin_absolute'] += (sale - cost)
             tot_sale[product_id] += sale
-        for product_id in tot_sale.keys():
+        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)
                 res[product_id]['margin_relative'] = 999.
@@ -112,4 +116,3 @@
                                         "based on historical values computed from open and paid invoices."
                                         "If no real margin set, will display 999.0 (if not invoiced yet for example)."),
         }
-

=== modified file 'product_historical_margin/product_view.xml'
--- product_historical_margin/product_view.xml	2013-10-17 14:57:20 +0000
+++ product_historical_margin/product_view.xml	2013-10-17 14:57:20 +0000
@@ -6,11 +6,10 @@
       <field name="name">product_historical_margin.form</field>
       <field name="model">product.product</field>
       <field name="inherit_id" ref='product_standard_margin.sale_markup_product_form'/>
-      <field name="type">form</field>
       <field name="arch" type="xml">
         <field name="standard_margin_rate" position="after">
-          <field name="margin_absolute" />
-          <field name="margin_relative" />
+          <field name="margin_absolute"/>
+          <field name="margin_relative"/>
         </field>
       </field>
     </record>
@@ -18,9 +17,8 @@
     <record id="view_product_historical_margin" model="ir.ui.view">
       <field name="name">product.product.historical_margin.tree</field>
       <field name="model">product.product</field>
-      <field name="type">tree</field>
       <field name="arch" type="xml">
-        <tree string="Historical Margins">
+        <tree string="Historical Margins" create="false">
           <field name="default_code"/>
           <field name="name"/>
           <field name="categ_id" invisible="1"/>

=== modified file 'product_historical_margin/wizard/historical_margin.py'
--- product_historical_margin/wizard/historical_margin.py	2012-12-22 18:35:28 +0000
+++ product_historical_margin/wizard/historical_margin.py	2013-10-17 14:57:20 +0000
@@ -34,7 +34,7 @@
         if context is None: context = {}
         res = False
         if (context.get('active_model', False) == 'product.product' and
-            context.get('active_ids', False)):
+                context.get('active_ids', False)):
             res = context['active_ids']
         return res
 
@@ -60,11 +60,13 @@
         if context is None:
             context = {}
         user_obj = self.pool.get('res.users')
-        company_id = user_obj.browse(cr, uid, uid).company_id.id
-        wiz = self.read(cr, uid, ids, [], context)[0]
+        company_id = user_obj.browse(cr, uid, uid, context=context).company_id.id
+        wiz = self.read(cr, uid, ids, [], context=context)[0]
         ctx = context.copy()
-        ctx['from_date']  = wiz.get('from_date')
-        ctx['to_date'] = wiz.get('to_date')
+        ctx.update(
+            from_date=wiz.get('from_date'),
+            to_date=wiz.get('to_date')
+            )
         product_ids = wiz.get('product_ids')
         data_pool = self.pool.get('ir.model.data')
         filter_ids = data_pool.get_object_reference(cr, uid, 'product',
@@ -79,12 +81,12 @@
         if not product_ids:
             _logger.info('no ids supplied. Computing ids of sold products')
             query = '''SELECT DISTINCT product_id
-        FROM account_invoice_line AS line
-        INNER JOIN account_invoice AS inv ON (inv.id = line.invoice_id)
-        WHERE %s inv.state IN ('open', 'paid')
-          AND type NOT IN ('in_invoice', 'in_refund')
-          AND inv.company_id = %%(company_id)s
-        '''
+                    FROM account_invoice_line AS line
+                    INNER JOIN account_invoice AS inv ON (inv.id = line.invoice_id)
+                    WHERE %s inv.state IN ('open', 'paid')
+                      AND type NOT IN ('in_invoice', 'in_refund')
+                      AND inv.company_id = %%(company_id)s
+                    '''
             date_clause = []
             if 'from_date' in ctx:
                 date_clause.append('inv.date_invoice >= %(from_date)s AND')
@@ -100,7 +102,7 @@
             'type': 'ir.actions.act_window',
             'name': _('Historical Margins'),
             'context': ctx,
-            'domain':domain,
+            'domain': domain,
             'view_type': 'form',
             'view_mode': 'tree',
             'res_model': 'product.product',

=== modified file 'product_historical_margin/wizard/historical_margin_view.xml'
--- product_historical_margin/wizard/historical_margin_view.xml	2013-10-17 14:57:20 +0000
+++ product_historical_margin/wizard/historical_margin_view.xml	2013-10-17 14:57:20 +0000
@@ -4,19 +4,18 @@
     <record id="view_historical_margin" model="ir.ui.view">
       <field name="name">historical.margin.form</field>
       <field name="model">historical.margin</field>
-      <field name="type">form</field>
       <field name="arch" type="xml">
-        <form string="Historical Margin Properties">
-          <group colspan="4">
+        <form string="Historical Margin Properties" version="7.0">
+          <group>
             <field name="from_date" />
             <field name="to_date"/>
             <field name="product_ids" invisible="1"/>
           </group>
-          <separator string="" colspan="4"/>
-          <group colspan="4" col="6">
-            <button icon="gtk-cancel" special="cancel" string="Cancel"/>
-            <button icon="terp-gtk-go-back-rtl" string="Compute margins" name="action_open_window" type="object"/>
-          </group>
+          <footer>
+            <button name="action_open_window" string="Compute margins" type="object" icon="gtk-execute" class="oe_highlight"/>
+            or
+            <button string="Cancel" class="oe_link" special="cancel" />
+          </footer>
         </form>
       </field>
     </record>
@@ -33,7 +32,7 @@
 
     <menuitem icon="STOCK_INDENT" action="action_product_margin_view"
         id="menu_action_product_margin_tree"
-        parent="account.menu_finance_statistic_report_statement" />
+        parent="account.menu_finance_reporting" />
 
 
     <!-- Remove it for right management <act_window name="Product Historical Margins"


Follow ups