Merge lp:~camptocamp/department-mgmt/7.0-port-sale_department into lp:~department-core-editors/department-mgmt/7.0

Proposed by Yannick Vaucher @ Camptocamp
Status: Merged
Approved by: Daniel Reis
Approved revision: 18
Merged at revision: 15
Proposed branch: lp:~camptocamp/department-mgmt/7.0-port-sale_department
Merge into: lp:~department-core-editors/department-mgmt/7.0
Diff against target: 318 lines (+134/-131)
4 files modified
sale_department/__init__.py (+3/-1)
sale_department/__openerp__.py (+33/-46)
sale_department/sale.py (+46/-40)
sale_department/sale_view.xml (+52/-44)
To merge this branch: bzr merge lp:~camptocamp/department-mgmt/7.0-port-sale_department
Reviewer Review Type Date Requested Status
Daniel Reis tested install, no errors. Approve
Nhomar - Vauxoo Approve
Review via email: mp+170248@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Nhomar - Vauxoo (nhomar) wrote :

Approve.

Just Code Review. No test.

review: Approve
Revision history for this message
Daniel Reis (dreis-pt) wrote :

Hmmm ... my tests return an error message when installing.
Maybe this happens because I don't have multicompany installed?

2013-07-15 16:57:25,471 26929 ERROR dept7-dev openerp.tools.convert: Parse error in /opt/openerp/dept7/dev/department-mgmt/invoice_department/invoice_view.xml:16:
<record id="invoice_form" model="ir.ui.view">
      <field name="name">account.invoice.form</field>
      <field name="model">account.invoice</field>
      <field name="inherit_id" ref="account.invoice_form"/>
      <field name="arch" type="xml">
        <field name="company_id" position="before">
          <field name="department_id" widget="selection"/>
        </field>
      </field>
    </record>
(...)
2013-07-15 16:57:25,475 26929 ERROR dept7-dev openerp.netsvc: ValidateError
Error occurred while validating the field(s) arch: Invalid XML for View Architecture!

review: Needs Information
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

This issue doesn't seems to come from sale_department but from its dependency invoice_department which conflicts with portal_sale (auto installed with portal and sale thus with sale_department).

To complete install of sale_department from scratch I had to do those steps:

- comment invoice_form and invoice_supplier_form in invoice_department/invoice_view.xml
- comment invoice_form_payment in portal_sale/portal_sale_view.xml
- launch OpenERP with --update=all
- uncomment view in portal_sale
- launch OpenERP with --update=portal_sale
- uncomment view in invoice_department
- launch OpenERP with --update=invoice_department

I guess this is due to some OpenERP bug in view inheritance...

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Somehow, on update of portal_sale, it uses some cached view trying to read department_id before it has been defined by invoice_department.

We cannot make invoice_department depending on portal_sale as it doesn't make sense. Let's see if a new bug report on view inheritance bring us some solution to this.

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Finally it seems it is simply in invoice_department that we try to add the field department_id before company_id of invoice line instead of doing it before the company_id of invoice. Funny I could install invoice_department anyway...

Revision history for this message
Daniel Reis (dreis-pt) wrote :

As a suggestion for future improvement:
From a usability PoV, the widget "selection" is only appropriate for small lists of items (less than a handfull).
In this case, when the Department list grows significantly (in my case, many dozens of records) it gets harder to use.
So, the default v7 search-as-you-type list widget will probably be more adequate here.

review: Approve (tested install, no errors.)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Thanks for the review.

You are right using completion instead of selection makes sense with dozens of departments.
I kept it like this as we haven't such case with that many departments but to be more generic it would be a good improvement.

Actually we have half of department-mgmt using selection and half using default completion.

