Vijaykumar Baladaniya has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-sales-team-on-invoices-vba into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-sales-team-on-invoices-vba/+merge/135680

Hello,

    All changes applied related to task: [Sales Team on Invoices].

Thanks,
 VBA
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-sales-team-on-invoices-vba/+merge/135680
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-sales-team-on-invoices-vba.
=== modified file 'account/report/account_invoice_report.py'
--- account/report/account_invoice_report.py	2012-10-16 05:25:13 +0000
+++ account/report/account_invoice_report.py	2012-11-22 13:23:31 +0000
@@ -102,11 +102,11 @@
         'due_delay': fields.float('Avg. Due Delay', readonly=True, group_operator="avg"),
     }
     _order = 'date desc'
-    def init(self, cr):
-        tools.drop_view_if_exists(cr, 'account_invoice_report')
-        cr.execute("""
-            create or replace view account_invoice_report as (
-                 select min(ail.id) as id,
+
+
+    def _select(self):
+        select_str = """
+            SELECT min(ail.id) as id,
                     ai.date_invoice as date,
                     to_char(ai.date_invoice, 'YYYY') as year,
                     to_char(ai.date_invoice, 'MM') as month,
@@ -183,15 +183,30 @@
                          where a.id=ai.id)
                        ELSE 1
                        END) / cr.rate as residual
-                from account_invoice_line as ail
+        """
+        return select_str
+
+    def _where(self):
+        where_str = """
+            WHERE cr.id in (select id from res_currency_rate cr2  where (cr2.currency_id = ai.currency_id)
+                and ((ai.date_invoice is not null and cr.name <= ai.date_invoice) or (ai.date_invoice is null and cr.name <= NOW())) order by name desc limit 1)
+        """
+        return where_str
+
+    def _from(self):
+        from_str = """
+            FROM account_invoice_line as ail
                 left join account_invoice as ai ON (ai.id=ail.invoice_id)
                 left join product_product pr on (pr.id=ail.product_id)
                 left join product_template pt on (pt.id=pr.product_tmpl_id)
                 left join product_uom u on (u.id=ail.uos_id),
                 res_currency_rate cr
-                where cr.id in (select id from res_currency_rate cr2  where (cr2.currency_id = ai.currency_id)
-                and ((ai.date_invoice is not null and cr.name <= ai.date_invoice) or (ai.date_invoice is null and cr.name <= NOW())) order by name desc limit 1)
-                group by ail.product_id,
+        """
+        return from_str
+
+    def _group_by(self):
+        group_by_str = """
+            GROUP BY ail.product_id,
                     ai.date_invoice,
                     ai.id,
                     cr.rate,
@@ -218,8 +233,15 @@
                     ai.amount_total,
                     u.uom_type,
                     u.category_id
-            )
-        """)
+        """
+        return group_by_str
+
+    def init(self, cr):
+        # self._table = account_invoice_report
+        tools.drop_view_if_exists(cr, self._table)
+        cr.execute("CREATE or REPLACE VIEW %s as (%s %s %s %s)" % (
+                    self._table, 
+                    self._select(), self._from(), self._where(), self._group_by()))
 
 account_invoice_report()
 

=== modified file 'sale_crm/__init__.py'
--- sale_crm/__init__.py	2012-03-05 18:40:03 +0000
+++ sale_crm/__init__.py	2012-11-22 13:23:31 +0000
@@ -21,5 +21,6 @@
 
 import wizard
 import sale_crm
+import report
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'sale_crm/__openerp__.py'
--- sale_crm/__openerp__.py	2012-10-24 08:58:42 +0000
+++ sale_crm/__openerp__.py	2012-11-22 13:23:31 +0000
@@ -43,7 +43,8 @@
         'sale_crm_view.xml',
         'process/sale_crm_process.xml',
         'security/sale_crm_security.xml',
-        'security/ir.model.access.csv'
+        'security/ir.model.access.csv',
+        'report/sale_crm_account_invoice_report_view.xml',
     ],
     'demo': [],
     'test': ['test/sale_crm.yml'],

=== added directory 'sale_crm/report'
=== added file 'sale_crm/report/__init__.py'
--- sale_crm/report/__init__.py	1970-01-01 00:00:00 +0000
+++ sale_crm/report/__init__.py	2012-11-22 13:23:31 +0000
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import sales_crm_account_invoice_report
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+

=== added file 'sale_crm/report/sale_crm_account_invoice_report_view.xml'
--- sale_crm/report/sale_crm_account_invoice_report_view.xml	1970-01-01 00:00:00 +0000
+++ sale_crm/report/sale_crm_account_invoice_report_view.xml	2012-11-22 13:23:31 +0000
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+<data>
+
+    <!-- Update account invoice !-->
+    <record model="ir.ui.view" id="account_invoice_report_tree">
+        <field name="name">account.invoice.report.tree</field>
+        <field name="model">account.invoice.report</field>
+        <field name="inherit_id" ref="account.view_account_invoice_report_tree"/>
+        <field name="arch" type="xml">
+            <data>
+                <xpath expr="//field[@name='date']" position="after">
+                    <field name="section_id"/>
+                </xpath>
+            </data>
+        </field>
+    </record>
+
+</data>
+</openerp>

