Merge lp:~camptocamp/department-mgmt/7.0-port-sale_department into lp:~department-core-editors/department-mgmt/7.0
- 7.0-port-sale_department
- Merge into 7.0
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Reis | tested install, no errors. | Approve | |
Nhomar - Vauxoo | Approve | ||
Review via email: mp+170248@code.launchpad.net |
Commit message
Description of the change
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.
<record id="invoice_form" model="ir.ui.view">
<field name="name"
<field name="model"
<field name="inherit_id" ref="account.
<field name="arch" type="xml">
<field name="company_id" position="before">
<field name="departmen
</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!
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_
- comment invoice_
- launch OpenERP with --update=all
- uncomment view in portal_sale
- launch OpenERP with --update=
- uncomment view in invoice_department
- launch OpenERP with --update=
I guess this is due to some OpenERP bug in view inheritance...
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.
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...
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.
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
1 | === modified file 'sale_department/__init__.py' |
2 | --- sale_department/__init__.py 2011-08-12 12:53:16 +0000 |
3 | +++ sale_department/__init__.py 2013-06-19 06:55:30 +0000 |
4 | @@ -1,7 +1,7 @@ |
5 | # -*- coding: utf-8 -*- |
6 | ############################################################################## |
7 | # |
8 | -# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com) |
9 | +# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com) |
10 | # All Right Reserved |
11 | # |
12 | # Author : Joel Grand-guillaume (Camptocamp) |
13 | @@ -30,3 +30,5 @@ |
14 | ############################################################################## |
15 | |
16 | import sale |
17 | + |
18 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
19 | \ No newline at end of file |
20 | |
21 | === modified file 'sale_department/__openerp__.py' |
22 | --- sale_department/__openerp__.py 2013-01-04 10:32:58 +0000 |
23 | +++ sale_department/__openerp__.py 2013-06-19 06:55:30 +0000 |
24 | @@ -1,55 +1,42 @@ |
25 | # -*- coding: utf-8 -*- |
26 | ############################################################################## |
27 | # |
28 | -# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com) |
29 | -# All Right Reserved |
30 | -# |
31 | -# Author : Joel Grand-guillaume (Camptocamp) |
32 | -# |
33 | -# WARNING: This program as such is intended to be used by professional |
34 | -# programmers who take the whole responsability of assessing all potential |
35 | -# consequences resulting from its eventual inadequacies and bugs |
36 | -# End users who are looking for a ready-to-use solution with commercial |
37 | -# garantees and support are strongly adviced to contract a Free Software |
38 | -# Service Company |
39 | -# |
40 | -# This program is Free Software; you can redistribute it and/or |
41 | -# modify it under the terms of the GNU General Public License |
42 | -# as published by the Free Software Foundation; either version 2 |
43 | -# of the License, or (at your option) any later version. |
44 | -# |
45 | -# This program is distributed in the hope that it will be useful, |
46 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
47 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
48 | -# GNU General Public License for more details. |
49 | -# |
50 | -# You should have received a copy of the GNU General Public License |
51 | -# along with this program; if not, write to the Free Software |
52 | -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
53 | +# Author: Joël Grand-guillaume (Camptocamp) |
54 | +# Copyright 2011 Camptocamp SA |
55 | +# |
56 | +# This program is free software: you can redistribute it and/or modify |
57 | +# it under the terms of the GNU Affero General Public License as |
58 | +# published by the Free Software Foundation, either version 3 of the |
59 | +# License, or (at your option) any later version. |
60 | +# |
61 | +# This program is distributed in the hope that it will be useful, |
62 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
63 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
64 | +# GNU Affero General Public License for more details. |
65 | +# |
66 | +# You should have received a copy of the GNU Affero General Public License |
67 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
68 | # |
69 | ############################################################################## |
70 | - |
71 | { |
72 | - "name" : "Sales Order with Department Categorization", |
73 | - "version" : "1.0", |
74 | - "author" : "Camptocamp", |
75 | - "category" : "Generic Modules/Sales & Purchases", |
76 | - "description": |
77 | -""" |
78 | + 'name' : 'Sales Order with Department Categorization', |
79 | + 'version' : '1.0', |
80 | + 'category' : 'Generic Modules/Sales & Purchases', |
81 | + 'description': |
82 | +''' |
83 | Add the department on Sales Order and Customer Invoices as well as the related filter and button in the search form. |
84 | - |
85 | -""", |
86 | - "website": "http://camptocamp.com", |
87 | - "depends" : [ |
88 | - "sale", |
89 | - "invoice_department", |
90 | - "hr" |
91 | - ], |
92 | - "init_xml" : [], |
93 | - "demo_xml" : [], |
94 | - "update_xml" : [ |
95 | - "sale_view.xml", |
96 | + |
97 | +''', |
98 | + 'author' : 'Camptocamp', |
99 | + 'website': 'http://camptocamp.com', |
100 | + 'depends' : ['sale', 'invoice_department', 'hr'], |
101 | + 'data' : [ |
102 | + 'sale_view.xml', |
103 | ], |
104 | - "active": False, |
105 | - 'installable': False |
106 | + 'demo' : [], |
107 | + 'installable': True, |
108 | + 'auto_install': False, |
109 | + 'application': False, |
110 | } |
111 | + |
112 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
113 | |
114 | === modified file 'sale_department/sale.py' |
115 | --- sale_department/sale.py 2011-08-12 12:53:16 +0000 |
116 | +++ sale_department/sale.py 2013-06-19 06:55:30 +0000 |
117 | @@ -1,51 +1,57 @@ |
118 | # -*- coding: utf-8 -*- |
119 | ############################################################################## |
120 | # |
121 | -# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) |
122 | -# All Right Reserved |
123 | -# |
124 | -# Author : Joel Grand-guillaume (Camptocamp) |
125 | -# |
126 | -# WARNING: This program as such is intended to be used by professional |
127 | -# programmers who take the whole responsability of assessing all potential |
128 | -# consequences resulting from its eventual inadequacies and bugs |
129 | -# End users who are looking for a ready-to-use solution with commercial |
130 | -# garantees and support are strongly adviced to contract a Free Software |
131 | -# Service Company |
132 | -# |
133 | -# This program is Free Software; you can redistribute it and/or |
134 | -# modify it under the terms of the GNU General Public License |
135 | -# as published by the Free Software Foundation; either version 2 |
136 | -# of the License, or (at your option) any later version. |
137 | -# |
138 | -# This program is distributed in the hope that it will be useful, |
139 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
140 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
141 | -# GNU General Public License for more details. |
142 | -# |
143 | -# You should have received a copy of the GNU General Public License |
144 | -# along with this program; if not, write to the Free Software |
145 | -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
146 | +# Author: Joël Grand-guillaume (Camptocamp) |
147 | +# Copyright 2010 Camptocamp SA |
148 | +# |
149 | +# This program is free software: you can redistribute it and/or modify |
150 | +# it under the terms of the GNU Affero General Public License as |
151 | +# published by the Free Software Foundation, either version 3 of the |
152 | +# License, or (at your option) any later version. |
153 | +# |
154 | +# This program is distributed in the hope that it will be useful, |
155 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
156 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
157 | +# GNU Affero General Public License for more details. |
158 | +# |
159 | +# You should have received a copy of the GNU Affero General Public License |
160 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
161 | # |
162 | ############################################################################## |
163 | - |
164 | -from osv import osv |
165 | -from osv import fields |
166 | - |
167 | -class sale_order(osv.osv): |
168 | - _inherit = "sale.order" |
169 | - |
170 | +from openerp.osv import orm, fields |
171 | + |
172 | +class SaleOrder(orm.Model): |
173 | + _inherit = 'sale.order' |
174 | _columns = { |
175 | 'department_id': fields.many2one('hr.department', 'Department'), |
176 | - } |
177 | + } |
178 | + |
179 | + def _get_department(self, cr, uid, ids, context=None): |
180 | + employee_obj = self.pool.get('hr.employee') |
181 | + department_id = False |
182 | + employee_ids = employee_obj.search( |
183 | + cr, uid, |
184 | + [('user_id','=', uid)], |
185 | + context=context) |
186 | + if employee_ids: |
187 | + department_id = employee_obj.browse( |
188 | + cr, uid, employee_ids[0], |
189 | + context=context).department_id.id |
190 | + return department_id |
191 | + |
192 | _defaults = { |
193 | - 'department_id': lambda s,cr,uid,c: s.pool.get('res.users').browse(cr,uid,uid).context_department_id.id, |
194 | - } |
195 | - |
196 | + 'department_id': _get_department, |
197 | + } |
198 | + |
199 | def _make_invoice(self, cr, uid, order, lines, context=None): |
200 | - res = super(sale_order,self)._make_invoice(cr,uid,order,lines,context) |
201 | - self.pool.get('account.invoice').write(cr,uid,res,{'department_id':order.department_id.id},context) |
202 | + invoice_obj = self.pool.get('account.invoice') |
203 | + res = super(SaleOrder, self)._make_invoice( |
204 | + cr, uid, order, |
205 | + lines, context=context) |
206 | + invoice_obj.write( |
207 | + cr, uid, res, |
208 | + {'department_id': order.department_id.id}, |
209 | + context=context) |
210 | return res |
211 | - |
212 | |
213 | -sale_order() |
214 | \ No newline at end of file |
215 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
216 | |
217 | === modified file 'sale_department/sale_view.xml' (properties changed: +x to -x) |
218 | --- sale_department/sale_view.xml 2011-08-12 12:53:16 +0000 |
219 | +++ sale_department/sale_view.xml 2013-06-19 06:55:30 +0000 |
220 | @@ -1,45 +1,53 @@ |
221 | +<?xml version="1.0" encoding="utf-8"?> |
222 | <openerp> |
223 | - <data> |
224 | - |
225 | - <record id="view_order_tree" model="ir.ui.view"> |
226 | - <field name="name">sale.order.tree</field> |
227 | - <field name="model">sale.order</field> |
228 | - <field name="type">tree</field> |
229 | - <field name="inherit_id" ref="sale.view_order_tree" /> |
230 | - <field name="arch" type="xml"> |
231 | - <xpath expr="/tree/field[@name='user_id']" position="after"> |
232 | - <field name="department_id" /> |
233 | - </xpath> |
234 | - </field> |
235 | - </record> |
236 | - |
237 | - <record id="view_order_form" model="ir.ui.view"> |
238 | - <field name="name">sale.order.form</field> |
239 | - <field name="model">sale.order</field> |
240 | - <field name="type">form</field> |
241 | - <field name="inherit_id" ref="sale.view_order_form" /> |
242 | - <field name="arch" type="xml"> |
243 | - <xpath expr="/form/notebook/page[@string='Other Information']/group/field[@name='user_id']" position="after"> |
244 | - <field name="department_id" widget="selection"/> |
245 | - </xpath> |
246 | - </field> |
247 | - </record> |
248 | - |
249 | - <record id="view_sales_order_filter" model="ir.ui.view"> |
250 | - <field name="name">sale.order.list.select</field> |
251 | - <field name="model">sale.order</field> |
252 | - <field name="type">search</field> |
253 | - <field name="inherit_id" ref="sale.view_sales_order_filter" /> |
254 | - <field name="arch" type="xml"> |
255 | - <xpath expr="/search/group/filter[@string='Salesman']" position="after"> |
256 | - <filter string="Department" icon="terp-folder-orange" domain="[]" context="{'group_by':'department_id'}"/> |
257 | - </xpath> |
258 | - <xpath expr="/search/field[@name='partner_id']" position="after"> |
259 | - <field name="department_id" select="1" widget="selection"/> |
260 | - </xpath> |
261 | - </field> |
262 | - </record> |
263 | - |
264 | - |
265 | - </data> |
266 | -</openerp> |
267 | \ No newline at end of file |
268 | + <data> |
269 | + |
270 | + <record id="view_quotation_tree" model="ir.ui.view"> |
271 | + <field name="name">sale.order.tree</field> |
272 | + <field name="model">sale.order</field> |
273 | + <field name="inherit_id" ref="sale.view_quotation_tree" /> |
274 | + <field name="arch" type="xml"> |
275 | + <field name="user_id" position="after"> |
276 | + <field name="department_id" /> |
277 | + </field> |
278 | + </field> |
279 | + </record> |
280 | + |
281 | + <record id="view_order_tree" model="ir.ui.view"> |
282 | + <field name="name">sale.order.tree</field> |
283 | + <field name="model">sale.order</field> |
284 | + <field name="inherit_id" ref="sale.view_order_tree" /> |
285 | + <field name="arch" type="xml"> |
286 | + <field name="user_id" position="after"> |
287 | + <field name="department_id" /> |
288 | + </field> |
289 | + </field> |
290 | + </record> |
291 | + |
292 | + <record id="view_order_form" model="ir.ui.view"> |
293 | + <field name="name">sale.order.form</field> |
294 | + <field name="model">sale.order</field> |
295 | + <field name="inherit_id" ref="sale.view_order_form" /> |
296 | + <field name="arch" type="xml"> |
297 | + <field name="user_id" position="after"> |
298 | + <field name="department_id" widget="selection"/> |
299 | + </field> |
300 | + </field> |
301 | + </record> |
302 | + |
303 | + <record id="view_sales_order_filter" model="ir.ui.view"> |
304 | + <field name="name">sale.order.list.select</field> |
305 | + <field name="model">sale.order</field> |
306 | + <field name="inherit_id" ref="sale.view_sales_order_filter" /> |
307 | + <field name="arch" type="xml"> |
308 | + <xpath expr="//filter[@string='Salesperson']" position="after"> |
309 | + <filter string="Department" icon="terp-folder-orange" domain="[]" context="{'group_by':'department_id'}"/> |
310 | + </xpath> |
311 | + <field name="partner_id" position="after"> |
312 | + <field name="department_id" widget="selection"/> |
313 | + </field> |
314 | + </field> |
315 | + </record> |
316 | + |
317 | + </data> |
318 | +</openerp> |
Approve.
Just Code Review. No test.