So we will have to change it in the following modules:
crm_department
invoice_department
sale_department

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'sale_department/__init__.py'
--- sale_department/__init__.py 2011-08-12 12:53:16 +0000
+++ sale_department/__init__.py 2013-06-19 06:55:30 +0000
@@ -1,7 +1,7 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2##############################################################################2##############################################################################
3#3#
4# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com) 4# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com)
5# All Right Reserved5# All Right Reserved
6#6#
7# Author : Joel Grand-guillaume (Camptocamp)7# Author : Joel Grand-guillaume (Camptocamp)
@@ -30,3 +30,5 @@
30##############################################################################30##############################################################################
3131
32import sale32import sale
33
34# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
33\ No newline at end of file35\ No newline at end of file
3436
=== modified file 'sale_department/__openerp__.py'
--- sale_department/__openerp__.py 2013-01-04 10:32:58 +0000
+++ sale_department/__openerp__.py 2013-06-19 06:55:30 +0000
@@ -1,55 +1,42 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2##############################################################################2##############################################################################
3#3#
4# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com) 4# Author: Joël Grand-guillaume (Camptocamp)
5# All Right Reserved5# Copyright 2011 Camptocamp SA
6#6#
7# Author : Joel Grand-guillaume (Camptocamp)7# This program is free software: you can redistribute it and/or modify
8#8# it under the terms of the GNU Affero General Public License as
9# WARNING: This program as such is intended to be used by professional9# published by the Free Software Foundation, either version 3 of the
10# programmers who take the whole responsability of assessing all potential10# License, or (at your option) any later version.
11# consequences resulting from its eventual inadequacies and bugs11#
12# End users who are looking for a ready-to-use solution with commercial12# This program is distributed in the hope that it will be useful,
13# garantees and support are strongly adviced to contract a Free Software13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# Service Company14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15#15# GNU Affero General Public License for more details.
16# This program is Free Software; you can redistribute it and/or16#
17# modify it under the terms of the GNU General Public License17# You should have received a copy of the GNU Affero General Public License
18# as published by the Free Software Foundation; either version 218# along with this program. If not, see <http://www.gnu.org/licenses/>.
19# of the License, or (at your option) any later version.
20#
21# This program is distributed in the hope that it will be useful,
22# but WITHOUT ANY WARRANTY; without even the implied warranty of
23# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24# GNU General Public License for more details.
25#
26# You should have received a copy of the GNU General Public License
27# along with this program; if not, write to the Free Software
28# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29#19#
30##############################################################################20##############################################################################
31
32{21{
33 "name" : "Sales Order with Department Categorization",22 'name' : 'Sales Order with Department Categorization',
34 "version" : "1.0",23 'version' : '1.0',
35 "author" : "Camptocamp",24 'category' : 'Generic Modules/Sales & Purchases',
36 "category" : "Generic Modules/Sales & Purchases",25 'description':
37 "description":26'''
38"""
39 Add the department on Sales Order and Customer Invoices as well as the related filter and button in the search form.27 Add the department on Sales Order and Customer Invoices as well as the related filter and button in the search form.
40 28
41""",29''',
42 "website": "http://camptocamp.com",30 'author' : 'Camptocamp',
43 "depends" : [31 'website': 'http://camptocamp.com',
44 "sale",32 'depends' : ['sale', 'invoice_department', 'hr'],
45 "invoice_department",33 'data' : [
46 "hr"34 'sale_view.xml',
47 ],
48 "init_xml" : [],
49 "demo_xml" : [],
50 "update_xml" : [
51 "sale_view.xml",
52 ],35 ],
53 "active": False,36 'demo' : [],
54 'installable': False37 'installable': True,
38 'auto_install': False,
39 'application': False,
55}40}
41
42# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
5643
=== modified file 'sale_department/sale.py'
--- sale_department/sale.py 2011-08-12 12:53:16 +0000
+++ sale_department/sale.py 2013-06-19 06:55:30 +0000
@@ -1,51 +1,57 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2##############################################################################2##############################################################################
3#3#
4# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) 4# Author: Joël Grand-guillaume (Camptocamp)
5# All Right Reserved5# Copyright 2010 Camptocamp SA
6#6#
7# Author : Joel Grand-guillaume (Camptocamp)7# This program is free software: you can redistribute it and/or modify
8#8# it under the terms of the GNU Affero General Public License as
9# WARNING: This program as such is intended to be used by professional9# published by the Free Software Foundation, either version 3 of the
10# programmers who take the whole responsability of assessing all potential10# License, or (at your option) any later version.
11# consequences resulting from its eventual inadequacies and bugs11#
12# End users who are looking for a ready-to-use solution with commercial12# This program is distributed in the hope that it will be useful,
13# garantees and support are strongly adviced to contract a Free Software13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# Service Company14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15#15# GNU Affero General Public License for more details.
16# This program is Free Software; you can redistribute it and/or16#
17# modify it under the terms of the GNU General Public License17# You should have received a copy of the GNU Affero General Public License
18# as published by the Free Software Foundation; either version 218# along with this program. If not, see <http://www.gnu.org/licenses/>.
19# of the License, or (at your option) any later version.
20#
21# This program is distributed in the hope that it will be useful,
22# but WITHOUT ANY WARRANTY; without even the implied warranty of
23# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24# GNU General Public License for more details.
25#
26# You should have received a copy of the GNU General Public License
27# along with this program; if not, write to the Free Software
28# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29#19#
30##############################################################################20##############################################################################
3121from openerp.osv import orm, fields
32from osv import osv22
33from osv import fields23class SaleOrder(orm.Model):
3424 _inherit = 'sale.order'
35class sale_order(osv.osv):
36 _inherit = "sale.order"
37
38 _columns = {25 _columns = {
39 'department_id': fields.many2one('hr.department', 'Department'),26 'department_id': fields.many2one('hr.department', 'Department'),
40 }27 }
28
29 def _get_department(self, cr, uid, ids, context=None):
30 employee_obj = self.pool.get('hr.employee')
31 department_id = False
32 employee_ids = employee_obj.search(
33 cr, uid,
34 [('user_id','=', uid)],
35 context=context)
36 if employee_ids:
37 department_id = employee_obj.browse(
38 cr, uid, employee_ids[0],
39 context=context).department_id.id
40 return department_id
41
41 _defaults = {42 _defaults = {
42 'department_id': lambda s,cr,uid,c: s.pool.get('res.users').browse(cr,uid,uid).context_department_id.id,43 'department_id': _get_department,
43 }44 }
44 45
45 def _make_invoice(self, cr, uid, order, lines, context=None):46 def _make_invoice(self, cr, uid, order, lines, context=None):
46 res = super(sale_order,self)._make_invoice(cr,uid,order,lines,context)47 invoice_obj = self.pool.get('account.invoice')
47 self.pool.get('account.invoice').write(cr,uid,res,{'department_id':order.department_id.id},context)48 res = super(SaleOrder, self)._make_invoice(
49 cr, uid, order,
50 lines, context=context)
51 invoice_obj.write(
52 cr, uid, res,
53 {'department_id': order.department_id.id},
54 context=context)
48 return res55 return res
49
5056
51sale_order()
52\ No newline at end of file57\ No newline at end of file
58# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
5359
=== modified file 'sale_department/sale_view.xml' (properties changed: +x to -x)
--- sale_department/sale_view.xml 2011-08-12 12:53:16 +0000
+++ sale_department/sale_view.xml 2013-06-19 06:55:30 +0000
@@ -1,45 +1,53 @@
1<?xml version="1.0" encoding="utf-8"?>
1<openerp>2<openerp>
2 <data>
3
4 <record id="view_order_tree" model="ir.ui.view">
5 <field name="name">sale.order.tree</field>
6 <field name="model">sale.order</field>
7 <field name="type">tree</field>
8 <field name="inherit_id" ref="sale.view_order_tree" />
9 <field name="arch" type="xml">
10 <xpath expr="/tree/field[@name='user_id']" position="after">
11 <field name="department_id" />
12 </xpath>
13 </field>
14 </record>
15
16 <record id="view_order_form" model="ir.ui.view">
17 <field name="name">sale.order.form</field>
18 <field name="model">sale.order</field>
19 <field name="type">form</field>
20 <field name="inherit_id" ref="sale.view_order_form" />
21 <field name="arch" type="xml">
22 <xpath expr="/form/notebook/page[@string='Other Information']/group/field[@name='user_id']" position="after">
23 <field name="department_id" widget="selection"/>
24 </xpath>
25 </field>
26 </record>
27
28 <record id="view_sales_order_filter" model="ir.ui.view">
29 <field name="name">sale.order.list.select</field>
30 <field name="model">sale.order</field>
31 <field name="type">search</field>
32 <field name="inherit_id" ref="sale.view_sales_order_filter" />
33 <field name="arch" type="xml">
34 <xpath expr="/search/group/filter[@string='Salesman']" position="after">
35 <filter string="Department" icon="terp-folder-orange" domain="[]" context="{'group_by':'department_id'}"/>
36 </xpath>
37 <xpath expr="/search/field[@name='partner_id']" position="after">
38 <field name="department_id" select="1" widget="selection"/>
39 </xpath>
40 </field>
41 </record>
42
43
44 </data>
45</openerp>
46\ No newline at end of file3\ No newline at end of file
4 <data>
5
6 <record id="view_quotation_tree" model="ir.ui.view">
7 <field name="name">sale.order.tree</field>
8 <field name="model">sale.order</field>
9 <field name="inherit_id" ref="sale.view_quotation_tree" />
10 <field name="arch" type="xml">
11 <field name="user_id" position="after">
12 <field name="department_id" />
13 </field>
14 </field>
15 </record>
16
17 <record id="view_order_tree" model="ir.ui.view">
18 <field name="name">sale.order.tree</field>
19 <field name="model">sale.order</field>
20 <field name="inherit_id" ref="sale.view_order_tree" />
21 <field name="arch" type="xml">
22 <field name="user_id" position="after">
23 <field name="department_id" />
24 </field>
25 </field>
26 </record>
27
28 <record id="view_order_form" model="ir.ui.view">
29 <field name="name">sale.order.form</field>
30 <field name="model">sale.order</field>
31 <field name="inherit_id" ref="sale.view_order_form" />
32 <field name="arch" type="xml">
33 <field name="user_id" position="after">
34 <field name="department_id" widget="selection"/>
35 </field>
36 </field>
37 </record>
38
39 <record id="view_sales_order_filter" model="ir.ui.view">
40 <field name="name">sale.order.list.select</field>
41 <field name="model">sale.order</field>
42 <field name="inherit_id" ref="sale.view_sales_order_filter" />
43 <field name="arch" type="xml">
44 <xpath expr="//filter[@string='Salesperson']" position="after">
45 <filter string="Department" icon="terp-folder-orange" domain="[]" context="{'group_by':'department_id'}"/>
46 </xpath>
47 <field name="partner_id" position="after">
48 <field name="department_id" widget="selection"/>
49 </field>
50 </field>
51 </record>
52
53 </data>
54</openerp>

Subscribers

People subscribed via source and target branches