=== added file 'sale_crm/report/sales_crm_account_invoice_report.py'
--- sale_crm/report/sales_crm_account_invoice_report.py	1970-01-01 00:00:00 +0000
+++ sale_crm/report/sales_crm_account_invoice_report.py	2012-11-22 13:23:31 +0000
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from osv import fields,osv
+
+class account_invoice_report(osv.osv):
+    _inherit = 'account.invoice.report'
+    _columns = {
+        'section_id': fields.many2one('crm.case.section', 'Sales Team'),
+    }
+
+    def _select(self):
+        return  super(account_invoice_report, self)._select() + ", ai.section_id as section_id"
+
+    def _group_by(self):
+        return super(account_invoice_report, self)._group_by() + ", ai.section_id"
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'sale_crm/sale_crm.py'
--- sale_crm/sale_crm.py	2012-09-27 19:10:59 +0000
+++ sale_crm/sale_crm.py	2012-11-22 13:23:31 +0000
@@ -46,4 +46,39 @@
 
 sale_order()
 
+class res_users(osv.Model):
+    _inherit = 'res.users'
+
+    _columns = {
+        'default_section_id': fields.many2one('crm.case.section', 'Default Sales Team'),
+    }
+
+res_users()
+
+class account_invoice(osv.osv):
+    _inherit = 'account.invoice'
+
+    _columns = {
+        'section_id': fields.many2one('crm.case.section', 'Sales Team'),
+    }
+
+    _defaults = {
+        'section_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).default_section_id.id,
+    }
+
+    def create(self, cr, uid, vals, context=None):
+        if context is None:
+            context = {}
+        section_id = vals.get('section_id', False)
+        invoice_type = context.get('type', False)
+        user_id = vals.get('user_id', False)
+        user_obj = self.pool.get('res.users').browse(cr, uid, user_id, context=context)
+        if not section_id and invoice_type in ['out_invoice', 'out_refund'] and user_id and user_obj.default_section_id:
+            vals['section_id'] = user_obj.default_section_id.id
+        obj_id =  super(account_invoice, self).create(cr, uid, vals, context=context)
+        return obj_id
+
+
+account_invoice()
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'sale_crm/sale_crm_view.xml'
--- sale_crm/sale_crm_view.xml	2012-10-10 19:43:25 +0000
+++ sale_crm/sale_crm_view.xml	2012-11-22 13:23:31 +0000
@@ -46,5 +46,72 @@
             </field>
         </record>
 
+        <!-- Update account invoice list view!-->
+        <record model="ir.ui.view" id="account_invoice_tree">
+            <field name="name">Account Invoice</field>
+            <field name="model">account.invoice</field>
+            <field name="inherit_id" ref="account.invoice_tree"/>
+            <field name="arch" type="xml">
+                <data>
+                    <xpath expr="//field[@name='date_invoice']" position="after">
+                        <field name="section_id" invisible="1"/>
+                    </xpath>
+                </data>
+            </field>
+        </record>
+
+        <record id="account_invoice_groupby_inherit" model="ir.ui.view">
+            <field name="name">account.invoice.groupby</field>
+            <field name="model">account.invoice</field>
+            <field name="inherit_id" ref="account.view_account_invoice_filter"/>
+            <field name="arch" type="xml">
+                <xpath expr="//group/filter[@string='Due Date']" position="after">
+                    <filter string="Sales Team" icon="terp-partner" domain="[]" context="{'group_by':'section_id'}"/>
+                </xpath>
+            </field>
+        </record>
+
+        <!-- Update account invoice !-->
+        <record model="ir.ui.view" id="account_invoice_form">
+            <field name="name">Account Invoice</field>
+            <field name="model">account.invoice</field>
+            <field name="inherit_id" ref="account.invoice_form"/>
+            <field name="arch" type="xml">
+                <data>
+                    <xpath expr="//field[@name='user_id']" position="after">
+                        <field name="section_id"/>
+                    </xpath>
+                </data>
+            </field>
+        </record>
+
+        <!-- Update user form !-->
+        <record model="ir.ui.view" id="res_user_form">
+            <field name="name">Users Preferences</field>
+            <field name="model">res.users</field>
+            <field name="inherit_id" ref="base.view_users_form"/>
+            <field name="arch" type="xml">
+                <data>
+                    <xpath expr="//field[@name='email']" position="after">
+                        <field name="default_section_id"/>
+                    </xpath>
+                </data>
+            </field>
+        </record>
+
+        <!-- Update Preferences form !-->
+        <record id="view_users_form_preferences" model="ir.ui.view">
+            <field name="name">res.users.preferences.form</field>
+            <field name="model">res.users</field>
+            <field name="inherit_id" ref="base.view_users_form_simple_modif"/>
+            <field name="arch" type="xml">
+            <data>
+                    <xpath expr="//field[@name='company_id']" position="after">
+                        <field name="default_section_id"/>
+                    </xpath>
+                </data>
+            </field>
+        </record>
+
     </data>
 </openerp>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : openerp-dev-gtk@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to