Merge lp:~akretion-team/project-service/project-service-base-sale-project into lp:~project-core-editors/project-service/trunk
- project-service-base-sale-project
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 32 |
Proposed branch: | lp:~akretion-team/project-service/project-service-base-sale-project |
Merge into: | lp:~project-core-editors/project-service/trunk |
Diff against target: |
272 lines (+241/-0) 6 files modified
sale_project_base/__init__.py (+26/-0) sale_project_base/__openerp__.py (+43/-0) sale_project_base/i18n/sale_project_base.po (+38/-0) sale_project_base/project.py (+37/-0) sale_project_base/sale.py (+69/-0) sale_project_base/sale_view.xml (+28/-0) |
To merge this branch: | bzr merge lp:~akretion-team/project-service/project-service-base-sale-project |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Reis | lgtm, no test | Approve | |
Pedro Manuel Baeza | code review | Approve | |
Review via email: mp+211960@code.launchpad.net |
Commit message
Description of the change
Hi,
We are cleanning and improving our OpenERP, so we plan to contribute everything here !
Let's start with some basic module
Here it's just a base module in order to link correctly a project and a sale order and also to create a project from a sale order.
No big thing, it's an base module that can be usefull in many case
Thanks for your review
Pedro Manuel Baeza (pedro.baeza) wrote : | # |
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote : | # |
Hi Pedro
In fact this module is not a glue it more a base module for our modules (they will be contributed). But we think other project can need it so it why I push it here right now.
This module just add basic but usefull link between order and project and give the possibility to create a project from the sale order. I am not sure that it's a good idea to install it by default, I think it's better to install it only if it's needed. This is why I call it base_sale_project because it should be use as dependency of other module.
Regarding the field "project_id". In our case we need to have a real link between the sale order and the project. As "project_id" is already used for adding a link with... analytic.account :'(. We need to have a field that point on the "project.project" we don't found a better name than "true_project_id". The best will to clean addons code... and replace "project_id" by "analytic_
Thanks for your feedback
Pedro Manuel Baeza (pedro.baeza) wrote : | # |
Yeah, you're right about project_id relation with analytic account instead of the project.
About names and so on, it's a matter of taste, so I'm not going to object.
I have checked code and seems OK, so I give my approval.
What is what we expect next?
Regards.
Daniel Reis (dreis-pt) wrote : | # |
Thanks for the contribution!
Generating Projects from Sales Orders is a possible workflow.
But generating Tasks from Sales orders is also a valid workflow.
So I don't think it's a good idea to have it "autoinstall"ed.
I agree with Pedro on the two other issues:
- "base_*" modules are usually core functionality related; how about "sale_project_
- I also find that "true_project_id" is not very intuitive. How about something like "related_
Nitpicks:
L66: s/posibility/
L182: methods intended to be called by a button tend to be called "action_*". I suggest renaming this to "action_
L188: I believe the context==None control can be safely removed here
Another suggestion (could be a later improvement):
- It would be nice for the create button to return an action, so that it opens the created Project after the button is clicked; like the Issue's "Create Task" button (standard in v6, ported to v7 in a project-service module).
- 38. By Sébastien BEAU - http://www.akretion.com
-
[REF] change module name, rename method linked to the button, remove useless context is None
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote : | # |
@Daniel
I did the change, the name sale_project_base seem perfect for me.
For the field name, we should found something that contrast with the native "project_id" to avoid confusion. Developper that read the code should be alarmed by the name of the field.
Maybe "real_project_id"? What do you think?
note : related_project_id is great also. Pedro which one do you prefers?
Pedro Manuel Baeza (pedro.baeza) wrote : | # |
I think related_project_id can be intuitive enough and not a shocking name.
Daniel suggestions are good for me too.
Regards.
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote : | # |
IMHO real_project_id and true_project id looks the same.
For us keeping true_project_id would make migration easier...
I also think "true_project_id" carries enough "subversive meta information" to make it clear that if a foreign key points to an analytic account and not to a project, may be it was not a good idea to call it "project_id".
Thoughts?
Daniel Reis (dreis-pt) wrote : | # |
If you're already using the module, changing a field name is rather painful, and it probably isn't worth the effort. So, no objections there.
It would also be nice to add the i18n/.po file, but I won't pick on that.
Daniel Reis (dreis-pt) wrote : | # |
PS: Raphael, having a "project_id" field pointing at a Analytic Account is the kind of thing that bring emotion to OpenERP ;-)
- 39. By Sébastien BEAU - http://www.akretion.com
-
[REF] rename true_project_id into related_project_id
- 40. By Sébastien BEAU - http://www.akretion.com
-
[IMP] add translation file
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote : | # |
I talk with Raph.
Even if we have to migrate our work, the later we will do the change the more painful it will be so let's rename it!
I also add the .po file
Thanks for your feedback
Just one question what is the best name for the onchange method?
- onchange_my_field
- on_my_field_change
-....
Pedro Manuel Baeza (pedro.baeza) wrote : | # |
I use to call it onchange_fieldname: compact and indicating the field name.
Regards.
- 41. By Sébastien BEAU - http://www.akretion.com
-
[REF] rename onchange and pass the context
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote : | # |
Yes is seem to be the best option, let's update my code
Preview Diff
1 | === added directory 'sale_project_base' |
2 | === added file 'sale_project_base/__init__.py' |
3 | --- sale_project_base/__init__.py 1970-01-01 00:00:00 +0000 |
4 | +++ sale_project_base/__init__.py 2014-03-20 19:06:11 +0000 |
5 | @@ -0,0 +1,26 @@ |
6 | +# -*- coding: utf-8 -*- |
7 | +############################################################################### |
8 | +# |
9 | +# Module for OpenERP |
10 | +# Copyright (C) 2014 Akretion (http://www.akretion.com). |
11 | +# Copyright (C) 2010-2013 Akretion LDTA (<http://www.akretion.com>) |
12 | +# @author Sébastien BEAU <sebastien.beau@akretion.com> |
13 | +# @author Benoît GUILLOT <benoit.guillot@akretion.com> |
14 | +# |
15 | +# This program is free software: you can redistribute it and/or modify |
16 | +# it under the terms of the GNU Affero General Public License as |
17 | +# published by the Free Software Foundation, either version 3 of the |
18 | +# License, or (at your option) any later version. |
19 | +# |
20 | +# This program is distributed in the hope that it will be useful, |
21 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | +# GNU Affero General Public License for more details. |
24 | +# |
25 | +# You should have received a copy of the GNU Affero General Public License |
26 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | +# |
28 | +############################################################################### |
29 | + |
30 | +from . import sale |
31 | +from . import project |
32 | |
33 | === added file 'sale_project_base/__openerp__.py' |
34 | --- sale_project_base/__openerp__.py 1970-01-01 00:00:00 +0000 |
35 | +++ sale_project_base/__openerp__.py 2014-03-20 19:06:11 +0000 |
36 | @@ -0,0 +1,43 @@ |
37 | +# -*- coding: utf-8 -*- |
38 | +############################################################################### |
39 | +# |
40 | +# Module for OpenERP |
41 | +# Copyright (C) 2010-2013 Akretion LDTA (<http://www.akretion.com>). |
42 | +# Copyright (C) 2013 Akretion (http://www.akretion.com). |
43 | +# @author Benoît GUILLOT <benoit.guillot@akretion.com> |
44 | +# |
45 | +# This program is free software: you can redistribute it and/or modify |
46 | +# it under the terms of the GNU Affero General Public License as |
47 | +# published by the Free Software Foundation, either version 3 of the |
48 | +# License, or (at your option) any later version. |
49 | +# |
50 | +# This program is distributed in the hope that it will be useful, |
51 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
52 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
53 | +# GNU Affero General Public License for more details. |
54 | +# |
55 | +# You should have received a copy of the GNU Affero General Public License |
56 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
57 | +# |
58 | +############################################################################### |
59 | + |
60 | + |
61 | +{ |
62 | + 'name': 'Sale Project Base', |
63 | + 'version': '7.0', |
64 | + 'category': 'Generic Modules/Others', |
65 | + 'license': 'AGPL-3', |
66 | + 'description': """This module is a base module that give the possibility to |
67 | + create a project from a quotation""", |
68 | + 'author': 'Akretion', |
69 | + 'website': 'http://www.akretion.com/', |
70 | + 'depends': [ |
71 | + 'project', |
72 | + 'sale', |
73 | + ], |
74 | + 'demo': [], |
75 | + 'data': [ |
76 | + 'sale_view.xml', |
77 | + ], |
78 | + 'installable': True, |
79 | +} |
80 | |
81 | === added directory 'sale_project_base/i18n' |
82 | === added file 'sale_project_base/i18n/sale_project_base.po' |
83 | --- sale_project_base/i18n/sale_project_base.po 1970-01-01 00:00:00 +0000 |
84 | +++ sale_project_base/i18n/sale_project_base.po 2014-03-20 19:06:11 +0000 |
85 | @@ -0,0 +1,38 @@ |
86 | +# Translation of OpenERP Server. |
87 | +# This file contains the translation of the following modules: |
88 | +# * sale_project_base |
89 | +# |
90 | +msgid "" |
91 | +msgstr "" |
92 | +"Project-Id-Version: OpenERP Server 7.0\n" |
93 | +"Report-Msgid-Bugs-To: \n" |
94 | +"POT-Creation-Date: 2014-03-20 17:47+0000\n" |
95 | +"PO-Revision-Date: 2014-03-20 17:47+0000\n" |
96 | +"Last-Translator: <>\n" |
97 | +"Language-Team: \n" |
98 | +"MIME-Version: 1.0\n" |
99 | +"Content-Type: text/plain; charset=UTF-8\n" |
100 | +"Content-Transfer-Encoding: \n" |
101 | +"Plural-Forms: \n" |
102 | + |
103 | +#. module: sale_project_base |
104 | +#: model:ir.model,name:sale_project_base.model_project_project |
105 | +#: field:sale.order,related_project_id:0 |
106 | +msgid "Project" |
107 | +msgstr "" |
108 | + |
109 | +#. module: sale_project_base |
110 | +#: model:ir.model,name:sale_project_base.model_sale_order |
111 | +msgid "Sales Order" |
112 | +msgstr "" |
113 | + |
114 | +#. module: sale_project_base |
115 | +#: view:sale.order:0 |
116 | +msgid "Create Project" |
117 | +msgstr "" |
118 | + |
119 | +#. module: sale_project_base |
120 | +#: field:project.project,order_ids:0 |
121 | +msgid "Orders" |
122 | +msgstr "" |
123 | + |
124 | |
125 | === added file 'sale_project_base/project.py' |
126 | --- sale_project_base/project.py 1970-01-01 00:00:00 +0000 |
127 | +++ sale_project_base/project.py 2014-03-20 19:06:11 +0000 |
128 | @@ -0,0 +1,37 @@ |
129 | +# -*- coding: utf-8 -*- |
130 | +############################################################################### |
131 | +# |
132 | +# Module for OpenERP |
133 | +# Copyright (C) 2014 Akretion (http://www.akretion.com). |
134 | +# Copyright (C) 2010-2013 Akretion LDTA (<http://www.akretion.com>) |
135 | +# @author Sébastien BEAU <sebastien.beau@akretion.com> |
136 | +# @author Benoît GUILLOT <benoit.guillot@akretion.com> |
137 | +# |
138 | +# This program is free software: you can redistribute it and/or modify |
139 | +# it under the terms of the GNU Affero General Public License as |
140 | +# published by the Free Software Foundation, either version 3 of the |
141 | +# License, or (at your option) any later version. |
142 | +# |
143 | +# This program is distributed in the hope that it will be useful, |
144 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
145 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
146 | +# GNU Affero General Public License for more details. |
147 | +# |
148 | +# You should have received a copy of the GNU Affero General Public License |
149 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
150 | +# |
151 | +############################################################################### |
152 | + |
153 | + |
154 | +from openerp.osv import fields, orm |
155 | + |
156 | + |
157 | +class project_project(orm.Model): |
158 | + _inherit = "project.project" |
159 | + |
160 | + _columns = { |
161 | + 'order_ids': fields.one2many( |
162 | + 'sale.order', |
163 | + 'related_project_id', |
164 | + 'Orders'), |
165 | + } |
166 | |
167 | === added file 'sale_project_base/sale.py' |
168 | --- sale_project_base/sale.py 1970-01-01 00:00:00 +0000 |
169 | +++ sale_project_base/sale.py 2014-03-20 19:06:11 +0000 |
170 | @@ -0,0 +1,69 @@ |
171 | +# -*- coding: utf-8 -*- |
172 | +############################################################################### |
173 | +# |
174 | +# Module for OpenERP |
175 | +# Copyright (C) 2014 Akretion (http://www.akretion.com). |
176 | +# Copyright (C) 2010-2013 Akretion LDTA (<http://www.akretion.com>) |
177 | +# @author Sébastien BEAU <sebastien.beau@akretion.com> |
178 | +# @author Benoît GUILLOT <benoit.guillot@akretion.com> |
179 | +# |
180 | +# This program is free software: you can redistribute it and/or modify |
181 | +# it under the terms of the GNU Affero General Public License as |
182 | +# published by the Free Software Foundation, either version 3 of the |
183 | +# License, or (at your option) any later version. |
184 | +# |
185 | +# This program is distributed in the hope that it will be useful, |
186 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
187 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
188 | +# GNU Affero General Public License for more details. |
189 | +# |
190 | +# You should have received a copy of the GNU Affero General Public License |
191 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
192 | +# |
193 | +############################################################################### |
194 | + |
195 | +from openerp.osv import fields, orm |
196 | +from datetime import date |
197 | + |
198 | + |
199 | +class sale_order(orm.Model): |
200 | + _inherit = "sale.order" |
201 | + |
202 | + _columns = { |
203 | + 'related_project_id': fields.many2one( |
204 | + 'project.project', |
205 | + 'Project', |
206 | + readonly=True, |
207 | + states={'draft': [('readonly', False)]} |
208 | + ), |
209 | + } |
210 | + |
211 | + def onchange_related_project_id(self, cr, uid, ids, related_project_id, context=None): |
212 | + project_obj = self.pool['project.project'] |
213 | + if related_project_id: |
214 | + project = project_obj.browse(cr, uid, related_project_id, context=context) |
215 | + return {'value': {'project_id': project.analytic_account_id.id}} |
216 | + return {} |
217 | + |
218 | + def _prepare_project_vals(self, cr, uid, order, context=None): |
219 | + name = u" %s - %s - %s" % ( |
220 | + order.partner_id.name, |
221 | + date.today().year, |
222 | + order.name) |
223 | + return { |
224 | + 'user_id': order.user_id.id, |
225 | + 'name': name, |
226 | + 'partner_id': order.partner_id.id, |
227 | + } |
228 | + |
229 | + def action_create_project(self, cr, uid, ids, context=None): |
230 | + project_obj = self.pool['project.project'] |
231 | + for order in self.browse(cr, uid, ids, context=context): |
232 | + vals = self._prepare_project_vals(cr, uid, order, context) |
233 | + project_id = project_obj.create(cr, uid, vals, context=context) |
234 | + project = project_obj.browse(cr, uid, project_id, context=context) |
235 | + order.write({ |
236 | + 'related_project_id': project_id, |
237 | + 'project_id': project.analytic_account_id.id |
238 | + }) |
239 | + return True |
240 | |
241 | === added file 'sale_project_base/sale_view.xml' |
242 | --- sale_project_base/sale_view.xml 1970-01-01 00:00:00 +0000 |
243 | +++ sale_project_base/sale_view.xml 2014-03-20 19:06:11 +0000 |
244 | @@ -0,0 +1,28 @@ |
245 | +<?xml version="1.0" encoding="utf-8"?> |
246 | +<openerp> |
247 | + <data> |
248 | + |
249 | + <record id="view_order_form" model="ir.ui.view"> |
250 | + <field name="name">view_project_quotation_order_form</field> |
251 | + <field name="model">sale.order</field> |
252 | + <field name="inherit_id" ref="sale.view_order_form" /> |
253 | + <field name="arch" type="xml"> |
254 | + <field name="project_id" position="replace"> |
255 | + <field name="project_id" invisible="1" /> |
256 | + <group col="4" colspan="2"> |
257 | + <field name="related_project_id" |
258 | + on_change="onchange_related_project_id(related_project_id, context)" |
259 | + domain="[('partner_id','=',partner_id)]" |
260 | + attrs="{'readonly':[('partner_id','=', False)]}"/> |
261 | + <group attrs="{'invisible':[('related_project_id', '!=', False)]}"> |
262 | + <button name="action_create_project" states="draft" |
263 | + string="Create Project" |
264 | + type="object" icon="gtk-execute" /> |
265 | + </group> |
266 | + </group> |
267 | + </field> |
268 | + </field> |
269 | + </record> |
270 | + |
271 | + </data> |
272 | +</openerp> |
Hi, Sébastien, some remarks from a quick scan:
- Why do you need to declare a new field 'true_project_id' instead of using existing 'project_id'?
- You can put auto_install to True so that if sale and project are installed, this module is automatically installed.
- A similar module that glues sale and stock is called sale_stock. Maybe you can call yours sale_project.
Thanks for the contribution.
Regards.