Merge lp:~ajite/multi-company/multi-company-add-0001 into lp:multi-company
- multi-company-add-0001
- Merge into 7.0
Proposed by
Augustin Cisterne-Kaas - www.elico-corp.com
Status: | Needs review |
---|---|
Proposed branch: | lp:~ajite/multi-company/multi-company-add-0001 |
Merge into: | lp:multi-company |
Diff against target: |
2897 lines (+2703/-0) 33 files modified
base_intercompany/__init__.py (+27/-0) base_intercompany/__openerp__.py (+49/-0) base_intercompany/backend.py (+30/-0) base_intercompany/base_intercompany_demo.xml (+76/-0) base_intercompany/base_intercompany_menu.xml (+22/-0) base_intercompany/company.py (+142/-0) base_intercompany/connector.py (+136/-0) base_intercompany/consumer.py (+77/-0) base_intercompany/icops_model.py (+92/-0) base_intercompany/icops_model_view.xml (+59/-0) base_intercompany/security/ir.model.access.csv (+3/-0) base_intercompany/static/description/index.html (+25/-0) base_intercompany/unit/__init__.py (+26/-0) base_intercompany/unit/backend_adapter.py (+151/-0) base_intercompany/unit/binder.py (+122/-0) base_intercompany/unit/export_synchronizer.py (+258/-0) base_intercompany/unit/mapper.py (+66/-0) base_intercompany_sale/__init__.py (+28/-0) base_intercompany_sale/__openerp__.py (+50/-0) base_intercompany_sale/base_intercompany_sale_demo.xml (+53/-0) base_intercompany_sale/company.py (+56/-0) base_intercompany_sale/connector.py (+32/-0) base_intercompany_sale/consumer.py (+79/-0) base_intercompany_sale/icops_model.py (+33/-0) base_intercompany_sale/icops_model_view.xml (+15/-0) base_intercompany_sale/purchase.py (+296/-0) base_intercompany_sale/purchase_view.xml (+26/-0) base_intercompany_sale/sale.py (+390/-0) base_intercompany_sale/sale_view.xml (+26/-0) base_intercompany_sale/security/ir.model.access.csv (+21/-0) base_intercompany_sale/static/description/index.html (+26/-0) base_intercompany_sale/tests/__init__.py (+30/-0) base_intercompany_sale/tests/test_sale.py (+181/-0) |
To merge this branch: | bzr merge lp:~ajite/multi-company/multi-company-add-0001 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexandre Fayolle - camptocamp | Needs Resubmitting | ||
Review via email: mp+203454@code.launchpad.net |
Commit message
[ADD] base_intercompany and base_intercompa
Description of the change
Added base_intercompany and base_intercompa
To post a comment you must log in.
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote : | # |
review:
Needs Fixing
(tried to install and run the tests)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote : | # |
Hello,
The management of the project has moved to Github: https:/
Please migrate your merge proposal to Github. You may want to check https:/
Thanks for contributing to the project
review:
Needs Resubmitting
Unmerged revisions
- 7. By Augustin Cisterne-Kaas <email address hidden>
-
[FIX] A bug that was preventing to create normal SO/PO
- 6. By Augustin Cisterne-Kaas <email address hidden>
-
[FIX] Made it compatible with the last version of the connector
- 5. By Augustin Cisterne-Kaas <email address hidden>
-
[ADD] Module base_intercompany and base_intercompa
ny_sale
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'base_intercompany' | |||
2 | === added file 'base_intercompany/__init__.py' | |||
3 | --- base_intercompany/__init__.py 1970-01-01 00:00:00 +0000 | |||
4 | +++ base_intercompany/__init__.py 2014-02-23 01:10:59 +0000 | |||
5 | @@ -0,0 +1,27 @@ | |||
6 | 1 | # -*- coding: utf-8 -*- | ||
7 | 2 | ############################################################################## | ||
8 | 3 | # | ||
9 | 4 | # OpenERP, Open Source Management Solution | ||
10 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
11 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
12 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
13 | 8 | |||
14 | 9 | # This program is free software: you can redistribute it and/or modify | ||
15 | 10 | # it under the terms of the GNU Affero General Public License as | ||
16 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
17 | 12 | # License, or (at your option) any later version. | ||
18 | 13 | # | ||
19 | 14 | # This program is distributed in the hope that it will be useful, | ||
20 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | 17 | # GNU Affero General Public License for more details. | ||
23 | 18 | # | ||
24 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
25 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
26 | 21 | # | ||
27 | 22 | ############################################################################## | ||
28 | 23 | import connector | ||
29 | 24 | import consumer | ||
30 | 25 | import backend | ||
31 | 26 | import company | ||
32 | 27 | import icops_model | ||
33 | 0 | 28 | ||
34 | === added file 'base_intercompany/__openerp__.py' | |||
35 | --- base_intercompany/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
36 | +++ base_intercompany/__openerp__.py 2014-02-23 01:10:59 +0000 | |||
37 | @@ -0,0 +1,49 @@ | |||
38 | 1 | # -*- coding: utf-8 -*- | ||
39 | 2 | ############################################################################## | ||
40 | 3 | # | ||
41 | 4 | # OpenERP, Open Source Management Solution | ||
42 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
43 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
44 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
45 | 8 | |||
46 | 9 | # This program is free software: you can redistribute it and/or modify | ||
47 | 10 | # it under the terms of the GNU Affero General Public License as | ||
48 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
49 | 12 | # License, or (at your option) any later version. | ||
50 | 13 | # | ||
51 | 14 | # This program is distributed in the hope that it will be useful, | ||
52 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
53 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
54 | 17 | # GNU Affero General Public License for more details. | ||
55 | 18 | # | ||
56 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
57 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
58 | 21 | # | ||
59 | 22 | ############################################################################## | ||
60 | 23 | |||
61 | 24 | {'name': 'Base Intercompany', | ||
62 | 25 | 'version': '0.4', | ||
63 | 26 | 'category': 'Generic Modules', | ||
64 | 27 | 'depends': ['connector'], | ||
65 | 28 | 'author': 'Elico Corp', | ||
66 | 29 | 'license': 'AGPL-3', | ||
67 | 30 | 'website': 'https://www.elico-corp.com', | ||
68 | 31 | 'description': """ | ||
69 | 32 | This module is the structure designed to manage Inter-company Process (ICOPS) | ||
70 | 33 | and allows 2 companies to create objects in each other. | ||
71 | 34 | This module needs to be installed with one of the following modules: | ||
72 | 35 | - Base Intercompany Sale | ||
73 | 36 | - Base Intercompany Stock (in development) | ||
74 | 37 | - Any module which extends the Base Intercompany module | ||
75 | 38 | |||
76 | 39 | TODO: demo data to be improved.\n | ||
77 | 40 | Blueprint: https://blueprints.launchpad.net/multi-company/+spec/icops | ||
78 | 41 | """, | ||
79 | 42 | 'images': [], | ||
80 | 43 | 'demo': ['base_intercompany_demo.xml'], | ||
81 | 44 | 'data': ['security/ir.model.access.csv', | ||
82 | 45 | 'icops_model_view.xml', | ||
83 | 46 | 'base_intercompany_menu.xml'], | ||
84 | 47 | 'installable': True, | ||
85 | 48 | 'application': False, | ||
86 | 49 | } | ||
87 | 0 | 50 | ||
88 | === added file 'base_intercompany/backend.py' | |||
89 | --- base_intercompany/backend.py 1970-01-01 00:00:00 +0000 | |||
90 | +++ base_intercompany/backend.py 2014-02-23 01:10:59 +0000 | |||
91 | @@ -0,0 +1,30 @@ | |||
92 | 1 | # -*- coding: utf-8 -*- | ||
93 | 2 | ############################################################################## | ||
94 | 3 | # | ||
95 | 4 | # OpenERP, Open Source Management Solution | ||
96 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
97 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
98 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
99 | 8 | |||
100 | 9 | # This program is free software: you can redistribute it and/or modify | ||
101 | 10 | # it under the terms of the GNU Affero General Public License as | ||
102 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
103 | 12 | # License, or (at your option) any later version. | ||
104 | 13 | # | ||
105 | 14 | # This program is distributed in the hope that it will be useful, | ||
106 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
107 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
108 | 17 | # GNU Affero General Public License for more details. | ||
109 | 18 | # | ||
110 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
111 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
112 | 21 | # | ||
113 | 22 | ############################################################################## | ||
114 | 23 | import openerp.addons.connector.backend as backend | ||
115 | 24 | |||
116 | 25 | |||
117 | 26 | icops = backend.Backend('icops') | ||
118 | 27 | """ Generic ICOPS Backend """ | ||
119 | 28 | |||
120 | 29 | icops7 = backend.Backend(parent=icops, version='7.0') | ||
121 | 30 | """ ICOPS Backend for OpenERP 7 """ | ||
122 | 0 | 31 | ||
123 | === added file 'base_intercompany/base_intercompany_demo.xml' | |||
124 | --- base_intercompany/base_intercompany_demo.xml 1970-01-01 00:00:00 +0000 | |||
125 | +++ base_intercompany/base_intercompany_demo.xml 2014-02-23 01:10:59 +0000 | |||
126 | @@ -0,0 +1,76 @@ | |||
127 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
128 | 2 | <openerp> | ||
129 | 3 | <data noupdate="1"> | ||
130 | 4 | <record id="customer_origin" model="res.partner"> | ||
131 | 5 | <field name="name">Company Origin</field> | ||
132 | 6 | </record> | ||
133 | 7 | |||
134 | 8 | <record id="supplier_destination" model="res.partner"> | ||
135 | 9 | <field name="name">Company Destination</field> | ||
136 | 10 | <field name="supplier" eval="True" /> | ||
137 | 11 | </record> | ||
138 | 12 | |||
139 | 13 | <record id="company_origin" model="res.company"> | ||
140 | 14 | <field name="name">Company Origin</field> | ||
141 | 15 | <field name="parent_id" ref="base.main_company"/> | ||
142 | 16 | <field name="partner_id" ref="customer_origin" /> | ||
143 | 17 | </record> | ||
144 | 18 | |||
145 | 19 | <record id="company_destination" model="res.company"> | ||
146 | 20 | <field name="name">Company Destination</field> | ||
147 | 21 | <field name="parent_id" ref="base.main_company"/> | ||
148 | 22 | <field name="partner_id" ref="supplier_destination" /> | ||
149 | 23 | </record> | ||
150 | 24 | |||
151 | 25 | <record id="customer_origin" model="res.partner"> | ||
152 | 26 | <field name="company_id"></field> | ||
153 | 27 | </record> | ||
154 | 28 | |||
155 | 29 | <record id="supplier_destination" model="res.partner"> | ||
156 | 30 | <field name="company_id"></field> | ||
157 | 31 | </record> | ||
158 | 32 | |||
159 | 33 | <record id="partner_origin" model="res.partner"> | ||
160 | 34 | <field name="name">User Origin</field> | ||
161 | 35 | <field name="company_id" ref="company_origin"/> | ||
162 | 36 | <field name="customer" eval="False"/> | ||
163 | 37 | </record> | ||
164 | 38 | |||
165 | 39 | <record id="user_origin" model="res.users"> | ||
166 | 40 | <field name="partner_id" ref="partner_origin"/> | ||
167 | 41 | <field name="login">user.origin</field> | ||
168 | 42 | <field name="password">user.origin</field> | ||
169 | 43 | <field name="company_id" ref="company_origin"/> | ||
170 | 44 | <field name="company_ids" eval="[(6,0,[ref('company_origin')])]" /> | ||
171 | 45 | <field name="groups_id" eval="[(6,0,[ref('base.group_user'), ref('base.group_partner_manager')])]"/> | ||
172 | 46 | </record> | ||
173 | 47 | |||
174 | 48 | <record id="partner_destination" model="res.partner"> | ||
175 | 49 | <field name="name">User Destination</field> | ||
176 | 50 | <field name="company_id" ref="company_destination"/> | ||
177 | 51 | <field name="customer" eval="False"/> | ||
178 | 52 | </record> | ||
179 | 53 | |||
180 | 54 | <record id="user_destination" model="res.users"> | ||
181 | 55 | <field name="partner_id" ref="partner_destination"/> | ||
182 | 56 | <field name="login">user.destination</field> | ||
183 | 57 | <field name="password">user.destination</field> | ||
184 | 58 | <field name="company_id" ref="company_destination"/> | ||
185 | 59 | <field name="company_ids" eval="[(6,0,[ref('company_destination')])]" /> | ||
186 | 60 | <field name="groups_id" eval="[(6,0,[ref('base.group_user'), ref('base.group_partner_manager')])]"/> | ||
187 | 61 | </record> | ||
188 | 62 | |||
189 | 63 | <!-- ICOPS Setup --> | ||
190 | 64 | <record id="backend_origin" model="icops.backend"> | ||
191 | 65 | <field name="name">Backend Origin</field> | ||
192 | 66 | <field name="company_id" ref="company_origin" /> | ||
193 | 67 | <field name="icops_uid" ref="user_origin" /> | ||
194 | 68 | </record> | ||
195 | 69 | |||
196 | 70 | <record id="backend_destination" model="icops.backend"> | ||
197 | 71 | <field name="name">Backend Destination</field> | ||
198 | 72 | <field name="company_id" ref="company_destination" /> | ||
199 | 73 | <field name="icops_uid" ref="user_destination" /> | ||
200 | 74 | </record> | ||
201 | 75 | </data> | ||
202 | 76 | </openerp> | ||
203 | 0 | \ No newline at end of file | 77 | \ No newline at end of file |
204 | 1 | 78 | ||
205 | === added file 'base_intercompany/base_intercompany_menu.xml' | |||
206 | --- base_intercompany/base_intercompany_menu.xml 1970-01-01 00:00:00 +0000 | |||
207 | +++ base_intercompany/base_intercompany_menu.xml 2014-02-23 01:10:59 +0000 | |||
208 | @@ -0,0 +1,22 @@ | |||
209 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
210 | 2 | <openerp> | ||
211 | 3 | <data> | ||
212 | 4 | <menuitem id="menu_icops_root" | ||
213 | 5 | parent="connector.menu_connector_root" | ||
214 | 6 | name="ICOPS" | ||
215 | 7 | sequence="10" | ||
216 | 8 | groups="connector.group_connector_manager"/> | ||
217 | 9 | |||
218 | 10 | <menuitem id="menu_icops_backend" | ||
219 | 11 | name="Backends" | ||
220 | 12 | parent="menu_icops_root" | ||
221 | 13 | action="action_icops_backend"/> | ||
222 | 14 | |||
223 | 15 | <menuitem id="menu_server_root" | ||
224 | 16 | parent="connector.menu_connector_root" | ||
225 | 17 | name="Server" | ||
226 | 18 | sequence="20" | ||
227 | 19 | groups="connector.group_connector_manager"/> | ||
228 | 20 | |||
229 | 21 | </data> | ||
230 | 22 | </openerp> | ||
231 | 0 | 23 | ||
232 | === added file 'base_intercompany/company.py' | |||
233 | --- base_intercompany/company.py 1970-01-01 00:00:00 +0000 | |||
234 | +++ base_intercompany/company.py 2014-02-23 01:10:59 +0000 | |||
235 | @@ -0,0 +1,142 @@ | |||
236 | 1 | # -*- coding: utf-8 -*- | ||
237 | 2 | ############################################################################## | ||
238 | 3 | # | ||
239 | 4 | # OpenERP, Open Source Management Solution | ||
240 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
241 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
242 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
243 | 8 | |||
244 | 9 | # This program is free software: you can redistribute it and/or modify | ||
245 | 10 | # it under the terms of the GNU Affero General Public License as | ||
246 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
247 | 12 | # License, or (at your option) any later version. | ||
248 | 13 | # | ||
249 | 14 | # This program is distributed in the hope that it will be useful, | ||
250 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
251 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
252 | 17 | # GNU Affero General Public License for more details. | ||
253 | 18 | # | ||
254 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
255 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
256 | 21 | # | ||
257 | 22 | ############################################################################## | ||
258 | 23 | |||
259 | 24 | from openerp.osv import orm, fields | ||
260 | 25 | |||
261 | 26 | |||
262 | 27 | class res_intercompany(orm.Model): | ||
263 | 28 | _name = 'res.intercompany' | ||
264 | 29 | _description = 'Inter-Company' | ||
265 | 30 | |||
266 | 31 | def _select_concepts(self, cr, uid, context=None): | ||
267 | 32 | """ Available concepts | ||
268 | 33 | |||
269 | 34 | Can be inherited to add custom versions. | ||
270 | 35 | """ | ||
271 | 36 | return [] | ||
272 | 37 | |||
273 | 38 | def _select_models(self, cr, uid, context=None): | ||
274 | 39 | """ Available Object names | ||
275 | 40 | |||
276 | 41 | Can be inherited to add custom versions. | ||
277 | 42 | """ | ||
278 | 43 | return {} | ||
279 | 44 | |||
280 | 45 | def _get_model(self, cr, uid, ids, name, arg, context=None): | ||
281 | 46 | """ Available versions | ||
282 | 47 | |||
283 | 48 | Can be inherited to add custom versions. | ||
284 | 49 | """ | ||
285 | 50 | res = {} | ||
286 | 51 | for intercompany in self.browse(cr, uid, ids, context): | ||
287 | 52 | model = None | ||
288 | 53 | if intercompany.concept: | ||
289 | 54 | model = self._select_models( | ||
290 | 55 | cr, uid)[intercompany.concept] | ||
291 | 56 | res[intercompany.id] = model | ||
292 | 57 | return res | ||
293 | 58 | |||
294 | 59 | def get_intercompany(self, cr, uid, obj_id, | ||
295 | 60 | obj_class_name, obj_name, context=None): | ||
296 | 61 | """ | ||
297 | 62 | get company from and to | ||
298 | 63 | """ | ||
299 | 64 | if isinstance(obj_id, list): | ||
300 | 65 | obj_id = obj_id[0] | ||
301 | 66 | assert isinstance(obj_id, int) or isinstance(obj_id, long) | ||
302 | 67 | obj = self.pool.get(obj_class_name).browse( | ||
303 | 68 | cr, | ||
304 | 69 | uid, | ||
305 | 70 | obj_id, | ||
306 | 71 | context=None) | ||
307 | 72 | company = obj.company_id | ||
308 | 73 | ic_uid_ids = None | ||
309 | 74 | company_to_ids = [] | ||
310 | 75 | for ic in company.intercompany_ids: | ||
311 | 76 | if ic.concept == obj_name: | ||
312 | 77 | company_to_ids.append(ic.company_to.id) | ||
313 | 78 | ic_uid_ids = ic.icops_uid.id | ||
314 | 79 | if company.intercompany_ids: | ||
315 | 80 | ic_uid_ids = company.intercompany_ids[0].icops_uid.id | ||
316 | 81 | return obj.company_id.id, company_to_ids, ic_uid_ids | ||
317 | 82 | |||
318 | 83 | def _check_intercompany_user(self, cr, uid, ids, context=None): | ||
319 | 84 | for ic in self.browse(cr, uid, ids, context=context): | ||
320 | 85 | if not ic.icops_uid: | ||
321 | 86 | return False | ||
322 | 87 | return True | ||
323 | 88 | |||
324 | 89 | _columns = { | ||
325 | 90 | 'backend_id': fields.many2one('icops.backend', 'Original Backend', | ||
326 | 91 | required=True, ondelete='cascade'), | ||
327 | 92 | 'backend_to': fields.many2one('icops.backend', 'Destination Backend', | ||
328 | 93 | required=True, ondelete='cascade'), | ||
329 | 94 | 'concept': fields.selection(_select_concepts, string="Concept", | ||
330 | 95 | required=True), | ||
331 | 96 | 'model': fields.function(_get_model, type='char', | ||
332 | 97 | string='Object', store=False), | ||
333 | 98 | 'icops_uid': fields.related( | ||
334 | 99 | 'backend_to', 'icops_uid', type='many2one', | ||
335 | 100 | relation='res.users', readonly=True, string='IC User'), | ||
336 | 101 | 'on_create': fields.boolean('Create'), | ||
337 | 102 | 'on_write': fields.boolean('Update'), | ||
338 | 103 | 'on_unlink': fields.boolean('Delete'), | ||
339 | 104 | 'on_confirm': fields.boolean('Confirm'), | ||
340 | 105 | 'on_cancel': fields.boolean('Cancel') | ||
341 | 106 | } | ||
342 | 107 | |||
343 | 108 | _constraints = [ | ||
344 | 109 | (_check_intercompany_user, 'Please set IC user for the Company first', | ||
345 | 110 | ['icops_uid']) | ||
346 | 111 | ] | ||
347 | 112 | |||
348 | 113 | _defaults = { | ||
349 | 114 | 'backend_id': lambda self, cr, uid, c: c.get('active_id', False), | ||
350 | 115 | } | ||
351 | 116 | # _sql_constraints = [( | ||
352 | 117 | # 'company_from_company_to_unique', 'unique(company_from, company_to)', | ||
353 | 118 | # 'A setup for that company already exists')] | ||
354 | 119 | |||
355 | 120 | def check_need_create_intercompany_object( | ||
356 | 121 | self, cr, uid, company_from, company_to, concept, | ||
357 | 122 | event, return_list_type=False, regular=False): | ||
358 | 123 | """ @company_from | ||
359 | 124 | @company_to | ||
360 | 125 | @o2o_field_name file name.Example, so2po po2so ,,,, | ||
361 | 126 | @node value of o2o_field_name , draft, confirm | ||
362 | 127 | @return_list_type, the return type is list or boolean | ||
363 | 128 | """ | ||
364 | 129 | |||
365 | 130 | if type(company_to) != list: | ||
366 | 131 | company_to = [company_to] | ||
367 | 132 | request = [('company_from', '=', company_from), | ||
368 | 133 | ('concept', '=', concept), | ||
369 | 134 | (event, '=', True)] | ||
370 | 135 | if not regular: | ||
371 | 136 | request.append(('company_to', 'in', company_to)) | ||
372 | 137 | intercompany_ids = self.search( | ||
373 | 138 | cr, uid, request) | ||
374 | 139 | if return_list_type: | ||
375 | 140 | return intercompany_ids | ||
376 | 141 | else: | ||
377 | 142 | return intercompany_ids and True or False | ||
378 | 0 | 143 | ||
379 | === added file 'base_intercompany/connector.py' | |||
380 | --- base_intercompany/connector.py 1970-01-01 00:00:00 +0000 | |||
381 | +++ base_intercompany/connector.py 2014-02-23 01:10:59 +0000 | |||
382 | @@ -0,0 +1,136 @@ | |||
383 | 1 | # -*- coding: utf-8 -*- | ||
384 | 2 | ############################################################################## | ||
385 | 3 | # | ||
386 | 4 | # OpenERP, Open Source Management Solution | ||
387 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
388 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
389 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
390 | 8 | |||
391 | 9 | # This program is free software: you can redistribute it and/or modify | ||
392 | 10 | # it under the terms of the GNU Affero General Public License as | ||
393 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
394 | 12 | # License, or (at your option) any later version. | ||
395 | 13 | # | ||
396 | 14 | # This program is distributed in the hope that it will be useful, | ||
397 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
398 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
399 | 17 | # GNU Affero General Public License for more details. | ||
400 | 18 | # | ||
401 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
402 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
403 | 21 | # | ||
404 | 22 | ############################################################################## | ||
405 | 23 | |||
406 | 24 | from openerp.osv import orm, osv, fields | ||
407 | 25 | from openerp.addons.connector.connector import Environment | ||
408 | 26 | from openerp.addons.connector.checkpoint import checkpoint | ||
409 | 27 | |||
410 | 28 | |||
411 | 29 | class base_intercompany_installed(orm.AbstractModel): | ||
412 | 30 | """Empty model used to know if the module is installed on the | ||
413 | 31 | database. | ||
414 | 32 | |||
415 | 33 | If the model is in the registry, the module is installed. | ||
416 | 34 | """ | ||
417 | 35 | _name = 'base_intercompany.installed' | ||
418 | 36 | |||
419 | 37 | |||
420 | 38 | def get_environment(session, model_name, backend_id): | ||
421 | 39 | """ Create an environment to work with. """ | ||
422 | 40 | backend_record = session.browse('icops.backend', backend_id) | ||
423 | 41 | env = Environment(backend_record, session, model_name) | ||
424 | 42 | lang_code = 'en_US' | ||
425 | 43 | env.set_lang(code=lang_code) | ||
426 | 44 | return env | ||
427 | 45 | |||
428 | 46 | |||
429 | 47 | class icops_binding(orm.AbstractModel): | ||
430 | 48 | _name = 'icops.binding' | ||
431 | 49 | _inherit = 'external.binding' | ||
432 | 50 | _description = 'Coswin Binding (abstract)' | ||
433 | 51 | |||
434 | 52 | _columns = { | ||
435 | 53 | 'backend_id': fields.many2one( | ||
436 | 54 | 'icops.backend', | ||
437 | 55 | 'ICOPS Backend', | ||
438 | 56 | required=True, | ||
439 | 57 | ondelete='restrict'), | ||
440 | 58 | 'icops_ids': fields.one2many( | ||
441 | 59 | 'icops.record', 'binding_id', | ||
442 | 60 | string="ICOPS Record"), | ||
443 | 61 | } | ||
444 | 62 | |||
445 | 63 | |||
446 | 64 | class icops_record(orm.Model): | ||
447 | 65 | _name = 'icops.record' | ||
448 | 66 | |||
449 | 67 | _columns = { | ||
450 | 68 | 'binding_id': fields.integer('ICOPS Binding'), | ||
451 | 69 | 'record_id': fields.integer('ICOPS ID'), | ||
452 | 70 | 'model': fields.char('Model'), | ||
453 | 71 | 'concept': fields.char('Concept'), | ||
454 | 72 | 'backend_id': fields.many2one( | ||
455 | 73 | 'icops.backend', 'ICOPS Backends'), | ||
456 | 74 | } | ||
457 | 75 | |||
458 | 76 | |||
459 | 77 | class icops_model(orm.AbstractModel): | ||
460 | 78 | _name = 'icops.model' | ||
461 | 79 | |||
462 | 80 | def _is_locked(self, cr, uid, ids, name, arg, context=None): | ||
463 | 81 | res = {} | ||
464 | 82 | for obj in self.browse(cr, uid, ids, context=context): | ||
465 | 83 | pool = self.pool.get('icops.record') | ||
466 | 84 | record_ids = pool.search( | ||
467 | 85 | cr, uid, [('record_id', '=', obj.id), | ||
468 | 86 | ('model', '=', self._name)]) | ||
469 | 87 | |||
470 | 88 | res[obj.id] = True if record_ids else False | ||
471 | 89 | return res | ||
472 | 90 | |||
473 | 91 | def _check_icops(self, cr, uid, ids, context=None): | ||
474 | 92 | context = context or {} | ||
475 | 93 | if isinstance(ids, int): | ||
476 | 94 | ids = [ids] | ||
477 | 95 | if 'icops' in context: | ||
478 | 96 | return | ||
479 | 97 | fields = ['locked', 'temp_unlock'] | ||
480 | 98 | for obj in self.read(cr, uid, ids, fields, context=context): | ||
481 | 99 | if obj['temp_unlock']: | ||
482 | 100 | return | ||
483 | 101 | elif obj['locked']: | ||
484 | 102 | raise osv.except_osv( | ||
485 | 103 | 'ICOPS Error', | ||
486 | 104 | 'This object is locked by an intercompany process') | ||
487 | 105 | |||
488 | 106 | _columns = { | ||
489 | 107 | 'locked': fields.function( | ||
490 | 108 | _is_locked, type='boolean', string='Is Locked', store=False), | ||
491 | 109 | # To handle special workflow | ||
492 | 110 | 'temp_unlock': fields.boolean('Temporary Unlock') | ||
493 | 111 | } | ||
494 | 112 | |||
495 | 113 | def action_unlock(self, cr, uid, ids, context): | ||
496 | 114 | pool = self.pool.get('icops.record') | ||
497 | 115 | for obj in self.browse(cr, uid, ids, context=context): | ||
498 | 116 | record_ids = pool.search( | ||
499 | 117 | cr, uid, [('record_id', '=', obj.id), | ||
500 | 118 | ('model', '=', self._name)]) | ||
501 | 119 | pool.unlink(cr, uid, record_ids, context=context) | ||
502 | 120 | |||
503 | 121 | |||
504 | 122 | def add_checkpoint(session, model_name, record_id, backend_id): | ||
505 | 123 | """ Add a row in the model ``connector.checkpoint`` for a record, | ||
506 | 124 | meaning it has to be reviewed by a user. | ||
507 | 125 | |||
508 | 126 | :param session: current session | ||
509 | 127 | :type session: :py:class:openerp.addons.connector.session.ConnectorSession | ||
510 | 128 | :param model_name: name of the model of the record to be reviewed | ||
511 | 129 | :type model_name: str | ||
512 | 130 | :param record_id: ID of the record to be reviewed | ||
513 | 131 | :type record_id: int | ||
514 | 132 | :param backend_id: ID of the Coswin Backend | ||
515 | 133 | :type backend_id: int | ||
516 | 134 | """ | ||
517 | 135 | return checkpoint.add_checkpoint(session, model_name, record_id, | ||
518 | 136 | 'icops.backend', backend_id) | ||
519 | 0 | 137 | ||
520 | === added file 'base_intercompany/consumer.py' | |||
521 | --- base_intercompany/consumer.py 1970-01-01 00:00:00 +0000 | |||
522 | +++ base_intercompany/consumer.py 2014-02-23 01:10:59 +0000 | |||
523 | @@ -0,0 +1,77 @@ | |||
524 | 1 | # -*- coding: utf-8 -*- | ||
525 | 2 | ############################################################################## | ||
526 | 3 | # | ||
527 | 4 | # OpenERP, Open Source Management Solution | ||
528 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
529 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
530 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
531 | 8 | |||
532 | 9 | # This program is free software: you can redistribute it and/or modify | ||
533 | 10 | # it under the terms of the GNU Affero General Public License as | ||
534 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
535 | 12 | # License, or (at your option) any later version. | ||
536 | 13 | # | ||
537 | 14 | # This program is distributed in the hope that it will be useful, | ||
538 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
539 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
540 | 17 | # GNU Affero General Public License for more details. | ||
541 | 18 | # | ||
542 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
543 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
544 | 21 | # | ||
545 | 22 | ############################################################################## | ||
546 | 23 | from openerp.addons.connector.event import (on_record_write, | ||
547 | 24 | on_record_create, | ||
548 | 25 | on_record_unlink | ||
549 | 26 | ) | ||
550 | 27 | from .unit.export_synchronizer import ( | ||
551 | 28 | export_record) | ||
552 | 29 | |||
553 | 30 | _MODEL_NAMES = () | ||
554 | 31 | _BIND_MODEL_NAMES = () | ||
555 | 32 | _UNLINK_MODEL_NAMES = () | ||
556 | 33 | _UNLINK_BIND_MODEL_NAMES = () | ||
557 | 34 | |||
558 | 35 | |||
559 | 36 | @on_record_create(model_names=_BIND_MODEL_NAMES) | ||
560 | 37 | @on_record_write(model_names=_BIND_MODEL_NAMES) | ||
561 | 38 | def delay_export(session, model_name, record_id, fields=None): | ||
562 | 39 | """ Delay a job which export a binding record. | ||
563 | 40 | |||
564 | 41 | (A binding record being a ``icops.res.partner``, | ||
565 | 42 | ``icops.sale.order``, ...) | ||
566 | 43 | """ | ||
567 | 44 | export_record(session, model_name, record_id, fields=fields) | ||
568 | 45 | |||
569 | 46 | |||
570 | 47 | @on_record_write(model_names=_MODEL_NAMES) | ||
571 | 48 | def delay_export_all_bindings(session, model_name, record_id, fields=None): | ||
572 | 49 | """ Delay a job which export all the bindings of a record. | ||
573 | 50 | |||
574 | 51 | In this case, it is called on records of normal models and will delay | ||
575 | 52 | the export for all the bindings. | ||
576 | 53 | """ | ||
577 | 54 | model = session.pool.get(model_name) | ||
578 | 55 | record = model.browse(session.cr, session.uid, | ||
579 | 56 | record_id, context=session.context) | ||
580 | 57 | for binding in record.icops_bind_ids: | ||
581 | 58 | export_record(session, binding._model._name, binding.id, | ||
582 | 59 | fields=fields) | ||
583 | 60 | |||
584 | 61 | |||
585 | 62 | @on_record_unlink(model_names=_UNLINK_MODEL_NAMES) | ||
586 | 63 | def delay_unlink(session, model_name, record_id): | ||
587 | 64 | """ Delay a job which delete a record on Magento. | ||
588 | 65 | |||
589 | 66 | Called on binding records.""" | ||
590 | 67 | fields = {'icops_delete': True} | ||
591 | 68 | delay_export_all_bindings(session, model_name, record_id, fields) | ||
592 | 69 | |||
593 | 70 | |||
594 | 71 | @on_record_unlink(model_names=_UNLINK_BIND_MODEL_NAMES) | ||
595 | 72 | def delay_unlink_binding(session, model_name, record_id): | ||
596 | 73 | """ Delay a job which delete a record on Magento. | ||
597 | 74 | |||
598 | 75 | Called on binding records.""" | ||
599 | 76 | fields = {'icops_delete': True} | ||
600 | 77 | delay_export(session, model_name, record_id, fields) | ||
601 | 0 | 78 | ||
602 | === added file 'base_intercompany/icops_model.py' | |||
603 | --- base_intercompany/icops_model.py 1970-01-01 00:00:00 +0000 | |||
604 | +++ base_intercompany/icops_model.py 2014-02-23 01:10:59 +0000 | |||
605 | @@ -0,0 +1,92 @@ | |||
606 | 1 | # -*- coding: utf-8 -*- | ||
607 | 2 | ############################################################################## | ||
608 | 3 | # | ||
609 | 4 | # OpenERP, Open Source Management Solution | ||
610 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
611 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
612 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
613 | 8 | |||
614 | 9 | # This program is free software: you can redistribute it and/or modify | ||
615 | 10 | # it under the terms of the GNU Affero General Public License as | ||
616 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
617 | 12 | # License, or (at your option) any later version. | ||
618 | 13 | # | ||
619 | 14 | # This program is distributed in the hope that it will be useful, | ||
620 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
621 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
622 | 17 | # GNU Affero General Public License for more details. | ||
623 | 18 | # | ||
624 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
625 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
626 | 21 | # | ||
627 | 22 | ############################################################################## | ||
628 | 23 | |||
629 | 24 | import logging | ||
630 | 25 | from openerp.osv import fields, orm | ||
631 | 26 | |||
632 | 27 | _logger = logging.getLogger(__name__) | ||
633 | 28 | |||
634 | 29 | |||
635 | 30 | class icops_backend(orm.Model): | ||
636 | 31 | _name = 'icops.backend' | ||
637 | 32 | _description = 'ICOPS Backend' | ||
638 | 33 | _inherit = 'connector.backend' | ||
639 | 34 | |||
640 | 35 | _backend_type = 'icops' | ||
641 | 36 | |||
642 | 37 | def _select_versions(self, cr, uid, context=None): | ||
643 | 38 | """ Available versions | ||
644 | 39 | |||
645 | 40 | Can be inherited to add custom versions. | ||
646 | 41 | """ | ||
647 | 42 | return [('7.0', '7.0')] | ||
648 | 43 | |||
649 | 44 | _columns = { | ||
650 | 45 | 'version': fields.selection( | ||
651 | 46 | _select_versions, | ||
652 | 47 | string='Version', | ||
653 | 48 | required=True), | ||
654 | 49 | 'company_id': fields.many2one( | ||
655 | 50 | 'res.company', string="Company", required=True), | ||
656 | 51 | 'icops_ids': fields.one2many( | ||
657 | 52 | 'res.intercompany', 'backend_id', 'Inter-Company Setup'), | ||
658 | 53 | 'icops_uid': fields.many2one( | ||
659 | 54 | 'res.users', 'IC User', | ||
660 | 55 | required=True, | ||
661 | 56 | domain="[('company_id', '=', company_id)]", | ||
662 | 57 | help="User to create update unlink IC records"), | ||
663 | 58 | 'model': fields.related( | ||
664 | 59 | 'backend_to', 'icops_uid', type='many2one', | ||
665 | 60 | relation='res.users', readonly=True, string='IC User'), | ||
666 | 61 | } | ||
667 | 62 | |||
668 | 63 | _defaults = { | ||
669 | 64 | 'version': '7.0', | ||
670 | 65 | } | ||
671 | 66 | |||
672 | 67 | def _icops_backend(self, cr, uid, callback, domain=None, | ||
673 | 68 | context=None): | ||
674 | 69 | if domain is None: | ||
675 | 70 | domain = [] | ||
676 | 71 | ids = self.search(cr, uid, domain, context=context) | ||
677 | 72 | if ids: | ||
678 | 73 | callback(cr, uid, ids, context=context) | ||
679 | 74 | |||
680 | 75 | def prepare_binding(self, cr, uid, data, context=None): | ||
681 | 76 | context = context or {} | ||
682 | 77 | icops_bind_ids = [] | ||
683 | 78 | if not 'icops_bind_ids' in data: | ||
684 | 79 | data['icops_bind_ids'] = None | ||
685 | 80 | if not 'icops' in context and not data['icops_bind_ids']: | ||
686 | 81 | user = self.pool.get('res.users').browse( | ||
687 | 82 | cr, uid, uid, context) | ||
688 | 83 | backend_pool = self.pool.get('icops.backend') | ||
689 | 84 | backend_ids = backend_pool.search( | ||
690 | 85 | cr, uid, [('company_id', '=', user.company_id.id)]) | ||
691 | 86 | if backend_ids: | ||
692 | 87 | backends = backend_pool.browse( | ||
693 | 88 | cr, uid, backend_ids, context) | ||
694 | 89 | for backend in backends: | ||
695 | 90 | icops_bind_ids.append( | ||
696 | 91 | (0, 0, {'backend_id': backend.id})) | ||
697 | 92 | return icops_bind_ids | ||
698 | 0 | 93 | ||
699 | === added file 'base_intercompany/icops_model_view.xml' | |||
700 | --- base_intercompany/icops_model_view.xml 1970-01-01 00:00:00 +0000 | |||
701 | +++ base_intercompany/icops_model_view.xml 2014-02-23 01:10:59 +0000 | |||
702 | @@ -0,0 +1,59 @@ | |||
703 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
704 | 2 | <openerp> | ||
705 | 3 | <data> | ||
706 | 4 | <record id="view_icops_backend_form" model="ir.ui.view"> | ||
707 | 5 | <field name="name">icops.backend.form</field> | ||
708 | 6 | <field name="model">icops.backend</field> | ||
709 | 7 | <field name="arch" type="xml"> | ||
710 | 8 | <form string="ICOPS Backend" version="7.0"> | ||
711 | 9 | <sheet> | ||
712 | 10 | <label for="name" class="oe_edit_only"/> | ||
713 | 11 | <h1> | ||
714 | 12 | <field name="name" class="oe_inline" /> | ||
715 | 13 | </h1> | ||
716 | 14 | <group name="icops" string="ICOPS Configuration"> | ||
717 | 15 | <group colspan="4" col="4"> | ||
718 | 16 | <field name="version" cols="4" /> | ||
719 | 17 | <field name="company_id" cols="2" /> | ||
720 | 18 | <field name="icops_uid" cols="2" /> | ||
721 | 19 | </group> | ||
722 | 20 | </group> | ||
723 | 21 | <field name="icops_ids" context="{'active_id': active_id}"> | ||
724 | 22 | <tree editable="bottom"> | ||
725 | 23 | <field name="concept"/> | ||
726 | 24 | <field name="model" invisible="1" /> | ||
727 | 25 | <field name="backend_id" invisible="1" /> | ||
728 | 26 | <field name="backend_to" /> | ||
729 | 27 | <field name='icops_uid' invisible="1" /> | ||
730 | 28 | <field name="on_create" /> | ||
731 | 29 | <field name="on_write" /> | ||
732 | 30 | <field name="on_unlink" /> | ||
733 | 31 | <field name="on_confirm" /> | ||
734 | 32 | <field name="on_cancel" /> | ||
735 | 33 | </tree> | ||
736 | 34 | </field> | ||
737 | 35 | </sheet> | ||
738 | 36 | </form> | ||
739 | 37 | </field> | ||
740 | 38 | </record> | ||
741 | 39 | |||
742 | 40 | <record id="view_icops_backend_tree" model="ir.ui.view"> | ||
743 | 41 | <field name="name">icops.backend.tree</field> | ||
744 | 42 | <field name="model">icops.backend</field> | ||
745 | 43 | <field name="arch" type="xml"> | ||
746 | 44 | <tree string="ICOPS Backend" version="7.0"> | ||
747 | 45 | <field name="name"/> | ||
748 | 46 | <field name="company_id" /> | ||
749 | 47 | </tree> | ||
750 | 48 | </field> | ||
751 | 49 | </record> | ||
752 | 50 | |||
753 | 51 | <record id="action_icops_backend" model="ir.actions.act_window"> | ||
754 | 52 | <field name="name">ICOPS Backends</field> | ||
755 | 53 | <field name="res_model">icops.backend</field> | ||
756 | 54 | <field name="view_type">form</field> | ||
757 | 55 | <field name="view_mode">tree,form</field> | ||
758 | 56 | <field name="view_id" ref="view_icops_backend_tree"/> | ||
759 | 57 | </record> | ||
760 | 58 | </data> | ||
761 | 59 | </openerp> | ||
762 | 0 | 60 | ||
763 | === added directory 'base_intercompany/security' | |||
764 | === added file 'base_intercompany/security/ir.model.access.csv' | |||
765 | --- base_intercompany/security/ir.model.access.csv 1970-01-01 00:00:00 +0000 | |||
766 | +++ base_intercompany/security/ir.model.access.csv 2014-02-23 01:10:59 +0000 | |||
767 | @@ -0,0 +1,3 @@ | |||
768 | 1 | id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
769 | 2 | access_res_intercompany_manager,res intercompany manager,base_intercompany.model_res_intercompany,connector.group_connector_manager,1,1,1,1 | ||
770 | 3 | access_icops_backend_manager,icops backend manager,base_intercompany.model_icops_backend,connector.group_connector_manager,1,1,1,1 | ||
771 | 0 | \ No newline at end of file | 4 | \ No newline at end of file |
772 | 1 | 5 | ||
773 | === added directory 'base_intercompany/static' | |||
774 | === added directory 'base_intercompany/static/description' | |||
775 | === added file 'base_intercompany/static/description/Intercompany_setup.png' | |||
776 | 2 | Binary files base_intercompany/static/description/Intercompany_setup.png 1970-01-01 00:00:00 +0000 and base_intercompany/static/description/Intercompany_setup.png 2014-02-23 01:10:59 +0000 differ | 6 | Binary files base_intercompany/static/description/Intercompany_setup.png 1970-01-01 00:00:00 +0000 and base_intercompany/static/description/Intercompany_setup.png 2014-02-23 01:10:59 +0000 differ |
777 | === added file 'base_intercompany/static/description/index.html' | |||
778 | --- base_intercompany/static/description/index.html 1970-01-01 00:00:00 +0000 | |||
779 | +++ base_intercompany/static/description/index.html 2014-02-23 01:10:59 +0000 | |||
780 | @@ -0,0 +1,25 @@ | |||
781 | 1 | <section class="oe_container"> | ||
782 | 2 | <div class="oe_row"> | ||
783 | 3 | <h2 class="oe_slogan">base_intercompany</h2> | ||
784 | 4 | <h3 class="oe_slogan">Inter-Company Processing (ICOPS) <br /></h3> | ||
785 | 5 | <h4 class="oe_slogan"><a href="http://www.elico-corp.com">By Elico Corp</a></h4> | ||
786 | 6 | <p> | ||
787 | 7 | This module is the structure designed to manage Inter-company Process (ICOPS) and allows 2 companies to create objects in each other. This module needs to be installed with one of the following modules: | ||
788 | 8 | </p> | ||
789 | 9 | <ul> | ||
790 | 10 | <li>Base Intercompany Sale</li> | ||
791 | 11 | <li>Base Intercompany Stock (in development)</li> | ||
792 | 12 | <li>Any module which extends the Base Intercompany module</li> | ||
793 | 13 | </ul> | ||
794 | 14 | <p> | ||
795 | 15 | TODO: demo data to be improved<br /> | ||
796 | 16 | Blueprint: <a href="https://blueprints.launchpad.net/multi-company/+spec/icops">https://blueprints.launchpad.net/multi-company/+spec/icops</a><br /> | ||
797 | 17 | </p> | ||
798 | 18 | <div class="oe_row_img oe_centered oe_mt32"> | ||
799 | 19 | <img class="oe_picture oe_screenshot" src="Intercompany_setup.png" /> | ||
800 | 20 | </div> | ||
801 | 21 | </div> | ||
802 | 22 | <div class="oe_row oe_centeralign oe_more_space"> | ||
803 | 23 | <a href="http://www.elico-corp.com/saas/" class="oe_button oe_big">Start your <span class="oe_emph">free</span> trial</a> | ||
804 | 24 | </div> | ||
805 | 25 | </section> | ||
806 | 0 | 26 | ||
807 | === added directory 'base_intercompany/static/src' | |||
808 | === added directory 'base_intercompany/static/src/img' | |||
809 | === added file 'base_intercompany/static/src/img/icon.png' | |||
810 | 1 | Binary files base_intercompany/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and base_intercompany/static/src/img/icon.png 2014-02-23 01:10:59 +0000 differ | 27 | Binary files base_intercompany/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and base_intercompany/static/src/img/icon.png 2014-02-23 01:10:59 +0000 differ |
811 | === added directory 'base_intercompany/unit' | |||
812 | === added file 'base_intercompany/unit/__init__.py' | |||
813 | --- base_intercompany/unit/__init__.py 1970-01-01 00:00:00 +0000 | |||
814 | +++ base_intercompany/unit/__init__.py 2014-02-23 01:10:59 +0000 | |||
815 | @@ -0,0 +1,26 @@ | |||
816 | 1 | # -*- coding: utf-8 -*- | ||
817 | 2 | ############################################################################## | ||
818 | 3 | # | ||
819 | 4 | # OpenERP, Open Source Management Solution | ||
820 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
821 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
822 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
823 | 8 | # | ||
824 | 9 | # This program is free software: you can redistribute it and/or modify | ||
825 | 10 | # it under the terms of the GNU Affero General Public License as | ||
826 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
827 | 12 | # License, or (at your option) any later version. | ||
828 | 13 | # | ||
829 | 14 | # This program is distributed in the hope that it will be useful, | ||
830 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
831 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
832 | 17 | # GNU Affero General Public License for more details. | ||
833 | 18 | # | ||
834 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
835 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
836 | 21 | # | ||
837 | 22 | ############################################################################## | ||
838 | 23 | |||
839 | 24 | import binder | ||
840 | 25 | import export_synchronizer | ||
841 | 26 | import backend_adapter | ||
842 | 0 | 27 | ||
843 | === added file 'base_intercompany/unit/backend_adapter.py' | |||
844 | --- base_intercompany/unit/backend_adapter.py 1970-01-01 00:00:00 +0000 | |||
845 | +++ base_intercompany/unit/backend_adapter.py 2014-02-23 01:10:59 +0000 | |||
846 | @@ -0,0 +1,151 @@ | |||
847 | 1 | # -*- coding: utf-8 -*- | ||
848 | 2 | ############################################################################## | ||
849 | 3 | # | ||
850 | 4 | # OpenERP, Open Source Management Solution | ||
851 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
852 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
853 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
854 | 8 | |||
855 | 9 | # This program is free software: you can redistribute it and/or modify | ||
856 | 10 | # it under the terms of the GNU Affero General Public License as | ||
857 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
858 | 12 | # License, or (at your option) any later version. | ||
859 | 13 | # | ||
860 | 14 | # This program is distributed in the hope that it will be useful, | ||
861 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
862 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
863 | 17 | # GNU Affero General Public License for more details. | ||
864 | 18 | # | ||
865 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
866 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
867 | 21 | # | ||
868 | 22 | ############################################################################## | ||
869 | 23 | |||
870 | 24 | import logging | ||
871 | 25 | from openerp.addons.connector.unit.backend_adapter import CRUDAdapter | ||
872 | 26 | |||
873 | 27 | _logger = logging.getLogger(__name__) | ||
874 | 28 | recorder = {} | ||
875 | 29 | |||
876 | 30 | |||
877 | 31 | def call_to_key(method, arguments): | ||
878 | 32 | """ Used to 'freeze' the method and arguments of a call to Coswin | ||
879 | 33 | so they can be hashable; they will be stored in a dict. | ||
880 | 34 | |||
881 | 35 | Used in both the recorder and the tests. | ||
882 | 36 | """ | ||
883 | 37 | def freeze(arg): | ||
884 | 38 | if isinstance(arg, dict): | ||
885 | 39 | items = dict((key, freeze(value)) for key, value | ||
886 | 40 | in arg.iteritems()) | ||
887 | 41 | return frozenset(items.iteritems()) | ||
888 | 42 | elif isinstance(arg, list): | ||
889 | 43 | return tuple([freeze(item) for item in arg]) | ||
890 | 44 | else: | ||
891 | 45 | return arg | ||
892 | 46 | |||
893 | 47 | new_args = [] | ||
894 | 48 | for arg in arguments: | ||
895 | 49 | new_args.append(freeze(arg)) | ||
896 | 50 | return (method, tuple(new_args)) | ||
897 | 51 | |||
898 | 52 | |||
899 | 53 | def record(method, arguments, result): | ||
900 | 54 | """ Utility function which can be used to record test data | ||
901 | 55 | during synchronisations. Call it from CoswinOracleAdapter._call | ||
902 | 56 | |||
903 | 57 | Then ``output_recorder`` can be used to write the data recorded | ||
904 | 58 | to a file. | ||
905 | 59 | """ | ||
906 | 60 | recorder[call_to_key(method, arguments)] = result | ||
907 | 61 | |||
908 | 62 | |||
909 | 63 | def output_recorder(filename): | ||
910 | 64 | import pprint | ||
911 | 65 | with open(filename, 'w') as f: | ||
912 | 66 | pprint.pprint(recorder, f) | ||
913 | 67 | _logger.debug('recorder written to file %s', filename) | ||
914 | 68 | |||
915 | 69 | |||
916 | 70 | # class ICOPSLocation(object): | ||
917 | 71 | |||
918 | 72 | # def __init__(self, location, db_name, username, password): | ||
919 | 73 | # self.location = location | ||
920 | 74 | # self.db_name = db_name | ||
921 | 75 | # self.username = username | ||
922 | 76 | # self.password = password | ||
923 | 77 | |||
924 | 78 | |||
925 | 79 | class GenericAdapter(CRUDAdapter): | ||
926 | 80 | |||
927 | 81 | """ External Records Adapter for Coswin """ | ||
928 | 82 | |||
929 | 83 | def __init__(self, environment): | ||
930 | 84 | """ | ||
931 | 85 | |||
932 | 86 | :param environment: current environment (backend, session, ...) | ||
933 | 87 | :type environment: :py:class:`connector.connector.Environment` | ||
934 | 88 | """ | ||
935 | 89 | super(GenericAdapter, self).__init__(environment) | ||
936 | 90 | # self.icops = ICOPSLocation(self.backend_record.icops_server, | ||
937 | 91 | # self.backend_record.backup_server) | ||
938 | 92 | |||
939 | 93 | def search(self, filters=None): | ||
940 | 94 | """ Search records according to some criterias | ||
941 | 95 | and returns a list of ids """ | ||
942 | 96 | raise NotImplementedError | ||
943 | 97 | |||
944 | 98 | def read(self, id, attributes=None): | ||
945 | 99 | """ Returns the information of a record """ | ||
946 | 100 | raise NotImplementedError | ||
947 | 101 | |||
948 | 102 | def search_read(self, filters=None): | ||
949 | 103 | """ Search records according to some criterias | ||
950 | 104 | and returns their information""" | ||
951 | 105 | raise NotImplementedError | ||
952 | 106 | |||
953 | 107 | def create(self, data): | ||
954 | 108 | """ Create a record on the external system """ | ||
955 | 109 | raise NotImplementedError | ||
956 | 110 | |||
957 | 111 | def write(self, id, data): | ||
958 | 112 | """ Update records on the external system """ | ||
959 | 113 | raise NotImplementedError | ||
960 | 114 | |||
961 | 115 | def delete(self, id): | ||
962 | 116 | """ Delete a record on the external system """ | ||
963 | 117 | raise NotImplementedError | ||
964 | 118 | |||
965 | 119 | def _write(self, text): | ||
966 | 120 | return True | ||
967 | 121 | |||
968 | 122 | |||
969 | 123 | class ICOPSAdapter(GenericAdapter): | ||
970 | 124 | |||
971 | 125 | _model_name = None | ||
972 | 126 | |||
973 | 127 | def __init__(self, environment): | ||
974 | 128 | super(GenericAdapter, self).__init__(environment) | ||
975 | 129 | self._icops = None | ||
976 | 130 | self._backend_to = None | ||
977 | 131 | |||
978 | 132 | def _get_pool(self): | ||
979 | 133 | raise NotImplementedError | ||
980 | 134 | |||
981 | 135 | def create(self, data): | ||
982 | 136 | sess = self.session | ||
983 | 137 | pool = self._get_pool() | ||
984 | 138 | return pool.create( | ||
985 | 139 | sess.cr, self._backend_to.icops_uid.id, data, {'icops': True}) | ||
986 | 140 | |||
987 | 141 | def write(self, id, data): | ||
988 | 142 | sess = self.session | ||
989 | 143 | pool = self._get_pool() | ||
990 | 144 | pool.write(sess.cr, self._backend_to.icops_uid.id, id, data, | ||
991 | 145 | {'icops': True}) | ||
992 | 146 | |||
993 | 147 | def delete(self, id): | ||
994 | 148 | sess = self.session | ||
995 | 149 | pool = self._get_pool() | ||
996 | 150 | pool.unlink(sess.cr, self._backend_to.icops_uid.id, [id], | ||
997 | 151 | {'icops': True}) | ||
998 | 0 | 152 | ||
999 | === added file 'base_intercompany/unit/binder.py' | |||
1000 | --- base_intercompany/unit/binder.py 1970-01-01 00:00:00 +0000 | |||
1001 | +++ base_intercompany/unit/binder.py 2014-02-23 01:10:59 +0000 | |||
1002 | @@ -0,0 +1,122 @@ | |||
1003 | 1 | # -*- coding: utf-8 -*- | ||
1004 | 2 | ############################################################################## | ||
1005 | 3 | # | ||
1006 | 4 | # OpenERP, Open Source Management Solution | ||
1007 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
1008 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
1009 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
1010 | 8 | |||
1011 | 9 | # This program is free software: you can redistribute it and/or modify | ||
1012 | 10 | # it under the terms of the GNU Affero General Public License as | ||
1013 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
1014 | 12 | # License, or (at your option) any later version. | ||
1015 | 13 | # | ||
1016 | 14 | # This program is distributed in the hope that it will be useful, | ||
1017 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1018 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1019 | 17 | # GNU Affero General Public License for more details. | ||
1020 | 18 | # | ||
1021 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
1022 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1023 | 21 | # | ||
1024 | 22 | ############################################################################## | ||
1025 | 23 | |||
1026 | 24 | from datetime import datetime | ||
1027 | 25 | from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT | ||
1028 | 26 | from openerp.addons.connector.connector import Binder | ||
1029 | 27 | from ..backend import icops | ||
1030 | 28 | |||
1031 | 29 | |||
1032 | 30 | class ICOPSBinder(Binder): | ||
1033 | 31 | """ Generic Binder for ICOPS """ | ||
1034 | 32 | |||
1035 | 33 | |||
1036 | 34 | @icops | ||
1037 | 35 | class ICOPSModelBinder(ICOPSBinder): | ||
1038 | 36 | """ | ||
1039 | 37 | Bindings are done directly on the binding model. | ||
1040 | 38 | |||
1041 | 39 | Binding models are models called ``icops.{normal_model}``, | ||
1042 | 40 | like ``icops.res.partner`` or ``icops.sale.order``. | ||
1043 | 41 | They are ``_inherits`` of the normal models and contains | ||
1044 | 42 | the ICOPS ID, the ID of the ICOPS Backend and the additional | ||
1045 | 43 | fields belonging to the ICOPS instance. | ||
1046 | 44 | """ | ||
1047 | 45 | _model_name = [ | ||
1048 | 46 | 'icops.sale.order', | ||
1049 | 47 | 'icops.sale.order.line', | ||
1050 | 48 | 'icops.purchase.order', | ||
1051 | 49 | 'icops.purchase.order.line' | ||
1052 | 50 | ] | ||
1053 | 51 | |||
1054 | 52 | def to_openerp(self, external_id, unwrap=False): | ||
1055 | 53 | """ Give the OpenERP ID for an external ID | ||
1056 | 54 | |||
1057 | 55 | :param external_id: external ID for which we want the OpenERP ID | ||
1058 | 56 | :param unwrap: if True, returns the openerp_id of the icops_xxxx | ||
1059 | 57 | record, else return the id (binding id) of that record | ||
1060 | 58 | :return: a record ID, depending on the value of unwrap, | ||
1061 | 59 | or None if the external_id is not mapped | ||
1062 | 60 | :rtype: int | ||
1063 | 61 | """ | ||
1064 | 62 | binding_ids = self.session.search( | ||
1065 | 63 | self.model._name, | ||
1066 | 64 | [('icops_id', '=', external_id), | ||
1067 | 65 | ('backend_id', '=', self.backend_record.id)]) | ||
1068 | 66 | if not binding_ids: | ||
1069 | 67 | return None | ||
1070 | 68 | assert len(binding_ids) == 1, "Several records found: %s" % binding_ids | ||
1071 | 69 | binding_id = binding_ids[0] | ||
1072 | 70 | if unwrap: | ||
1073 | 71 | return self.session.read(self.model._name, | ||
1074 | 72 | binding_id, | ||
1075 | 73 | ['openerp_id'])['openerp_id'][0] | ||
1076 | 74 | else: | ||
1077 | 75 | return binding_id | ||
1078 | 76 | |||
1079 | 77 | def to_backend(self, binding_id): | ||
1080 | 78 | """ Give the external ID for an OpenERP ID | ||
1081 | 79 | |||
1082 | 80 | :param binding_id: OpenERP ID for which we want the external id | ||
1083 | 81 | :return: backend identifier of the record | ||
1084 | 82 | """ | ||
1085 | 83 | record = self.session.browse(self.model._name, | ||
1086 | 84 | binding_id) | ||
1087 | 85 | assert record | ||
1088 | 86 | res = {} | ||
1089 | 87 | for icops in record.icops_ids: | ||
1090 | 88 | key = '%s_%s' % (icops.backend_id.id, icops.concept) | ||
1091 | 89 | res[key] = {'id': icops.record_id} | ||
1092 | 90 | return res | ||
1093 | 91 | |||
1094 | 92 | def bind(self, records, binding_id): | ||
1095 | 93 | """ Create the link between an external ID and an OpenERP ID and | ||
1096 | 94 | update the last synchronization date. | ||
1097 | 95 | |||
1098 | 96 | :param external_ids: External ID to bind | ||
1099 | 97 | :param binding_id: OpenERP ID to bind | ||
1100 | 98 | :type binding_id: int | ||
1101 | 99 | """ | ||
1102 | 100 | # avoid to trigger the export when we modify the `icops_id` | ||
1103 | 101 | if not records: | ||
1104 | 102 | return | ||
1105 | 103 | context = self.session.context.copy() | ||
1106 | 104 | context['icops'] = True | ||
1107 | 105 | now_fmt = datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT) | ||
1108 | 106 | icops_ids = [] | ||
1109 | 107 | for record, record_id in records.items(): | ||
1110 | 108 | backend_id, concept = record.split('_') | ||
1111 | 109 | |||
1112 | 110 | icops_id = (0, 0, {'record_id': record_id['id'], | ||
1113 | 111 | 'backend_id': backend_id, | ||
1114 | 112 | 'concept': concept, | ||
1115 | 113 | 'binding_id': binding_id, | ||
1116 | 114 | 'model': record_id['model']}) | ||
1117 | 115 | icops_ids.append(icops_id) | ||
1118 | 116 | |||
1119 | 117 | self.environment.model.write( | ||
1120 | 118 | self.session.cr, | ||
1121 | 119 | self.session.uid, | ||
1122 | 120 | binding_id, | ||
1123 | 121 | {'icops_ids': icops_ids, 'sync_date': now_fmt}, | ||
1124 | 122 | context=context) | ||
1125 | 0 | 123 | ||
1126 | === added file 'base_intercompany/unit/export_synchronizer.py' | |||
1127 | --- base_intercompany/unit/export_synchronizer.py 1970-01-01 00:00:00 +0000 | |||
1128 | +++ base_intercompany/unit/export_synchronizer.py 2014-02-23 01:10:59 +0000 | |||
1129 | @@ -0,0 +1,258 @@ | |||
1130 | 1 | # -*- coding: utf-8 -*- | ||
1131 | 2 | ############################################################################## | ||
1132 | 3 | # | ||
1133 | 4 | # OpenERP, Open Source Management Solution | ||
1134 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
1135 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
1136 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
1137 | 8 | |||
1138 | 9 | # This program is free software: you can redistribute it and/or modify | ||
1139 | 10 | # it under the terms of the GNU Affero General Public License as | ||
1140 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
1141 | 12 | # License, or (at your option) any later version. | ||
1142 | 13 | # | ||
1143 | 14 | # This program is distributed in the hope that it will be useful, | ||
1144 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1145 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1146 | 17 | # GNU Affero General Public License for more details. | ||
1147 | 18 | # | ||
1148 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
1149 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1150 | 21 | # | ||
1151 | 22 | ############################################################################## | ||
1152 | 23 | |||
1153 | 24 | import logging | ||
1154 | 25 | from openerp.tools.translate import _ | ||
1155 | 26 | from openerp.addons.connector.queue.job import job | ||
1156 | 27 | from openerp.addons.connector.unit.synchronizer import ExportSynchronizer | ||
1157 | 28 | from ..connector import get_environment | ||
1158 | 29 | from openerp.addons.connector.exception import MappingError | ||
1159 | 30 | from osv import osv | ||
1160 | 31 | |||
1161 | 32 | _logger = logging.getLogger(__name__) | ||
1162 | 33 | |||
1163 | 34 | |||
1164 | 35 | """ | ||
1165 | 36 | |||
1166 | 37 | Exporters for ICOPS. | ||
1167 | 38 | |||
1168 | 39 | In addition to its export job, an exporter has to: | ||
1169 | 40 | |||
1170 | 41 | * check in ICOPS if the record has been updated more recently than the | ||
1171 | 42 | last sync date and if yes, delay an import | ||
1172 | 43 | * call the ``bind`` method of the binder to update the last sync date | ||
1173 | 44 | |||
1174 | 45 | """ | ||
1175 | 46 | |||
1176 | 47 | |||
1177 | 48 | class ICOPSBaseExporter(ExportSynchronizer): | ||
1178 | 49 | |||
1179 | 50 | """ Base exporter for ICOPS """ | ||
1180 | 51 | |||
1181 | 52 | def __init__(self, environment): | ||
1182 | 53 | """ | ||
1183 | 54 | :param environment: current environment (backend, session, ...) | ||
1184 | 55 | :type environment: :py:class:`connector.connector.Environment` | ||
1185 | 56 | """ | ||
1186 | 57 | super(ICOPSBaseExporter, self).__init__(environment) | ||
1187 | 58 | self.binding_id = None | ||
1188 | 59 | self.icops_ids = {} | ||
1189 | 60 | |||
1190 | 61 | def _get_openerp_data(self): | ||
1191 | 62 | """ Return the raw OpenERP data for ``self.binding_id`` """ | ||
1192 | 63 | return self.session.browse(self.model._name, self.binding_id) | ||
1193 | 64 | |||
1194 | 65 | def run(self, binding_id, *args, **kwargs): | ||
1195 | 66 | """ Run the synchronization | ||
1196 | 67 | |||
1197 | 68 | :param binding_id: identifier of the binding record to export | ||
1198 | 69 | """ | ||
1199 | 70 | self.binding_id = binding_id | ||
1200 | 71 | self.binding_record = self._get_openerp_data() | ||
1201 | 72 | |||
1202 | 73 | self.icops_ids = self.binder.to_backend(self.binding_id) | ||
1203 | 74 | result = self._run(*args, **kwargs) | ||
1204 | 75 | self.binder.bind(self.icops_ids, self.binding_id) | ||
1205 | 76 | return result | ||
1206 | 77 | |||
1207 | 78 | def _run(self): | ||
1208 | 79 | """ Flow of the synchronization, implemented in inherited classes""" | ||
1209 | 80 | raise NotImplementedError | ||
1210 | 81 | |||
1211 | 82 | |||
1212 | 83 | class ICOPSExporter(ICOPSBaseExporter): | ||
1213 | 84 | |||
1214 | 85 | _concepts = None | ||
1215 | 86 | """ A common flow for the exports to ICOPS """ | ||
1216 | 87 | def __init__(self, environment): | ||
1217 | 88 | """ | ||
1218 | 89 | :param environment: current environment (backend, session, ...) | ||
1219 | 90 | :type environment: :py:class:`connector.connector.Environment` | ||
1220 | 91 | """ | ||
1221 | 92 | super(ICOPSExporter, self).__init__(environment) | ||
1222 | 93 | self.binding_record = None | ||
1223 | 94 | |||
1224 | 95 | def _has_to_skip(self): | ||
1225 | 96 | """ Return True if the export can be skipped """ | ||
1226 | 97 | return False | ||
1227 | 98 | |||
1228 | 99 | def _routing(self, record, fields=None): | ||
1229 | 100 | fields = fields or [] | ||
1230 | 101 | icops = self.mapper._icops | ||
1231 | 102 | icops_id = self._get_icops_id( | ||
1232 | 103 | icops.backend_to.id, icops.concept) | ||
1233 | 104 | if not icops_id: | ||
1234 | 105 | return | ||
1235 | 106 | if 'icops_delete' in fields: | ||
1236 | 107 | self._delete(icops_id) | ||
1237 | 108 | else: | ||
1238 | 109 | self._custom_routing(icops_id, record, fields) | ||
1239 | 110 | |||
1240 | 111 | def _custom_routing(self, id, record, fields=None): | ||
1241 | 112 | self._write(id, record) | ||
1242 | 113 | |||
1243 | 114 | def _run(self, fields=None): | ||
1244 | 115 | """ Flow of the synchronization, implemented in inherited classes""" | ||
1245 | 116 | assert self.binding_id | ||
1246 | 117 | assert self.binding_record | ||
1247 | 118 | |||
1248 | 119 | if not self.icops_ids: | ||
1249 | 120 | fields = None # should be created with all the fields | ||
1250 | 121 | |||
1251 | 122 | if self._has_to_skip(): | ||
1252 | 123 | return | ||
1253 | 124 | |||
1254 | 125 | nb_records = 0 | ||
1255 | 126 | icops_ids = {} | ||
1256 | 127 | |||
1257 | 128 | for icops in self._get_icops(): | ||
1258 | 129 | backend = self._get_backend_with_permission(icops) | ||
1259 | 130 | self._set_icops(icops, backend) | ||
1260 | 131 | map_record = self._map_data(fields=fields) | ||
1261 | 132 | if self.icops_ids: | ||
1262 | 133 | record = None | ||
1263 | 134 | try: | ||
1264 | 135 | record = self._update_data(map_record, fields=fields) | ||
1265 | 136 | except MappingError as e: | ||
1266 | 137 | continue | ||
1267 | 138 | if not record: | ||
1268 | 139 | continue | ||
1269 | 140 | nb_records += 1 | ||
1270 | 141 | self._validate_data(record) | ||
1271 | 142 | self._routing(record, fields) | ||
1272 | 143 | else: | ||
1273 | 144 | record = None | ||
1274 | 145 | try: | ||
1275 | 146 | record = self._create_data(map_record, fields=fields) | ||
1276 | 147 | except MappingError as e: | ||
1277 | 148 | continue | ||
1278 | 149 | if not record: | ||
1279 | 150 | continue | ||
1280 | 151 | nb_records += 1 | ||
1281 | 152 | key = '%s_%s' % (icops.backend_to.id, icops.concept) | ||
1282 | 153 | icops_ids[key] = { | ||
1283 | 154 | 'id': self._create(record), | ||
1284 | 155 | 'model': self.backend_adapter._get_pool()._name | ||
1285 | 156 | } | ||
1286 | 157 | |||
1287 | 158 | self.icops_ids = icops_ids | ||
1288 | 159 | |||
1289 | 160 | if nb_records == 0: | ||
1290 | 161 | return _('Nothing to export.') | ||
1291 | 162 | return _('Record exported.') | ||
1292 | 163 | |||
1293 | 164 | def _get_backend_with_permission(self, icops): | ||
1294 | 165 | sess = self.session | ||
1295 | 166 | backend_pool = sess.pool.get('icops.backend') | ||
1296 | 167 | return backend_pool.browse( | ||
1297 | 168 | sess.cr, icops.icops_uid.id, icops.backend_to.id) | ||
1298 | 169 | |||
1299 | 170 | def _get_icops(self): | ||
1300 | 171 | res = [] | ||
1301 | 172 | sess = self.session | ||
1302 | 173 | user_pool = sess.pool.get('res.users') | ||
1303 | 174 | user = user_pool.browse(sess.cr, sess.uid, sess.uid) | ||
1304 | 175 | backend_pool = sess.pool.get('icops.backend') | ||
1305 | 176 | backend_ids = backend_pool.search( | ||
1306 | 177 | sess.cr, sess.uid, [('company_id', '=', user.company_id.id)]) | ||
1307 | 178 | if not backend_ids: | ||
1308 | 179 | return res | ||
1309 | 180 | intercompany_pool = sess.pool.get('res.intercompany') | ||
1310 | 181 | intercompany_ids = intercompany_pool.search( | ||
1311 | 182 | sess.cr, sess.uid, | ||
1312 | 183 | [('backend_id', '=', backend_ids[0]), | ||
1313 | 184 | ('concept', 'in', self._concepts), | ||
1314 | 185 | ('model', '=', self.binding_record.openerp_id._name)]) | ||
1315 | 186 | res = intercompany_pool.browse(sess.cr, sess.uid, intercompany_ids) | ||
1316 | 187 | return res | ||
1317 | 188 | |||
1318 | 189 | def _set_icops(self, icops, backend): | ||
1319 | 190 | self.mapper._icops = icops | ||
1320 | 191 | self.mapper._backend_to = backend | ||
1321 | 192 | self.backend_adapter._icops = icops | ||
1322 | 193 | self.backend_adapter._backend_to = backend | ||
1323 | 194 | |||
1324 | 195 | def _create(self, data): | ||
1325 | 196 | if not self.backend_adapter._icops.on_create: | ||
1326 | 197 | raise osv.except_osv('ICOPS Error', 'Can\'t create') | ||
1327 | 198 | self._validate_data(data) | ||
1328 | 199 | return self.backend_adapter.create(data) | ||
1329 | 200 | |||
1330 | 201 | def _write(self, id, data): | ||
1331 | 202 | context = self.session.context or {} | ||
1332 | 203 | if not self.backend_adapter._icops.on_write and not 'icops' in context: | ||
1333 | 204 | raise osv.except_osv('ICOPS Error', 'Can\'t write') | ||
1334 | 205 | self.backend_adapter.write(id, data) | ||
1335 | 206 | |||
1336 | 207 | def _confirm(self, id): | ||
1337 | 208 | if not self.backend_adapter._icops.on_confirm: | ||
1338 | 209 | raise osv.except_osv('ICOPS Error', 'Can\'t confirm') | ||
1339 | 210 | self.backend_adapter.confirm(id) | ||
1340 | 211 | |||
1341 | 212 | def _cancel(self, id): | ||
1342 | 213 | if not self.backend_adapter._icops.on_cancel: | ||
1343 | 214 | raise osv.except_osv('ICOPS Error', 'Can\'t cancel') | ||
1344 | 215 | self.backend_adapter.cancel(id) | ||
1345 | 216 | |||
1346 | 217 | def _delete(self, id): | ||
1347 | 218 | if not self.backend_adapter._icops.on_unlink: | ||
1348 | 219 | raise osv.except_osv('ICOPS Error', 'Can\'t delete') | ||
1349 | 220 | self.backend_adapter.delete(id) | ||
1350 | 221 | |||
1351 | 222 | def _map_data(self, fields=None): | ||
1352 | 223 | """ Convert the external record to OpenERP """ | ||
1353 | 224 | return self.mapper.map_record(self.binding_record) | ||
1354 | 225 | |||
1355 | 226 | def _create_data(self, map_record, fields=None, **kwargs): | ||
1356 | 227 | """ Get the data to pass to :py:meth:`_create` """ | ||
1357 | 228 | return map_record.values(for_create=True, fields=fields, **kwargs) | ||
1358 | 229 | |||
1359 | 230 | def _update_data(self, map_record, fields=None, **kwargs): | ||
1360 | 231 | """ Get the data to pass to :py:meth:`_update` """ | ||
1361 | 232 | return map_record.values(fields=fields, **kwargs) | ||
1362 | 233 | |||
1363 | 234 | def _validate_data(self, data): | ||
1364 | 235 | """ Check if the values to export are correct | ||
1365 | 236 | |||
1366 | 237 | Pro-actively check before the ``Model.create`` or | ||
1367 | 238 | ``Model.update`` if some fields are missing | ||
1368 | 239 | |||
1369 | 240 | Raise `InvalidDataError` | ||
1370 | 241 | """ | ||
1371 | 242 | return | ||
1372 | 243 | |||
1373 | 244 | def _get_icops_id(self, backend_id, concept): | ||
1374 | 245 | key = '%s_%s' % (backend_id, concept) | ||
1375 | 246 | try: | ||
1376 | 247 | return self.icops_ids[key]['id'] | ||
1377 | 248 | except: | ||
1378 | 249 | return None | ||
1379 | 250 | |||
1380 | 251 | |||
1381 | 252 | @job | ||
1382 | 253 | def export_record(session, model_name, binding_id, fields=None): | ||
1383 | 254 | """ Export a record on ICOPS """ | ||
1384 | 255 | record = session.browse(model_name, binding_id) | ||
1385 | 256 | env = get_environment(session, model_name, record.backend_id.id) | ||
1386 | 257 | exporter = env.get_connector_unit(ICOPSExporter) | ||
1387 | 258 | return exporter.run(binding_id, fields=fields) | ||
1388 | 0 | 259 | ||
1389 | === added file 'base_intercompany/unit/mapper.py' | |||
1390 | --- base_intercompany/unit/mapper.py 1970-01-01 00:00:00 +0000 | |||
1391 | +++ base_intercompany/unit/mapper.py 2014-02-23 01:10:59 +0000 | |||
1392 | @@ -0,0 +1,66 @@ | |||
1393 | 1 | # -*- coding: utf-8 -*- | ||
1394 | 2 | ############################################################################## | ||
1395 | 3 | # | ||
1396 | 4 | # OpenERP, Open Source Management Solution | ||
1397 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
1398 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
1399 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
1400 | 8 | |||
1401 | 9 | # This program is free software: you can redistribute it and/or modify | ||
1402 | 10 | # it under the terms of the GNU Affero General Public License as | ||
1403 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
1404 | 12 | # License, or (at your option) any later version. | ||
1405 | 13 | # | ||
1406 | 14 | # This program is distributed in the hope that it will be useful, | ||
1407 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1408 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1409 | 17 | # GNU Affero General Public License for more details. | ||
1410 | 18 | # | ||
1411 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
1412 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1413 | 21 | # | ||
1414 | 22 | ############################################################################## | ||
1415 | 23 | from openerp.addons.connector.unit.mapper import (ExportMapper, ExportMapChild) | ||
1416 | 24 | |||
1417 | 25 | |||
1418 | 26 | class ICOPSExportMapChild(ExportMapChild): | ||
1419 | 27 | """ :py:class:`MapChild` for the Exports """ | ||
1420 | 28 | |||
1421 | 29 | def _child_mapper(self): | ||
1422 | 30 | mapper = self.get_connector_unit_for_model( | ||
1423 | 31 | ExportMapper, self.model._name) | ||
1424 | 32 | mapper._icops = self._icops | ||
1425 | 33 | mapper._backend_to = self._backend_to | ||
1426 | 34 | return mapper | ||
1427 | 35 | |||
1428 | 36 | def format_items(self, items_values): | ||
1429 | 37 | items = super(ICOPSExportMapChild, self).format_items(items_values) | ||
1430 | 38 | return [(5, 0)] + [(0, 0, data) for data in items] | ||
1431 | 39 | |||
1432 | 40 | |||
1433 | 41 | class ICOPSExportMapper(ExportMapper): | ||
1434 | 42 | _map_child_class = ICOPSExportMapChild | ||
1435 | 43 | |||
1436 | 44 | def __init__(self, environment): | ||
1437 | 45 | """ | ||
1438 | 46 | |||
1439 | 47 | :param environment: current environment (backend, session, ...) | ||
1440 | 48 | :type environment: :py:class:`connector.connector.Environment` | ||
1441 | 49 | """ | ||
1442 | 50 | super(ICOPSExportMapper, self).__init__(environment) | ||
1443 | 51 | self._icops = None | ||
1444 | 52 | self._backend_to = None | ||
1445 | 53 | |||
1446 | 54 | def _get_map_child_unit(self, model_name): | ||
1447 | 55 | mapper = super(ICOPSExportMapper, self)._get_map_child_unit(model_name) | ||
1448 | 56 | mapper._icops = self._icops | ||
1449 | 57 | mapper._backend_to = self._backend_to | ||
1450 | 58 | return mapper | ||
1451 | 59 | |||
1452 | 60 | def _get_mapping(self, name, record): | ||
1453 | 61 | res = {} | ||
1454 | 62 | for method in dir(self): | ||
1455 | 63 | if method.startswith('%s_' % name): | ||
1456 | 64 | new_dict = getattr(self, method)(record) | ||
1457 | 65 | res = dict(res.items() + new_dict.items()) | ||
1458 | 66 | return res | ||
1459 | 0 | 67 | ||
1460 | === added directory 'base_intercompany_sale' | |||
1461 | === added file 'base_intercompany_sale/__init__.py' | |||
1462 | --- base_intercompany_sale/__init__.py 1970-01-01 00:00:00 +0000 | |||
1463 | +++ base_intercompany_sale/__init__.py 2014-02-23 01:10:59 +0000 | |||
1464 | @@ -0,0 +1,28 @@ | |||
1465 | 1 | # -*- coding: utf-8 -*- | ||
1466 | 2 | ############################################################################## | ||
1467 | 3 | # | ||
1468 | 4 | # OpenERP, Open Source Management Solution | ||
1469 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
1470 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
1471 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
1472 | 8 | |||
1473 | 9 | # This program is free software: you can redistribute it and/or modify | ||
1474 | 10 | # it under the terms of the GNU Affero General Public License as | ||
1475 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
1476 | 12 | # License, or (at your option) any later version. | ||
1477 | 13 | # | ||
1478 | 14 | # This program is distributed in the hope that it will be useful, | ||
1479 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1480 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1481 | 17 | # GNU Affero General Public License for more details. | ||
1482 | 18 | # | ||
1483 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
1484 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1485 | 21 | # | ||
1486 | 22 | ############################################################################## | ||
1487 | 23 | import connector | ||
1488 | 24 | import consumer | ||
1489 | 25 | import company | ||
1490 | 26 | import icops_model | ||
1491 | 27 | import sale | ||
1492 | 28 | import purchase | ||
1493 | 0 | 29 | ||
1494 | === added file 'base_intercompany_sale/__openerp__.py' | |||
1495 | --- base_intercompany_sale/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
1496 | +++ base_intercompany_sale/__openerp__.py 2014-02-23 01:10:59 +0000 | |||
1497 | @@ -0,0 +1,50 @@ | |||
1498 | 1 | # -*- coding: utf-8 -*- | ||
1499 | 2 | ############################################################################## | ||
1500 | 3 | # | ||
1501 | 4 | # OpenERP, Open Source Management Solution | ||
1502 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
1503 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
1504 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
1505 | 8 | |||
1506 | 9 | # This program is free software: you can redistribute it and/or modify | ||
1507 | 10 | # it under the terms of the GNU Affero General Public License as | ||
1508 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
1509 | 12 | # License, or (at your option) any later version. | ||
1510 | 13 | # | ||
1511 | 14 | # This program is distributed in the hope that it will be useful, | ||
1512 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1513 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1514 | 17 | # GNU Affero General Public License for more details. | ||
1515 | 18 | # | ||
1516 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
1517 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1518 | 21 | # | ||
1519 | 22 | ############################################################################## | ||
1520 | 23 | |||
1521 | 24 | {'name': 'Base Intercompany Sale', | ||
1522 | 25 | 'version': '0.4', | ||
1523 | 26 | 'category': 'Sales Management', | ||
1524 | 27 | 'depends': ['base_intercompany', 'sale', 'purchase'], | ||
1525 | 28 | 'author': 'Elico Corp', | ||
1526 | 29 | 'license': 'AGPL-3', | ||
1527 | 30 | 'website': 'https://www.elico-corp.com', | ||
1528 | 31 | 'description': """ | ||
1529 | 32 | This module is an extension designed to manage Inter-company Process (ICOPS) | ||
1530 | 33 | and allows 2 companies to create Sale Orders and Purchase Order in each other. | ||
1531 | 34 | - Sale Order to Purchase Order (so2po) | ||
1532 | 35 | - Sale Order to Sale Order (so2so) | ||
1533 | 36 | - Purchase Order to Sale Order (po2so) | ||
1534 | 37 | - Handles the following events: Create, Update, Delete, Confirm and Cancel | ||
1535 | 38 | |||
1536 | 39 | TODO: demo data to be improved.\n | ||
1537 | 40 | Blueprint: https://blueprints.launchpad.net/multi-company/+spec/icops | ||
1538 | 41 | """, | ||
1539 | 42 | 'images': [], | ||
1540 | 43 | 'demo': ['base_intercompany_sale_demo.xml'], | ||
1541 | 44 | 'data': ['security/ir.model.access.csv', | ||
1542 | 45 | 'icops_model_view.xml', | ||
1543 | 46 | 'sale_view.xml', | ||
1544 | 47 | 'purchase_view.xml'], | ||
1545 | 48 | 'installable': True, | ||
1546 | 49 | 'application': False, | ||
1547 | 50 | } | ||
1548 | 0 | 51 | ||
1549 | === added file 'base_intercompany_sale/base_intercompany_sale_demo.xml' | |||
1550 | --- base_intercompany_sale/base_intercompany_sale_demo.xml 1970-01-01 00:00:00 +0000 | |||
1551 | +++ base_intercompany_sale/base_intercompany_sale_demo.xml 2014-02-23 01:10:59 +0000 | |||
1552 | @@ -0,0 +1,53 @@ | |||
1553 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
1554 | 2 | <openerp> | ||
1555 | 3 | <data noupdate="1"> | ||
1556 | 4 | |||
1557 | 5 | <record id="base_intercompany.user_origin" model="res.users"> | ||
1558 | 6 | <field name="groups_id" eval="[(4, ref('base.group_sale_manager')), (4, ref('purchase.group_purchase_manager')), (4, ref('stock.group_stock_manager')), (4, ref('stock.group_locations'))]"/> | ||
1559 | 7 | </record> | ||
1560 | 8 | |||
1561 | 9 | <record id="base_intercompany.user_destination" model="res.users"> | ||
1562 | 10 | <field name="groups_id" eval="[(4, ref('base.group_sale_manager')), (4, ref('purchase.group_purchase_manager')), (4, ref('stock.group_stock_manager')), (4, ref('stock.group_locations'))]"/> | ||
1563 | 11 | </record> | ||
1564 | 12 | |||
1565 | 13 | <record id="warehouse_origin" model="stock.warehouse"> | ||
1566 | 14 | <field name="name">Warehouse Origin</field> | ||
1567 | 15 | <field name="company_id" ref="base_intercompany.company_origin" /> | ||
1568 | 16 | </record> | ||
1569 | 17 | |||
1570 | 18 | <record id="warehouse_destination" model="stock.warehouse"> | ||
1571 | 19 | <field name="name">Warehouse Destination</field> | ||
1572 | 20 | <field name="company_id" ref="base_intercompany.company_destination" /> | ||
1573 | 21 | </record> | ||
1574 | 22 | |||
1575 | 23 | <record id="shop_origin" model="sale.shop"> | ||
1576 | 24 | <field name="name">Shop Origin</field> | ||
1577 | 25 | <field name="warehouse_id" ref="warehouse_origin" /> | ||
1578 | 26 | <field name="payment_default_id" ref="account.account_payment_term_immediate" /> | ||
1579 | 27 | <field name="company_id" ref="base_intercompany.company_origin" /> | ||
1580 | 28 | </record> | ||
1581 | 29 | |||
1582 | 30 | <record id="shop_destination" model="sale.shop"> | ||
1583 | 31 | <field name="name">Shop Destination</field> | ||
1584 | 32 | <field name="warehouse_id" ref="warehouse_destination" /> | ||
1585 | 33 | <field name="payment_default_id" ref="account.account_payment_term_immediate" /> | ||
1586 | 34 | <field name="company_id" ref="base_intercompany.company_destination" /> | ||
1587 | 35 | </record> | ||
1588 | 36 | |||
1589 | 37 | <!-- ICOPS Setup --> | ||
1590 | 38 | <record id="base_intercompany.backend_origin" model="icops.backend"> | ||
1591 | 39 | <field name="icops_shop_id" ref="shop_origin" /> | ||
1592 | 40 | <field name="icops_ids" eval="[(0, 0, {'concept': 'so2po', 'backend_to': ref('base_intercompany.backend_destination'), 'on_create': True, 'on_write': True, 'on_unlink': True, 'on_confirm': True, 'on_cancel': True})]" /> | ||
1593 | 41 | </record> | ||
1594 | 42 | |||
1595 | 43 | <record id="base_intercompany.backend_destination" model="icops.backend"> | ||
1596 | 44 | <field name="icops_shop_id" ref="shop_destination" /> | ||
1597 | 45 | </record> | ||
1598 | 46 | |||
1599 | 47 | <!-- Remove company_id from stock --> | ||
1600 | 48 | <function model="stock.location" name="write"> | ||
1601 | 49 | <function eval="[[]]" model="stock.location" name="search"/> | ||
1602 | 50 | <value eval="{'company_id': None}" /> | ||
1603 | 51 | </function> | ||
1604 | 52 | </data> | ||
1605 | 53 | </openerp> | ||
1606 | 0 | \ No newline at end of file | 54 | \ No newline at end of file |
1607 | 1 | 55 | ||
1608 | === added file 'base_intercompany_sale/company.py' | |||
1609 | --- base_intercompany_sale/company.py 1970-01-01 00:00:00 +0000 | |||
1610 | +++ base_intercompany_sale/company.py 2014-02-23 01:10:59 +0000 | |||
1611 | @@ -0,0 +1,56 @@ | |||
1612 | 1 | # -*- coding: utf-8 -*- | ||
1613 | 2 | ############################################################################## | ||
1614 | 3 | # | ||
1615 | 4 | # OpenERP, Open Source Management Solution | ||
1616 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
1617 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
1618 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
1619 | 8 | |||
1620 | 9 | # This program is free software: you can redistribute it and/or modify | ||
1621 | 10 | # it under the terms of the GNU Affero General Public License as | ||
1622 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
1623 | 12 | # License, or (at your option) any later version. | ||
1624 | 13 | # | ||
1625 | 14 | # This program is distributed in the hope that it will be useful, | ||
1626 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1627 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1628 | 17 | # GNU Affero General Public License for more details. | ||
1629 | 18 | # | ||
1630 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
1631 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1632 | 21 | # | ||
1633 | 22 | ############################################################################## | ||
1634 | 23 | from openerp.osv import fields, orm | ||
1635 | 24 | |||
1636 | 25 | |||
1637 | 26 | class res_intercompany(orm.Model): | ||
1638 | 27 | _inherit = 'res.intercompany' | ||
1639 | 28 | |||
1640 | 29 | def _select_concepts(self, cr, uid, context=None): | ||
1641 | 30 | """ Available concepts | ||
1642 | 31 | |||
1643 | 32 | Can be inherited to add custom versions. | ||
1644 | 33 | """ | ||
1645 | 34 | res = super(res_intercompany, self)._select_concepts(cr, uid, context) | ||
1646 | 35 | res += [('so2po', 'SO to PO'), | ||
1647 | 36 | ('so2so', 'SO to SO'), | ||
1648 | 37 | ('po2so', 'PO to SO')] | ||
1649 | 38 | return res | ||
1650 | 39 | |||
1651 | 40 | def _select_models(self, cr, uid, context=None): | ||
1652 | 41 | """ Available Object names | ||
1653 | 42 | |||
1654 | 43 | Can be inherited to add custom versions. | ||
1655 | 44 | """ | ||
1656 | 45 | res = super(res_intercompany, self)._select_models( | ||
1657 | 46 | cr, uid, context) | ||
1658 | 47 | new_dict = {'so2po': 'sale.order', | ||
1659 | 48 | 'so2so': 'sale.order', | ||
1660 | 49 | 'po2so': 'purchase.order'} | ||
1661 | 50 | res = dict(res.items() + new_dict.items()) | ||
1662 | 51 | return res | ||
1663 | 52 | |||
1664 | 53 | _columns = { | ||
1665 | 54 | 'concept': fields.selection(_select_concepts, string="Concept", | ||
1666 | 55 | required=True), | ||
1667 | 56 | } | ||
1668 | 0 | 57 | ||
1669 | === added file 'base_intercompany_sale/connector.py' | |||
1670 | --- base_intercompany_sale/connector.py 1970-01-01 00:00:00 +0000 | |||
1671 | +++ base_intercompany_sale/connector.py 2014-02-23 01:10:59 +0000 | |||
1672 | @@ -0,0 +1,32 @@ | |||
1673 | 1 | # -*- coding: utf-8 -*- | ||
1674 | 2 | ############################################################################## | ||
1675 | 3 | # | ||
1676 | 4 | # OpenERP, Open Source Management Solution | ||
1677 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
1678 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
1679 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
1680 | 8 | |||
1681 | 9 | # This program is free software: you can redistribute it and/or modify | ||
1682 | 10 | # it under the terms of the GNU Affero General Public License as | ||
1683 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
1684 | 12 | # License, or (at your option) any later version. | ||
1685 | 13 | # | ||
1686 | 14 | # This program is distributed in the hope that it will be useful, | ||
1687 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1688 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1689 | 17 | # GNU Affero General Public License for more details. | ||
1690 | 18 | # | ||
1691 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
1692 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1693 | 21 | # | ||
1694 | 22 | ############################################################################## | ||
1695 | 23 | from openerp.osv import orm | ||
1696 | 24 | |||
1697 | 25 | |||
1698 | 26 | class base_intercompany_sale_installed(orm.AbstractModel): | ||
1699 | 27 | """Empty model used to know if the module is installed on the | ||
1700 | 28 | database. | ||
1701 | 29 | |||
1702 | 30 | If the model is in the registry, the module is installed. | ||
1703 | 31 | """ | ||
1704 | 32 | _name = 'base_intercompany_sale.installed' | ||
1705 | 0 | 33 | ||
1706 | === added file 'base_intercompany_sale/consumer.py' | |||
1707 | --- base_intercompany_sale/consumer.py 1970-01-01 00:00:00 +0000 | |||
1708 | +++ base_intercompany_sale/consumer.py 2014-02-23 01:10:59 +0000 | |||
1709 | @@ -0,0 +1,79 @@ | |||
1710 | 1 | # -*- coding: utf-8 -*- | ||
1711 | 2 | ############################################################################## | ||
1712 | 3 | # | ||
1713 | 4 | # OpenERP, Open Source Management Solution | ||
1714 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
1715 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
1716 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
1717 | 8 | |||
1718 | 9 | # This program is free software: you can redistribute it and/or modify | ||
1719 | 10 | # it under the terms of the GNU Affero General Public License as | ||
1720 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
1721 | 12 | # License, or (at your option) any later version. | ||
1722 | 13 | # | ||
1723 | 14 | # This program is distributed in the hope that it will be useful, | ||
1724 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1725 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1726 | 17 | # GNU Affero General Public License for more details. | ||
1727 | 18 | # | ||
1728 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
1729 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1730 | 21 | # | ||
1731 | 22 | ############################################################################## | ||
1732 | 23 | from openerp.addons.connector.event import (on_record_write, | ||
1733 | 24 | on_record_create, | ||
1734 | 25 | on_record_unlink | ||
1735 | 26 | ) | ||
1736 | 27 | from openerp.addons.base_intercompany.unit.export_synchronizer import ( | ||
1737 | 28 | export_record) | ||
1738 | 29 | |||
1739 | 30 | _MODEL_NAMES = ('sale.order', 'sale.order.line', | ||
1740 | 31 | 'purchase.order', 'purchase.order.line') | ||
1741 | 32 | _BIND_MODEL_NAMES = ('icops.sale.order', 'icops.sale.order.line', | ||
1742 | 33 | 'icops.purchase.order', 'icops.purchase.order.line') | ||
1743 | 34 | _UNLINK_MODEL_NAMES = ('sale.order', 'purchase.order') | ||
1744 | 35 | _UNLINK_BIND_MODEL_NAMES = ('icops.sale.order', 'icops.purchase.order') | ||
1745 | 36 | |||
1746 | 37 | |||
1747 | 38 | @on_record_create(model_names=_BIND_MODEL_NAMES) | ||
1748 | 39 | @on_record_write(model_names=_BIND_MODEL_NAMES) | ||
1749 | 40 | def delay_export(session, model_name, record_id, fields=None): | ||
1750 | 41 | """ Delay a job which export a binding record. | ||
1751 | 42 | |||
1752 | 43 | (A binding record being a ``icops.res.partner``, | ||
1753 | 44 | ``icops.sale.order``, ...) | ||
1754 | 45 | """ | ||
1755 | 46 | export_record(session, model_name, record_id, fields=fields) | ||
1756 | 47 | |||
1757 | 48 | |||
1758 | 49 | @on_record_write(model_names=_MODEL_NAMES) | ||
1759 | 50 | def delay_export_all_bindings(session, model_name, record_id, fields=None): | ||
1760 | 51 | """ Delay a job which export all the bindings of a record. | ||
1761 | 52 | |||
1762 | 53 | In this case, it is called on records of normal models and will delay | ||
1763 | 54 | the export for all the bindings. | ||
1764 | 55 | """ | ||
1765 | 56 | model = session.pool.get(model_name) | ||
1766 | 57 | record = model.browse(session.cr, session.uid, | ||
1767 | 58 | record_id, context=session.context) | ||
1768 | 59 | for binding in record.icops_bind_ids: | ||
1769 | 60 | export_record(session, binding._model._name, binding.id, | ||
1770 | 61 | fields=fields) | ||
1771 | 62 | |||
1772 | 63 | |||
1773 | 64 | @on_record_unlink(model_names=_UNLINK_MODEL_NAMES) | ||
1774 | 65 | def delay_unlink(session, model_name, record_id): | ||
1775 | 66 | """ Delay a job which delete a record on Magento. | ||
1776 | 67 | |||
1777 | 68 | Called on binding records.""" | ||
1778 | 69 | fields = {'icops_delete': True} | ||
1779 | 70 | delay_export_all_bindings(session, model_name, record_id, fields) | ||
1780 | 71 | |||
1781 | 72 | |||
1782 | 73 | @on_record_unlink(model_names=_UNLINK_BIND_MODEL_NAMES) | ||
1783 | 74 | def delay_unlink_binding(session, model_name, record_id): | ||
1784 | 75 | """ Delay a job which delete a record on Magento. | ||
1785 | 76 | |||
1786 | 77 | Called on binding records.""" | ||
1787 | 78 | fields = {'icops_delete': True} | ||
1788 | 79 | delay_export(session, model_name, record_id, fields) | ||
1789 | 0 | 80 | ||
1790 | === added file 'base_intercompany_sale/icops_model.py' | |||
1791 | --- base_intercompany_sale/icops_model.py 1970-01-01 00:00:00 +0000 | |||
1792 | +++ base_intercompany_sale/icops_model.py 2014-02-23 01:10:59 +0000 | |||
1793 | @@ -0,0 +1,33 @@ | |||
1794 | 1 | # -*- coding: utf-8 -*- | ||
1795 | 2 | ############################################################################## | ||
1796 | 3 | # | ||
1797 | 4 | # OpenERP, Open Source Management Solution | ||
1798 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
1799 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
1800 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
1801 | 8 | |||
1802 | 9 | # This program is free software: you can redistribute it and/or modify | ||
1803 | 10 | # it under the terms of the GNU Affero General Public License as | ||
1804 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
1805 | 12 | # License, or (at your option) any later version. | ||
1806 | 13 | # | ||
1807 | 14 | # This program is distributed in the hope that it will be useful, | ||
1808 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1809 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1810 | 17 | # GNU Affero General Public License for more details. | ||
1811 | 18 | # | ||
1812 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
1813 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1814 | 21 | # | ||
1815 | 22 | ############################################################################## | ||
1816 | 23 | from openerp.osv import fields, orm | ||
1817 | 24 | |||
1818 | 25 | |||
1819 | 26 | class icops_backend(orm.Model): | ||
1820 | 27 | _inherit = 'icops.backend' | ||
1821 | 28 | |||
1822 | 29 | _columns = { | ||
1823 | 30 | 'icops_shop_id': fields.many2one( | ||
1824 | 31 | 'sale.shop', 'IC Default location', | ||
1825 | 32 | required=True), | ||
1826 | 33 | } | ||
1827 | 0 | 34 | ||
1828 | === added file 'base_intercompany_sale/icops_model_view.xml' | |||
1829 | --- base_intercompany_sale/icops_model_view.xml 1970-01-01 00:00:00 +0000 | |||
1830 | +++ base_intercompany_sale/icops_model_view.xml 2014-02-23 01:10:59 +0000 | |||
1831 | @@ -0,0 +1,15 @@ | |||
1832 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
1833 | 2 | <openerp> | ||
1834 | 3 | <data> | ||
1835 | 4 | <record id="view_icops_backend_form" model="ir.ui.view"> | ||
1836 | 5 | <field name="name">icops.backend.form</field> | ||
1837 | 6 | <field name="model">icops.backend</field> | ||
1838 | 7 | <field name="inherit_id" ref="base_intercompany.view_icops_backend_form" /> | ||
1839 | 8 | <field name="arch" type="xml"> | ||
1840 | 9 | <field name="icops_uid" position="after"> | ||
1841 | 10 | <field name="icops_shop_id" cols="2" /> | ||
1842 | 11 | </field> | ||
1843 | 12 | </field> | ||
1844 | 13 | </record> | ||
1845 | 14 | </data> | ||
1846 | 15 | </openerp> | ||
1847 | 0 | \ No newline at end of file | 16 | \ No newline at end of file |
1848 | 1 | 17 | ||
1849 | === added file 'base_intercompany_sale/purchase.py' | |||
1850 | --- base_intercompany_sale/purchase.py 1970-01-01 00:00:00 +0000 | |||
1851 | +++ base_intercompany_sale/purchase.py 2014-02-23 01:10:59 +0000 | |||
1852 | @@ -0,0 +1,296 @@ | |||
1853 | 1 | # -*- coding: utf-8 -*- | ||
1854 | 2 | ############################################################################## | ||
1855 | 3 | # | ||
1856 | 4 | # OpenERP, Open Source Management Solution | ||
1857 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
1858 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
1859 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
1860 | 8 | |||
1861 | 9 | # This program is free software: you can redistribute it and/or modify | ||
1862 | 10 | # it under the terms of the GNU Affero General Public License as | ||
1863 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
1864 | 12 | # License, or (at your option) any later version. | ||
1865 | 13 | # | ||
1866 | 14 | # This program is distributed in the hope that it will be useful, | ||
1867 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1868 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1869 | 17 | # GNU Affero General Public License for more details. | ||
1870 | 18 | # | ||
1871 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
1872 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1873 | 21 | # | ||
1874 | 22 | ############################################################################## | ||
1875 | 23 | from openerp.osv import fields, orm | ||
1876 | 24 | from openerp.addons.base_intercompany.backend import icops | ||
1877 | 25 | from openerp.addons.base_intercompany.unit.export_synchronizer import ( | ||
1878 | 26 | ICOPSExporter) | ||
1879 | 27 | from openerp.addons.base_intercompany.unit.mapper import ICOPSExportMapper | ||
1880 | 28 | from openerp.addons.connector.unit.mapper import mapping | ||
1881 | 29 | from openerp.addons.base_intercompany.unit.backend_adapter import ( | ||
1882 | 30 | ICOPSAdapter) | ||
1883 | 31 | from openerp.addons.connector.exception import MappingError | ||
1884 | 32 | |||
1885 | 33 | |||
1886 | 34 | class purchase_order(orm.Model): | ||
1887 | 35 | _name = 'purchase.order' | ||
1888 | 36 | _inherit = ['purchase.order', 'icops.model'] | ||
1889 | 37 | |||
1890 | 38 | _columns = { | ||
1891 | 39 | 'openerp_id': fields.many2one('purchase.order', | ||
1892 | 40 | string='Sale Order', | ||
1893 | 41 | required=True, | ||
1894 | 42 | ondelete='cascade'), | ||
1895 | 43 | 'icops_bind_ids': fields.one2many( | ||
1896 | 44 | 'icops.purchase.order', 'openerp_id', | ||
1897 | 45 | string="ICOPS Bindings"), | ||
1898 | 46 | } | ||
1899 | 47 | |||
1900 | 48 | def copy_data(self, cr, uid, id, default=None, context=None): | ||
1901 | 49 | if default is None: | ||
1902 | 50 | default = {} | ||
1903 | 51 | default['icops_bind_ids'] = False | ||
1904 | 52 | return super(purchase_order, self).copy_data(cr, uid, id, | ||
1905 | 53 | default=default, | ||
1906 | 54 | context=context) | ||
1907 | 55 | |||
1908 | 56 | def create(self, cr, uid, data, context=None): | ||
1909 | 57 | data['icops_bind_ids'] = self.pool.get( | ||
1910 | 58 | 'icops.backend').prepare_binding(cr, uid, data, context) | ||
1911 | 59 | return super(purchase_order, self).create(cr, uid, data, context) | ||
1912 | 60 | |||
1913 | 61 | def write(self, cr, uid, ids, data, context=None): | ||
1914 | 62 | self._check_icops(cr, uid, ids, context=context) | ||
1915 | 63 | return super(purchase_order, self).write(cr, uid, ids, data, context) | ||
1916 | 64 | |||
1917 | 65 | def unlink(self, cr, uid, ids, context=None): | ||
1918 | 66 | self._check_icops(cr, uid, ids, context=context) | ||
1919 | 67 | return super(purchase_order, self).unlink(cr, uid, ids, context) | ||
1920 | 68 | |||
1921 | 69 | |||
1922 | 70 | class icops_purchase_order(orm.Model): | ||
1923 | 71 | _name = 'icops.purchase.order' | ||
1924 | 72 | _inherit = 'icops.binding' | ||
1925 | 73 | _inherits = {'purchase.order': 'openerp_id'} | ||
1926 | 74 | _description = 'ICOPS Purchase Order' | ||
1927 | 75 | |||
1928 | 76 | _columns = { | ||
1929 | 77 | 'openerp_id': fields.many2one('purchase.order', | ||
1930 | 78 | string='Product', | ||
1931 | 79 | required=True, | ||
1932 | 80 | ondelete='cascade'), | ||
1933 | 81 | 'backend_id': fields.many2one('icops.backend', | ||
1934 | 82 | string='ICOPS Backend'), | ||
1935 | 83 | 'icops_order_line_ids': fields.one2many('icops.purchase.order.line', | ||
1936 | 84 | 'icops_order_id', | ||
1937 | 85 | 'ICOPS Order Lines'), | ||
1938 | 86 | } | ||
1939 | 87 | |||
1940 | 88 | |||
1941 | 89 | class purchase_order_line(orm.Model): | ||
1942 | 90 | _inherit = 'purchase.order.line' | ||
1943 | 91 | _columns = { | ||
1944 | 92 | 'icops_bind_ids': fields.one2many( | ||
1945 | 93 | 'icops.purchase.order.line', 'openerp_id', | ||
1946 | 94 | string="ICOPS Bindings"), | ||
1947 | 95 | } | ||
1948 | 96 | |||
1949 | 97 | def copy_data(self, cr, uid, id, default=None, context=None): | ||
1950 | 98 | if default is None: | ||
1951 | 99 | default = {} | ||
1952 | 100 | default['icops_bind_ids'] = False | ||
1953 | 101 | return super(purchase_order_line, self).copy_data(cr, uid, id, | ||
1954 | 102 | default=default, | ||
1955 | 103 | context=context) | ||
1956 | 104 | |||
1957 | 105 | |||
1958 | 106 | class icops_purchase_order_line(orm.Model): | ||
1959 | 107 | _name = 'icops.purchase.order.line' | ||
1960 | 108 | _inherit = 'icops.binding' | ||
1961 | 109 | _description = 'ICOPS Sale Order Line' | ||
1962 | 110 | _inherits = {'purchase.order.line': 'openerp_id'} | ||
1963 | 111 | |||
1964 | 112 | def _get_lines_from_order(self, cr, uid, ids, context=None): | ||
1965 | 113 | line_obj = self.pool.get('icops.purchase.order.line') | ||
1966 | 114 | return line_obj.search(cr, uid, | ||
1967 | 115 | [('icops_order_id', 'in', ids)], | ||
1968 | 116 | context=context) | ||
1969 | 117 | _columns = { | ||
1970 | 118 | 'icops_order_id': fields.many2one('icops.purchase.order', | ||
1971 | 119 | 'ICOPS Sale Order', | ||
1972 | 120 | required=True, | ||
1973 | 121 | ondelete='cascade', | ||
1974 | 122 | select=True), | ||
1975 | 123 | 'openerp_id': fields.many2one('purchase.order.line', | ||
1976 | 124 | string='Sale Order Line', | ||
1977 | 125 | required=True, | ||
1978 | 126 | ondelete='cascade'), | ||
1979 | 127 | 'backend_id': fields.related( | ||
1980 | 128 | 'icops_order_id', 'backend_id', | ||
1981 | 129 | type='many2one', | ||
1982 | 130 | relation='icops.backend', | ||
1983 | 131 | string='ICOPS Backend', | ||
1984 | 132 | store={'icops.purchase.order.line': | ||
1985 | 133 | (lambda self, cr, uid, ids, c=None: ids, | ||
1986 | 134 | ['icops_order_id'], | ||
1987 | 135 | 10), | ||
1988 | 136 | 'icops.purchase.order': | ||
1989 | 137 | (_get_lines_from_order, ['backend_id'], 20), | ||
1990 | 138 | }, | ||
1991 | 139 | readonly=True) | ||
1992 | 140 | } | ||
1993 | 141 | |||
1994 | 142 | def create(self, cr, uid, vals, context=None): | ||
1995 | 143 | icops_order_id = vals['icops_order_id'] | ||
1996 | 144 | info = self.pool['icops.purchase.order'].read(cr, uid, | ||
1997 | 145 | [icops_order_id], | ||
1998 | 146 | ['openerp_id'], | ||
1999 | 147 | context=context) | ||
2000 | 148 | order_id = info[0]['openerp_id'] | ||
2001 | 149 | vals['order_id'] = order_id[0] | ||
2002 | 150 | return super(icops_purchase_order_line, self).create(cr, uid, vals, | ||
2003 | 151 | context=context) | ||
2004 | 152 | |||
2005 | 153 | |||
2006 | 154 | @icops | ||
2007 | 155 | class PurchaseOrderAdapter(ICOPSAdapter): | ||
2008 | 156 | _model_name = 'icops.purchase.order' | ||
2009 | 157 | |||
2010 | 158 | def _get_pool(self): | ||
2011 | 159 | sess = self.session | ||
2012 | 160 | return sess.pool.get('sale.order') | ||
2013 | 161 | |||
2014 | 162 | def confirm(self, id): | ||
2015 | 163 | sess = self.session | ||
2016 | 164 | pool = self._get_pool() | ||
2017 | 165 | context = {'icops': True} | ||
2018 | 166 | pool.write( | ||
2019 | 167 | sess.cr, self._backend_to.icops_uid.id, [id], | ||
2020 | 168 | {'temp_unlock': True}, context=context) | ||
2021 | 169 | pool.action_wait( | ||
2022 | 170 | sess.cr, self._backend_to.icops_uid.id, [id]) | ||
2023 | 171 | pool.write( | ||
2024 | 172 | sess.cr, self._backend_to.icops_uid.id, [id], | ||
2025 | 173 | {'temp_unlock': False}, context=context) | ||
2026 | 174 | |||
2027 | 175 | def cancel(self, id): | ||
2028 | 176 | sess = self.session | ||
2029 | 177 | pool = self._get_pool() | ||
2030 | 178 | context = {'icops': True} | ||
2031 | 179 | pool.write( | ||
2032 | 180 | sess.cr, self._backend_to.icops_uid.id, [id], | ||
2033 | 181 | {'temp_unlock': True}, context=context) | ||
2034 | 182 | pool.action_cancel(sess.cr, self._backend_to.icops_uid.id, [id]) | ||
2035 | 183 | pool.write( | ||
2036 | 184 | sess.cr, self._backend_to.icops_uid.id, [id], | ||
2037 | 185 | {'temp_unlock': False}, context=context) | ||
2038 | 186 | |||
2039 | 187 | |||
2040 | 188 | @icops | ||
2041 | 189 | class PurchaseOrderExport(ICOPSExporter): | ||
2042 | 190 | _model_name = ['icops.purchase.order'] | ||
2043 | 191 | _concepts = ['po2so'] | ||
2044 | 192 | |||
2045 | 193 | def _custom_routing(self, id, record, fields=None): | ||
2046 | 194 | if 'state' in fields: | ||
2047 | 195 | state = record.pop('state') | ||
2048 | 196 | if state == 'cancel': | ||
2049 | 197 | self._cancel(id) | ||
2050 | 198 | elif state == 'progress': | ||
2051 | 199 | self._confirm(id) | ||
2052 | 200 | elif fields: | ||
2053 | 201 | self._write(id, record) | ||
2054 | 202 | |||
2055 | 203 | |||
2056 | 204 | @icops | ||
2057 | 205 | class PurchaseOrderExportMapper(ICOPSExportMapper): | ||
2058 | 206 | _model_name = 'icops.purchase.order' | ||
2059 | 207 | |||
2060 | 208 | children = [ | ||
2061 | 209 | ('order_line', 'order_line', 'icops.purchase.order.line') | ||
2062 | 210 | ] | ||
2063 | 211 | |||
2064 | 212 | @mapping | ||
2065 | 213 | def origin(self, record): | ||
2066 | 214 | return {'origin': 'ICOPS: %s' % record.name} | ||
2067 | 215 | |||
2068 | 216 | @mapping | ||
2069 | 217 | def state(self, record): | ||
2070 | 218 | state = record.state | ||
2071 | 219 | if record.state == 'approved': | ||
2072 | 220 | state = 'progress' | ||
2073 | 221 | return {'state': state} | ||
2074 | 222 | |||
2075 | 223 | @mapping | ||
2076 | 224 | def address(self, record): | ||
2077 | 225 | sess = self.session | ||
2078 | 226 | partner = record.company_id.partner_id | ||
2079 | 227 | partner_pool = sess.pool.get('res.partner') | ||
2080 | 228 | addr = partner_pool.address_get(sess.cr, sess.uid, [partner.id], | ||
2081 | 229 | ['delivery', 'invoice', 'contact']) | ||
2082 | 230 | return { | ||
2083 | 231 | 'partner_invoice_id': addr['invoice'], | ||
2084 | 232 | 'partner_shipping_id': addr['delivery'] | ||
2085 | 233 | } | ||
2086 | 234 | |||
2087 | 235 | @mapping | ||
2088 | 236 | def icops(self, record): | ||
2089 | 237 | if not self._backend_to: | ||
2090 | 238 | raise MappingError("Could not find an ICOPS backend") | ||
2091 | 239 | sess = self.session | ||
2092 | 240 | backend = self._backend_to | ||
2093 | 241 | ic_uid = backend.icops_uid.id | ||
2094 | 242 | company = backend.company_id | ||
2095 | 243 | partner_pool = sess.pool.get('res.partner') | ||
2096 | 244 | partner_id = record.company_id.partner_id.id | ||
2097 | 245 | partner = partner_pool.browse(sess.cr, ic_uid, partner_id) | ||
2098 | 246 | pricelist = (partner.property_product_pricelist.id | ||
2099 | 247 | if partner.property_product_pricelist | ||
2100 | 248 | else False) | ||
2101 | 249 | fiscal_position = partner.property_account_position | ||
2102 | 250 | payment_term = partner.property_payment_term | ||
2103 | 251 | shop = self._backend_to.icops_shop_id | ||
2104 | 252 | if company.partner_id.id != record.partner_id.id: | ||
2105 | 253 | raise MappingError("Wrong partner") | ||
2106 | 254 | return { | ||
2107 | 255 | 'company_id': company.id, | ||
2108 | 256 | 'partner_id': partner.id, | ||
2109 | 257 | 'pricelist_id': pricelist, | ||
2110 | 258 | 'fiscal_position': fiscal_position.id, | ||
2111 | 259 | 'payment_term': payment_term.id, | ||
2112 | 260 | 'user_id': ic_uid, | ||
2113 | 261 | 'shop_id': shop.id | ||
2114 | 262 | } | ||
2115 | 263 | |||
2116 | 264 | |||
2117 | 265 | @icops | ||
2118 | 266 | class PurchaseOrderLineExportMapper(ICOPSExportMapper): | ||
2119 | 267 | _model_name = 'icops.purchase.order.line' | ||
2120 | 268 | |||
2121 | 269 | @mapping | ||
2122 | 270 | def product(self, record): | ||
2123 | 271 | return { | ||
2124 | 272 | 'name': record.name, | ||
2125 | 273 | 'product_id': record.product_id.id, | ||
2126 | 274 | 'product_uom': record.product_uom.id, | ||
2127 | 275 | 'product_uom_qty': record.product_qty | ||
2128 | 276 | } | ||
2129 | 277 | |||
2130 | 278 | @mapping | ||
2131 | 279 | def price(self, record): | ||
2132 | 280 | if not record.product_id: | ||
2133 | 281 | return {'price_unit': 0} | ||
2134 | 282 | sess = self.session | ||
2135 | 283 | backend = self._backend_to | ||
2136 | 284 | ic_uid = backend.icops_uid.id | ||
2137 | 285 | partner_pool = sess.pool.get('res.partner') | ||
2138 | 286 | partner_id = record.order_id.company_id.partner_id.id | ||
2139 | 287 | partner = partner_pool.browse(sess.cr, ic_uid, partner_id) | ||
2140 | 288 | pricelist_id = (partner.property_product_pricelist.id | ||
2141 | 289 | if partner.property_product_pricelist | ||
2142 | 290 | else False) | ||
2143 | 291 | pricelist_pool = sess.pool.get('product.pricelist') | ||
2144 | 292 | price_unit = pricelist_pool.price_get( | ||
2145 | 293 | sess.cr, ic_uid, [pricelist_id], | ||
2146 | 294 | record.product_id.id, record.product_qty) | ||
2147 | 295 | price = price_unit[int(pricelist_id)] | ||
2148 | 296 | return {'price_unit': price} | ||
2149 | 0 | 297 | ||
2150 | === added file 'base_intercompany_sale/purchase_view.xml' | |||
2151 | --- base_intercompany_sale/purchase_view.xml 1970-01-01 00:00:00 +0000 | |||
2152 | +++ base_intercompany_sale/purchase_view.xml 2014-02-23 01:10:59 +0000 | |||
2153 | @@ -0,0 +1,26 @@ | |||
2154 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2155 | 2 | <openerp> | ||
2156 | 3 | <data> | ||
2157 | 4 | <record id="purchase_order_form" model="ir.ui.view"> | ||
2158 | 5 | <field name="name">purchase.order.form</field> | ||
2159 | 6 | <field name="model">purchase.order</field> | ||
2160 | 7 | <field name="inherit_id" ref="purchase.purchase_order_form" /> | ||
2161 | 8 | <field name="arch" type="xml"> | ||
2162 | 9 | <xpath expr="//header/button[last()]" position="after"> | ||
2163 | 10 | <button name="action_unlock" string="Unlock" type="object" attrs="{'invisible':[('locked', '=', False)]}" class="oe_highlight" /> | ||
2164 | 11 | </xpath> | ||
2165 | 12 | <xpath expr="//page[last()]" position="after"> | ||
2166 | 13 | <page string="ICOPS"> | ||
2167 | 14 | <field name="locked" invisible="1" /> | ||
2168 | 15 | <field name="icops_bind_ids"> | ||
2169 | 16 | <tree string="ICOPS Backend" editable="bottom"> | ||
2170 | 17 | <field name="backend_id" /> | ||
2171 | 18 | <field name="icops_ids" /> | ||
2172 | 19 | </tree> | ||
2173 | 20 | </field> | ||
2174 | 21 | </page> | ||
2175 | 22 | </xpath> | ||
2176 | 23 | </field> | ||
2177 | 24 | </record> | ||
2178 | 25 | </data> | ||
2179 | 26 | </openerp> | ||
2180 | 0 | \ No newline at end of file | 27 | \ No newline at end of file |
2181 | 1 | 28 | ||
2182 | === added file 'base_intercompany_sale/sale.py' | |||
2183 | --- base_intercompany_sale/sale.py 1970-01-01 00:00:00 +0000 | |||
2184 | +++ base_intercompany_sale/sale.py 2014-02-23 01:10:59 +0000 | |||
2185 | @@ -0,0 +1,390 @@ | |||
2186 | 1 | # -*- coding: utf-8 -*- | ||
2187 | 2 | ############################################################################## | ||
2188 | 3 | # | ||
2189 | 4 | # OpenERP, Open Source Management Solution | ||
2190 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
2191 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
2192 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
2193 | 8 | |||
2194 | 9 | # This program is free software: you can redistribute it and/or modify | ||
2195 | 10 | # it under the terms of the GNU Affero General Public License as | ||
2196 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
2197 | 12 | # License, or (at your option) any later version. | ||
2198 | 13 | # | ||
2199 | 14 | # This program is distributed in the hope that it will be useful, | ||
2200 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2201 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2202 | 17 | # GNU Affero General Public License for more details. | ||
2203 | 18 | # | ||
2204 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
2205 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2206 | 21 | # | ||
2207 | 22 | ############################################################################## | ||
2208 | 23 | from openerp.osv import fields, orm | ||
2209 | 24 | from openerp.addons.base_intercompany.backend import icops | ||
2210 | 25 | from openerp.addons.base_intercompany.unit.export_synchronizer import ( | ||
2211 | 26 | ICOPSExporter) | ||
2212 | 27 | from openerp.addons.base_intercompany.unit.mapper import ICOPSExportMapper | ||
2213 | 28 | from openerp.addons.connector.unit.mapper import mapping | ||
2214 | 29 | from openerp.addons.connector.exception import MappingError | ||
2215 | 30 | from openerp.addons.base_intercompany.unit.backend_adapter import ICOPSAdapter | ||
2216 | 31 | |||
2217 | 32 | |||
2218 | 33 | class sale_order(orm.Model): | ||
2219 | 34 | _name = 'sale.order' | ||
2220 | 35 | _inherit = ['sale.order', 'icops.model'] | ||
2221 | 36 | |||
2222 | 37 | _columns = { | ||
2223 | 38 | 'openerp_id': fields.many2one('sale.order', | ||
2224 | 39 | string='Sale Order', | ||
2225 | 40 | required=True, | ||
2226 | 41 | ondelete='cascade'), | ||
2227 | 42 | 'icops_bind_ids': fields.one2many( | ||
2228 | 43 | 'icops.sale.order', 'openerp_id', | ||
2229 | 44 | string="ICOPS Bindings"), | ||
2230 | 45 | } | ||
2231 | 46 | |||
2232 | 47 | def copy_data(self, cr, uid, id, default=None, context=None): | ||
2233 | 48 | if default is None: | ||
2234 | 49 | default = {} | ||
2235 | 50 | default['icops_bind_ids'] = False | ||
2236 | 51 | return super(sale_order, self).copy_data(cr, uid, id, | ||
2237 | 52 | default=default, | ||
2238 | 53 | context=context) | ||
2239 | 54 | |||
2240 | 55 | def create(self, cr, uid, data, context=None): | ||
2241 | 56 | data['icops_bind_ids'] = self.pool.get( | ||
2242 | 57 | 'icops.backend').prepare_binding(cr, uid, data, context) | ||
2243 | 58 | return super(sale_order, self).create(cr, uid, data, context) | ||
2244 | 59 | |||
2245 | 60 | def write(self, cr, uid, ids, data, context=None): | ||
2246 | 61 | self._check_icops(cr, uid, ids, context=context) | ||
2247 | 62 | return super(sale_order, self).write(cr, uid, ids, data, context) | ||
2248 | 63 | |||
2249 | 64 | def unlink(self, cr, uid, ids, context=None): | ||
2250 | 65 | self._check_icops(cr, uid, ids, context=context) | ||
2251 | 66 | return super(sale_order, self).unlink(cr, uid, ids, context) | ||
2252 | 67 | |||
2253 | 68 | |||
2254 | 69 | class icops_sale_order(orm.Model): | ||
2255 | 70 | _name = 'icops.sale.order' | ||
2256 | 71 | _inherit = 'icops.binding' | ||
2257 | 72 | _inherits = {'sale.order': 'openerp_id'} | ||
2258 | 73 | _description = 'ICOPS Sale Order' | ||
2259 | 74 | |||
2260 | 75 | _columns = { | ||
2261 | 76 | 'openerp_id': fields.many2one('sale.order', | ||
2262 | 77 | string='SaleOrder', | ||
2263 | 78 | required=True, | ||
2264 | 79 | ondelete='cascade'), | ||
2265 | 80 | 'backend_id': fields.many2one('icops.backend', | ||
2266 | 81 | string='ICOPS Backend'), | ||
2267 | 82 | 'icops_order_line_ids': fields.one2many('icops.sale.order.line', | ||
2268 | 83 | 'icops_order_id', | ||
2269 | 84 | 'ICOPS Order Lines'), | ||
2270 | 85 | |||
2271 | 86 | } | ||
2272 | 87 | |||
2273 | 88 | |||
2274 | 89 | class sale_order_line(orm.Model): | ||
2275 | 90 | _inherit = 'sale.order.line' | ||
2276 | 91 | _columns = { | ||
2277 | 92 | 'icops_bind_ids': fields.one2many( | ||
2278 | 93 | 'icops.sale.order.line', 'openerp_id', | ||
2279 | 94 | string="ICOPS Bindings"), | ||
2280 | 95 | } | ||
2281 | 96 | |||
2282 | 97 | def copy_data(self, cr, uid, id, default=None, context=None): | ||
2283 | 98 | if default is None: | ||
2284 | 99 | default = {} | ||
2285 | 100 | default['icops_bind_ids'] = False | ||
2286 | 101 | return super(sale_order_line, self).copy_data(cr, uid, id, | ||
2287 | 102 | default=default, | ||
2288 | 103 | context=context) | ||
2289 | 104 | |||
2290 | 105 | |||
2291 | 106 | class icops_sale_order_line(orm.Model): | ||
2292 | 107 | _name = 'icops.sale.order.line' | ||
2293 | 108 | _inherit = 'icops.binding' | ||
2294 | 109 | _description = 'ICOPS Sale Order Line' | ||
2295 | 110 | _inherits = {'sale.order.line': 'openerp_id'} | ||
2296 | 111 | |||
2297 | 112 | def _get_lines_from_order(self, cr, uid, ids, context=None): | ||
2298 | 113 | line_obj = self.pool.get('icops.sale.order.line') | ||
2299 | 114 | return line_obj.search(cr, uid, | ||
2300 | 115 | [('icops_order_id', 'in', ids)], | ||
2301 | 116 | context=context) | ||
2302 | 117 | _columns = { | ||
2303 | 118 | 'icops_order_id': fields.many2one('icops.sale.order', | ||
2304 | 119 | 'ICOPS Sale Order', | ||
2305 | 120 | required=True, | ||
2306 | 121 | ondelete='cascade', | ||
2307 | 122 | select=True), | ||
2308 | 123 | 'openerp_id': fields.many2one('sale.order.line', | ||
2309 | 124 | string='Sale Order Line', | ||
2310 | 125 | required=True, | ||
2311 | 126 | ondelete='cascade'), | ||
2312 | 127 | 'backend_id': fields.related( | ||
2313 | 128 | 'icops_order_id', 'backend_id', | ||
2314 | 129 | type='many2one', | ||
2315 | 130 | relation='icops.backend', | ||
2316 | 131 | string='ICOPS Backend', | ||
2317 | 132 | store={'icops.sale.order.line': | ||
2318 | 133 | (lambda self, cr, uid, ids, c=None: ids, | ||
2319 | 134 | ['icops_order_id'], | ||
2320 | 135 | 10), | ||
2321 | 136 | 'icops.sale.order': | ||
2322 | 137 | (_get_lines_from_order, ['backend_id'], 20), | ||
2323 | 138 | }, | ||
2324 | 139 | readonly=True) | ||
2325 | 140 | } | ||
2326 | 141 | |||
2327 | 142 | def create(self, cr, uid, vals, context=None): | ||
2328 | 143 | icops_order_id = vals['icops_order_id'] | ||
2329 | 144 | info = self.pool['icops.sale.order'].read(cr, uid, | ||
2330 | 145 | [icops_order_id], | ||
2331 | 146 | ['openerp_id'], | ||
2332 | 147 | context=context) | ||
2333 | 148 | order_id = info[0]['openerp_id'] | ||
2334 | 149 | vals['order_id'] = order_id[0] | ||
2335 | 150 | return super(icops_sale_order_line, self).create(cr, uid, vals, | ||
2336 | 151 | context=context) | ||
2337 | 152 | |||
2338 | 153 | |||
2339 | 154 | @icops | ||
2340 | 155 | class SaleOrderAdapter(ICOPSAdapter): | ||
2341 | 156 | _model_name = 'icops.sale.order' | ||
2342 | 157 | |||
2343 | 158 | def _get_pool(self): | ||
2344 | 159 | sess = self.session | ||
2345 | 160 | name = ('purchase.order' | ||
2346 | 161 | if self._icops.concept == 'so2po' else 'sale.order') | ||
2347 | 162 | return sess.pool.get(name) | ||
2348 | 163 | |||
2349 | 164 | def confirm(self, id): | ||
2350 | 165 | sess = self.session | ||
2351 | 166 | pool = self._get_pool() | ||
2352 | 167 | context = {'icops': True} | ||
2353 | 168 | pool.write( | ||
2354 | 169 | sess.cr, self._backend_to.icops_uid.id, [id], | ||
2355 | 170 | {'temp_unlock': True}, context) | ||
2356 | 171 | if hasattr(pool, 'wkf_confirm_order'): | ||
2357 | 172 | pool.wkf_confirm_order( | ||
2358 | 173 | sess.cr, self._backend_to.icops_uid.id, [id]) | ||
2359 | 174 | else: | ||
2360 | 175 | pool.action_wait( | ||
2361 | 176 | sess.cr, self._backend_to.icops_uid.id, [id]) | ||
2362 | 177 | pool.write( | ||
2363 | 178 | sess.cr, self._backend_to.icops_uid.id, [id], | ||
2364 | 179 | {'temp_unlock': False}, context) | ||
2365 | 180 | |||
2366 | 181 | def cancel(self, id): | ||
2367 | 182 | sess = self.session | ||
2368 | 183 | pool = self._get_pool() | ||
2369 | 184 | context = {'icops': True} | ||
2370 | 185 | pool.write( | ||
2371 | 186 | sess.cr, self._backend_to.icops_uid.id, [id], | ||
2372 | 187 | {'temp_unlock': True}, context) | ||
2373 | 188 | pool.action_cancel(sess.cr, self._backend_to.icops_uid.id, [id]) | ||
2374 | 189 | pool.write( | ||
2375 | 190 | sess.cr, self._backend_to.icops_uid.id, [id], | ||
2376 | 191 | {'temp_unlock': False}, context) | ||
2377 | 192 | |||
2378 | 193 | |||
2379 | 194 | @icops | ||
2380 | 195 | class SaleOrderExport(ICOPSExporter): | ||
2381 | 196 | _model_name = ['icops.sale.order'] | ||
2382 | 197 | _concepts = ['so2po', 'so2so'] | ||
2383 | 198 | |||
2384 | 199 | def _custom_routing(self, id, record, fields=None): | ||
2385 | 200 | if 'state' in fields: | ||
2386 | 201 | state = record.pop('state') | ||
2387 | 202 | if state == 'cancel': | ||
2388 | 203 | self._cancel(id) | ||
2389 | 204 | elif state in ('approved', 'progress', 'manual'): | ||
2390 | 205 | self._confirm(id) | ||
2391 | 206 | elif fields: | ||
2392 | 207 | self._write(id, record) | ||
2393 | 208 | |||
2394 | 209 | |||
2395 | 210 | @icops | ||
2396 | 211 | class SaleOrderExportMapper(ICOPSExportMapper): | ||
2397 | 212 | _model_name = 'icops.sale.order' | ||
2398 | 213 | |||
2399 | 214 | children = [ | ||
2400 | 215 | ('order_line', 'order_line', 'icops.sale.order.line') | ||
2401 | 216 | ] | ||
2402 | 217 | |||
2403 | 218 | def _partner(self, record, is_po=False): | ||
2404 | 219 | sess = self.session | ||
2405 | 220 | backend = self._backend_to | ||
2406 | 221 | ic_uid = backend.icops_uid.id | ||
2407 | 222 | partner_pool = sess.pool.get('res.partner') | ||
2408 | 223 | partner_id = record.company_id.partner_id.id | ||
2409 | 224 | partner = partner_pool.browse(sess.cr, ic_uid, partner_id) | ||
2410 | 225 | pricelist_id = None | ||
2411 | 226 | payment_term_id = None | ||
2412 | 227 | if is_po: | ||
2413 | 228 | pricelist_id = (partner.property_product_pricelist_purchase.id | ||
2414 | 229 | if partner.property_product_pricelist_purchase | ||
2415 | 230 | else False) | ||
2416 | 231 | payment_term_id = (partner.property_supplier_payment_term.id | ||
2417 | 232 | if partner.property_supplier_payment_term | ||
2418 | 233 | else False) | ||
2419 | 234 | else: | ||
2420 | 235 | pricelist_id = (partner.property_product_pricelist.id | ||
2421 | 236 | if partner.property_product_pricelist | ||
2422 | 237 | else False) | ||
2423 | 238 | payment_term_id = (partner.property_payment_term.id | ||
2424 | 239 | if partner.property_payment_term | ||
2425 | 240 | else False) | ||
2426 | 241 | fiscal_position_id = (partner.property_account_position.id | ||
2427 | 242 | if partner.property_account_position | ||
2428 | 243 | else False) | ||
2429 | 244 | return {'partner_id': partner.id, | ||
2430 | 245 | 'pricelist_id': pricelist_id, | ||
2431 | 246 | 'payment_term_id': payment_term_id, | ||
2432 | 247 | 'fiscal_position': fiscal_position_id} | ||
2433 | 248 | |||
2434 | 249 | @mapping | ||
2435 | 250 | def origin(self, record): | ||
2436 | 251 | return {'origin': 'ICOPS: %s' % record.name} | ||
2437 | 252 | |||
2438 | 253 | @mapping | ||
2439 | 254 | def map_all(self, record): | ||
2440 | 255 | assert self._icops | ||
2441 | 256 | return self._get_mapping(self._icops.concept, record) | ||
2442 | 257 | |||
2443 | 258 | def so2so_icops(self, record): | ||
2444 | 259 | if not self._backend_to: | ||
2445 | 260 | raise MappingError("Could not find an ICOPS backend") | ||
2446 | 261 | backend = self._backend_to | ||
2447 | 262 | icops_uid = backend.icops_uid.id | ||
2448 | 263 | company = backend.company_id | ||
2449 | 264 | partner = company.partner_id | ||
2450 | 265 | pricelist = partner.property_product_pricelist | ||
2451 | 266 | fiscal_position = partner.property_account_position | ||
2452 | 267 | payment_term = partner.property_payment_term | ||
2453 | 268 | shop = self._backend_to.icops_shop_id | ||
2454 | 269 | |||
2455 | 270 | return { | ||
2456 | 271 | 'company_id': company.id, | ||
2457 | 272 | 'partner_id': partner.id, | ||
2458 | 273 | 'pricelist_id': pricelist.id, | ||
2459 | 274 | 'fiscal_position': fiscal_position.id, | ||
2460 | 275 | 'payment_term': payment_term.id, | ||
2461 | 276 | 'user_id': icops_uid, | ||
2462 | 277 | 'shop_id': shop.id | ||
2463 | 278 | } | ||
2464 | 279 | |||
2465 | 280 | def so2so_partner(self, record): | ||
2466 | 281 | return self._partner(record) | ||
2467 | 282 | |||
2468 | 283 | def so2so_address(self, record): | ||
2469 | 284 | sess = self.session | ||
2470 | 285 | partner = record.company_id.partner_id | ||
2471 | 286 | partner_pool = sess.pool.get('res.partner') | ||
2472 | 287 | addr = partner_pool.address_get(sess.cr, sess.uid, [partner.id], | ||
2473 | 288 | ['delivery', 'invoice', 'contact']) | ||
2474 | 289 | return { | ||
2475 | 290 | 'partner_invoice_id': addr['invoice'], | ||
2476 | 291 | 'partner_shipping_id': addr['delivery'] | ||
2477 | 292 | } | ||
2478 | 293 | |||
2479 | 294 | def so2so_policy(self, record): | ||
2480 | 295 | return {'order_policy': record.order_policy} | ||
2481 | 296 | |||
2482 | 297 | def so2so_state(self, record): | ||
2483 | 298 | return {'state': record.state} | ||
2484 | 299 | |||
2485 | 300 | def so2po_partner(self, record): | ||
2486 | 301 | return self._partner(record, True) | ||
2487 | 302 | |||
2488 | 303 | def so2po_icops(self, record): | ||
2489 | 304 | if not self._backend_to: | ||
2490 | 305 | raise MappingError("Could not find an ICOPS backend") | ||
2491 | 306 | backend = self._backend_to | ||
2492 | 307 | company = backend.company_id | ||
2493 | 308 | shop = backend.icops_shop_id | ||
2494 | 309 | warehouse = shop.warehouse_id | ||
2495 | 310 | location = warehouse.lot_stock_id | ||
2496 | 311 | |||
2497 | 312 | if company.partner_id.id != record.partner_id.id: | ||
2498 | 313 | raise MappingError("Wrong partner") | ||
2499 | 314 | return { | ||
2500 | 315 | 'company_id': company.id, | ||
2501 | 316 | 'location_id': location.id | ||
2502 | 317 | } | ||
2503 | 318 | |||
2504 | 319 | def so2po_state(self, record): | ||
2505 | 320 | state = record.state | ||
2506 | 321 | if record.state in ('progress', 'manual'): | ||
2507 | 322 | state = 'approved' | ||
2508 | 323 | return {'state': state} | ||
2509 | 324 | |||
2510 | 325 | |||
2511 | 326 | @icops | ||
2512 | 327 | class SaleOrderLineExportMapper(ICOPSExportMapper): | ||
2513 | 328 | _model_name = 'icops.sale.order.line' | ||
2514 | 329 | |||
2515 | 330 | @mapping | ||
2516 | 331 | def name(self, record): | ||
2517 | 332 | return {'name': record.name} | ||
2518 | 333 | |||
2519 | 334 | def _price(self, record, is_po=False): | ||
2520 | 335 | if not record.product_id: | ||
2521 | 336 | return {'price_unit': 0} | ||
2522 | 337 | sess = self.session | ||
2523 | 338 | backend = self._backend_to | ||
2524 | 339 | ic_uid = backend.icops_uid.id | ||
2525 | 340 | partner_pool = sess.pool.get('res.partner') | ||
2526 | 341 | partner_id = record.order_id.company_id.partner_id.id | ||
2527 | 342 | partner = partner_pool.browse(sess.cr, ic_uid, partner_id) | ||
2528 | 343 | pricelist_id = None | ||
2529 | 344 | if is_po: | ||
2530 | 345 | pricelist_id = (partner.property_product_pricelist_purchase.id | ||
2531 | 346 | if partner.property_product_pricelist_purchase | ||
2532 | 347 | else False) | ||
2533 | 348 | else: | ||
2534 | 349 | pricelist_id = (partner.property_product_pricelist.id | ||
2535 | 350 | if partner.property_product_pricelist | ||
2536 | 351 | else False) | ||
2537 | 352 | pricelist_pool = sess.pool.get('product.pricelist') | ||
2538 | 353 | price_unit = pricelist_pool.price_get( | ||
2539 | 354 | sess.cr, ic_uid, [pricelist_id], | ||
2540 | 355 | record.product_id.id, record.product_uom_qty) | ||
2541 | 356 | price = price_unit[int(pricelist_id)] | ||
2542 | 357 | return {'price_unit': price} | ||
2543 | 358 | |||
2544 | 359 | @mapping | ||
2545 | 360 | def map_all(self, record): | ||
2546 | 361 | assert self._icops | ||
2547 | 362 | return self._get_mapping(self._icops.concept, record) | ||
2548 | 363 | |||
2549 | 364 | def so2so_price(self, record): | ||
2550 | 365 | return self._price(record) | ||
2551 | 366 | |||
2552 | 367 | def so2so_product(self, record): | ||
2553 | 368 | return { | ||
2554 | 369 | 'product_id': record.product_id.id, | ||
2555 | 370 | 'product_uom': record.product_uom.id, | ||
2556 | 371 | 'product_uom_qty': record.product_uom_qty | ||
2557 | 372 | } | ||
2558 | 373 | |||
2559 | 374 | def so2po_price(self, record): | ||
2560 | 375 | return self._price(record, True) | ||
2561 | 376 | |||
2562 | 377 | def so2po_product(self, record): | ||
2563 | 378 | return { | ||
2564 | 379 | 'product_id': record.product_id.id, | ||
2565 | 380 | 'product_uom': record.product_uom.id, | ||
2566 | 381 | 'product_qty': record.product_uom_qty | ||
2567 | 382 | } | ||
2568 | 383 | |||
2569 | 384 | def so2po_date_planned(self, record): | ||
2570 | 385 | sess = self.session | ||
2571 | 386 | order = record.order_id | ||
2572 | 387 | order_pool = sess.pool.get(order._name) | ||
2573 | 388 | date_planned = order_pool._get_date_planned( | ||
2574 | 389 | sess.cr, sess.uid, order, record, order.date_order) | ||
2575 | 390 | return {'date_planned': date_planned} | ||
2576 | 0 | 391 | ||
2577 | === added file 'base_intercompany_sale/sale_view.xml' | |||
2578 | --- base_intercompany_sale/sale_view.xml 1970-01-01 00:00:00 +0000 | |||
2579 | +++ base_intercompany_sale/sale_view.xml 2014-02-23 01:10:59 +0000 | |||
2580 | @@ -0,0 +1,26 @@ | |||
2581 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2582 | 2 | <openerp> | ||
2583 | 3 | <data> | ||
2584 | 4 | <record id="view_order_form" model="ir.ui.view"> | ||
2585 | 5 | <field name="name">sale.order</field> | ||
2586 | 6 | <field name="model">sale.order</field> | ||
2587 | 7 | <field name="inherit_id" ref="sale.view_order_form" /> | ||
2588 | 8 | <field name="arch" type="xml"> | ||
2589 | 9 | <xpath expr="//header/button[last()]" position="after"> | ||
2590 | 10 | <button name="action_unlock" string="Unlock" type="object" attrs="{'invisible':[('locked', '=', False)]}" class="oe_highlight" /> | ||
2591 | 11 | </xpath> | ||
2592 | 12 | <xpath expr="//page[last()]" position="after"> | ||
2593 | 13 | <page string="ICOPS"> | ||
2594 | 14 | <field name="locked" invisible="1" /> | ||
2595 | 15 | <field name="icops_bind_ids"> | ||
2596 | 16 | <tree string="ICOPS Backend" editable="bottom"> | ||
2597 | 17 | <field name="backend_id" /> | ||
2598 | 18 | <field name="icops_ids" /> | ||
2599 | 19 | </tree> | ||
2600 | 20 | </field> | ||
2601 | 21 | </page> | ||
2602 | 22 | </xpath> | ||
2603 | 23 | </field> | ||
2604 | 24 | </record> | ||
2605 | 25 | </data> | ||
2606 | 26 | </openerp> | ||
2607 | 0 | \ No newline at end of file | 27 | \ No newline at end of file |
2608 | 1 | 28 | ||
2609 | === added directory 'base_intercompany_sale/security' | |||
2610 | === added file 'base_intercompany_sale/security/ir.model.access.csv' | |||
2611 | --- base_intercompany_sale/security/ir.model.access.csv 1970-01-01 00:00:00 +0000 | |||
2612 | +++ base_intercompany_sale/security/ir.model.access.csv 2014-02-23 01:10:59 +0000 | |||
2613 | @@ -0,0 +1,21 @@ | |||
2614 | 1 | id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
2615 | 2 | access_icops_sale_order_manager,icops sale order manager,base_intercompany_sale.model_icops_sale_order,base.group_sale_manager,1,1,1,1 | ||
2616 | 3 | access_icops_sale_order_user,icops sale order user,base_intercompany_sale.model_icops_sale_order,base.group_sale_salesman,1,1,1,1 | ||
2617 | 4 | access_icops_sale_order_line_manager,icops sale order line manager,base_intercompany_sale.model_icops_sale_order_line,base.group_sale_manager,1,1,1,1 | ||
2618 | 5 | access_icops_sale_order_line_user,icops sale order line user,base_intercompany_sale.model_icops_sale_order_line,base.group_sale_salesman,1,1,1,1 | ||
2619 | 6 | access_icops_backend_manager,icops backend manager,base_intercompany.model_icops_backend,base.group_sale_manager,1,1,1,1 | ||
2620 | 7 | access_icops_backend_user,icops backend user,base_intercompany.model_icops_backend,base.group_sale_salesman,1,1,1,1 | ||
2621 | 8 | access_res_intercompany_manager,res intercompany manager,base_intercompany.model_res_intercompany,base.group_sale_manager,1,1,1,1 | ||
2622 | 9 | access_res_intercompany_user,res intercompany user,base_intercompany.model_res_intercompany,base.group_sale_salesman,1,1,1,1 | ||
2623 | 10 | access_icops_record_manager,icops record manager,base_intercompany.model_icops_record,base.group_sale_manager,1,1,1,1 | ||
2624 | 11 | access_icops_record_user,icops record user,base_intercompany.model_icops_record,base.group_sale_salesman,1,1,1,1 | ||
2625 | 12 | access_icops_purchase_order_manager,icops purchase order manager,base_intercompany_sale.model_icops_purchase_order,purchase.group_purchase_manager,1,1,1,1 | ||
2626 | 13 | access_icops_purchase_order_user,icops purchase order user,base_intercompany_sale.model_icops_purchase_order,purchase.group_purchase_user,1,1,1,1 | ||
2627 | 14 | access_icops_purchase_order_line_manager,icops purchase order line manager,base_intercompany_sale.model_icops_purchase_order_line,purchase.group_purchase_manager,1,1,1,1 | ||
2628 | 15 | access_icops_purchase_order_line_user,icops purchase order line user,base_intercompany_sale.model_icops_purchase_order_line,purchase.group_purchase_user,1,1,1,1 | ||
2629 | 16 | access_icops_backend_manager,icops backend manager,base_intercompany.model_icops_backend,purchase.group_purchase_manager,1,1,1,1 | ||
2630 | 17 | access_icops_backend_user,icops backend user,base_intercompany.model_icops_backend,purchase.group_purchase_user,1,1,1,1 | ||
2631 | 18 | access_res_intercompany_manager,res intercompany manager,base_intercompany.model_res_intercompany,purchase.group_purchase_manager,1,1,1,1 | ||
2632 | 19 | access_res_intercompany_user,res intercompany user,base_intercompany.model_res_intercompany,purchase.group_purchase_user,1,1,1,1 | ||
2633 | 20 | access_icops_record_manager,icops record manager,base_intercompany.model_icops_record,purchase.group_purchase_manager,1,1,1,1 | ||
2634 | 21 | access_icops_record_user,icops record user,base_intercompany.model_icops_record,purchase.group_purchase_user,1,1,1,1 | ||
2635 | 0 | \ No newline at end of file | 22 | \ No newline at end of file |
2636 | 1 | 23 | ||
2637 | === added directory 'base_intercompany_sale/static' | |||
2638 | === added directory 'base_intercompany_sale/static/description' | |||
2639 | === added file 'base_intercompany_sale/static/description/Intercompany_setup.png' | |||
2640 | 2 | Binary files base_intercompany_sale/static/description/Intercompany_setup.png 1970-01-01 00:00:00 +0000 and base_intercompany_sale/static/description/Intercompany_setup.png 2014-02-23 01:10:59 +0000 differ | 24 | Binary files base_intercompany_sale/static/description/Intercompany_setup.png 1970-01-01 00:00:00 +0000 and base_intercompany_sale/static/description/Intercompany_setup.png 2014-02-23 01:10:59 +0000 differ |
2641 | === added file 'base_intercompany_sale/static/description/index.html' | |||
2642 | --- base_intercompany_sale/static/description/index.html 1970-01-01 00:00:00 +0000 | |||
2643 | +++ base_intercompany_sale/static/description/index.html 2014-02-23 01:10:59 +0000 | |||
2644 | @@ -0,0 +1,26 @@ | |||
2645 | 1 | <section class="oe_container"> | ||
2646 | 2 | <div class="oe_row"> | ||
2647 | 3 | <h2 class="oe_slogan">base_intercompany_sale</h2> | ||
2648 | 4 | <h3 class="oe_slogan">Sale Inter-Company Processing (ICOPS) <br /></h3> | ||
2649 | 5 | <h4 class="oe_slogan"><a href="http://www.elico-corp.com">By Elico Corp</a></h4> | ||
2650 | 6 | <p> | ||
2651 | 7 | This module is an extension designed to manage Inter-company Process (ICOPS) and allows 2 companies to create Sale Orders and Purchase Order in each other. | ||
2652 | 8 | </p> | ||
2653 | 9 | <ul> | ||
2654 | 10 | <li>Sale Order to Purchase Order (so2po)</li> | ||
2655 | 11 | <li>Sale Order to Sale Order (so2so)</li> | ||
2656 | 12 | <li>Purchase Order to Sale Order (po2so)</li> | ||
2657 | 13 | <li>Handles the following events: Create, Update, Delete, Confirm and Cancel</li> | ||
2658 | 14 | </ul> | ||
2659 | 15 | <p> | ||
2660 | 16 | TODO: demo data to be improved.<br /> | ||
2661 | 17 | Blueprint: <a href="https://blueprints.launchpad.net/multi-company/+spec/icops">https://blueprints.launchpad.net/multi-company/+spec/icops</a><br /> | ||
2662 | 18 | </p> | ||
2663 | 19 | <div class="oe_row_img oe_centered oe_mt32"> | ||
2664 | 20 | <img class="oe_picture oe_screenshot" src="Intercompany_setup.png" /> | ||
2665 | 21 | </div> | ||
2666 | 22 | </div> | ||
2667 | 23 | <div class="oe_row oe_centeralign oe_more_space"> | ||
2668 | 24 | <a href="http://www.elico-corp.com/saas/" class="oe_button oe_big">Start your <span class="oe_emph">free</span> trial</a> | ||
2669 | 25 | </div> | ||
2670 | 26 | </section> | ||
2671 | 0 | \ No newline at end of file | 27 | \ No newline at end of file |
2672 | 1 | 28 | ||
2673 | === added directory 'base_intercompany_sale/static/src' | |||
2674 | === added directory 'base_intercompany_sale/static/src/img' | |||
2675 | === added file 'base_intercompany_sale/static/src/img/icon.png' | |||
2676 | 2 | Binary files base_intercompany_sale/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and base_intercompany_sale/static/src/img/icon.png 2014-02-23 01:10:59 +0000 differ | 29 | Binary files base_intercompany_sale/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and base_intercompany_sale/static/src/img/icon.png 2014-02-23 01:10:59 +0000 differ |
2677 | === added directory 'base_intercompany_sale/tests' | |||
2678 | === added file 'base_intercompany_sale/tests/__init__.py' | |||
2679 | --- base_intercompany_sale/tests/__init__.py 1970-01-01 00:00:00 +0000 | |||
2680 | +++ base_intercompany_sale/tests/__init__.py 2014-02-23 01:10:59 +0000 | |||
2681 | @@ -0,0 +1,30 @@ | |||
2682 | 1 | # -*- coding: utf-8 -*- | ||
2683 | 2 | ############################################################################## | ||
2684 | 3 | # | ||
2685 | 4 | # OpenERP, Open Source Management Solution | ||
2686 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
2687 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
2688 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
2689 | 8 | # | ||
2690 | 9 | # This program is free software: you can redistribute it and/or modify | ||
2691 | 10 | # it under the terms of the GNU Affero General Public License as | ||
2692 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
2693 | 12 | # License, or (at your option) any later version. | ||
2694 | 13 | # | ||
2695 | 14 | # This program is distributed in the hope that it will be useful, | ||
2696 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2697 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2698 | 17 | # GNU Affero General Public License for more details. | ||
2699 | 18 | # | ||
2700 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
2701 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2702 | 21 | # | ||
2703 | 22 | ############################################################################## | ||
2704 | 23 | import test_sale | ||
2705 | 24 | |||
2706 | 25 | fast_suite = [ | ||
2707 | 26 | ] | ||
2708 | 27 | |||
2709 | 28 | checks = [ | ||
2710 | 29 | test_sale | ||
2711 | 30 | ] | ||
2712 | 0 | 31 | ||
2713 | === added file 'base_intercompany_sale/tests/test_sale.py' | |||
2714 | --- base_intercompany_sale/tests/test_sale.py 1970-01-01 00:00:00 +0000 | |||
2715 | +++ base_intercompany_sale/tests/test_sale.py 2014-02-23 01:10:59 +0000 | |||
2716 | @@ -0,0 +1,181 @@ | |||
2717 | 1 | # -*- coding: utf-8 -*- | ||
2718 | 2 | ############################################################################## | ||
2719 | 3 | # | ||
2720 | 4 | # OpenERP, Open Source Management Solution | ||
2721 | 5 | # Copyright (c) 2010-2014 Elico Corp. All Rights Reserved. | ||
2722 | 6 | # Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com> | ||
2723 | 7 | # Eric Caudal <eric.caudal@elico-corp.com> | ||
2724 | 8 | # | ||
2725 | 9 | # This program is free software: you can redistribute it and/or modify | ||
2726 | 10 | # it under the terms of the GNU Affero General Public License as | ||
2727 | 11 | # published by the Free Software Foundation, either version 3 of the | ||
2728 | 12 | # License, or (at your option) any later version. | ||
2729 | 13 | # | ||
2730 | 14 | # This program is distributed in the hope that it will be useful, | ||
2731 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2732 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2733 | 17 | # GNU Affero General Public License for more details. | ||
2734 | 18 | # | ||
2735 | 19 | # You should have received a copy of the GNU Affero General Public License | ||
2736 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2737 | 21 | # | ||
2738 | 22 | ############################################################################## | ||
2739 | 23 | import unittest2 | ||
2740 | 24 | from datetime import datetime, timedelta | ||
2741 | 25 | import openerp | ||
2742 | 26 | import openerp.tests.common as common | ||
2743 | 27 | from openerp.osv import osv | ||
2744 | 28 | |||
2745 | 29 | DB = common.DB | ||
2746 | 30 | ADMIN_USER_ID = common.ADMIN_USER_ID | ||
2747 | 31 | |||
2748 | 32 | |||
2749 | 33 | class test_sale(object): | ||
2750 | 34 | |||
2751 | 35 | def configure(self): | ||
2752 | 36 | # get super user | ||
2753 | 37 | self.m = self.registry('ir.model.data') | ||
2754 | 38 | # get companies | ||
2755 | 39 | self.company_origin = self.m.get_object( | ||
2756 | 40 | self.cr, self.uid, 'base_intercompany', 'company_origin') | ||
2757 | 41 | |||
2758 | 42 | self.company_destination = self.m.get_object( | ||
2759 | 43 | self.cr, self.uid, 'base_intercompany', 'company_destination') | ||
2760 | 44 | |||
2761 | 45 | self.user_origin = self.m.get_object( | ||
2762 | 46 | self.cr, self.uid, 'base_intercompany', 'user_origin') | ||
2763 | 47 | |||
2764 | 48 | self.user_destination = self.m.get_object( | ||
2765 | 49 | self.cr, self.uid, 'base_intercompany', 'user_destination') | ||
2766 | 50 | |||
2767 | 51 | self.shop_origin = self.m.get_object( | ||
2768 | 52 | self.cr, self.uid, 'base_intercompany_sale', 'shop_origin') | ||
2769 | 53 | |||
2770 | 54 | self.backend_origin = self.m.get_object( | ||
2771 | 55 | self.cr, self.uid, 'base_intercompany', 'backend_origin') | ||
2772 | 56 | |||
2773 | 57 | self.backend_destination = self.m.get_object( | ||
2774 | 58 | self.cr, self.uid, 'base_intercompany', 'backend_destination') | ||
2775 | 59 | |||
2776 | 60 | def set_backend(self, on_create=True, on_write=True, | ||
2777 | 61 | on_unlink=True, on_confirm=True, on_cancel=True): | ||
2778 | 62 | assert hasattr(self, 'concept') | ||
2779 | 63 | backend_pool = self.registry('icops.backend') | ||
2780 | 64 | backend_pool.write(self.cr, ADMIN_USER_ID, self.backend_origin.id, { | ||
2781 | 65 | 'icops_ids': [(5, 0), (0, 0, { | ||
2782 | 66 | 'backend_id': self.backend_origin.id, | ||
2783 | 67 | 'backend_to': self.backend_destination.id, | ||
2784 | 68 | 'concept': self.concept, | ||
2785 | 69 | 'on_create': on_create, | ||
2786 | 70 | 'on_write': on_write, | ||
2787 | 71 | 'on_unlink': on_unlink, | ||
2788 | 72 | 'on_confirm': on_confirm, | ||
2789 | 73 | 'on_cancel': on_cancel | ||
2790 | 74 | })] | ||
2791 | 75 | }) | ||
2792 | 76 | |||
2793 | 77 | def create_object(self): | ||
2794 | 78 | pool_origin = self.registry(self.model_origin) | ||
2795 | 79 | uid = self.user_origin.id | ||
2796 | 80 | obj_id = pool_origin.create( | ||
2797 | 81 | self.cr, self.user_origin.id, self.data_obj) | ||
2798 | 82 | obj = pool_origin.browse(self.cr, uid, obj_id) | ||
2799 | 83 | bind_ids = obj.icops_bind_ids | ||
2800 | 84 | self.assertEqual(len(bind_ids), 1) | ||
2801 | 85 | bind_id = bind_ids[0] | ||
2802 | 86 | icops_ids = bind_id.icops_ids | ||
2803 | 87 | self.assertEqual(len(icops_ids), 1) | ||
2804 | 88 | icops = icops_ids[0] | ||
2805 | 89 | ic_uid = icops.backend_id.icops_uid | ||
2806 | 90 | self.assertEqual(icops.model, self.model_destination) | ||
2807 | 91 | pool_destination = self.registry(icops.model) | ||
2808 | 92 | obj_dest = pool_destination.browse( | ||
2809 | 93 | self.cr, ic_uid, icops.record_id) | ||
2810 | 94 | self.assertIsNotNone(obj_dest) | ||
2811 | 95 | return obj, obj_dest | ||
2812 | 96 | |||
2813 | 97 | def write_object(self, obj, obj_dest): | ||
2814 | 98 | pool_origin = self.registry(self.model_origin) | ||
2815 | 99 | uid = self.user_origin.id | ||
2816 | 100 | self.assertEqual(len(obj.order_line), 0) | ||
2817 | 101 | self.assertEqual(len(obj_dest.order_line), 0) | ||
2818 | 102 | pool_origin.write(self.cr, uid, obj.id, { | ||
2819 | 103 | 'order_line': [(5, 0), (0, 0, self.data_line)] | ||
2820 | 104 | }) | ||
2821 | 105 | self.assertEqual(len(obj.order_line), 2) | ||
2822 | 106 | self.assertEqual(len(obj_dest.order_line), 2) | ||
2823 | 107 | |||
2824 | 108 | |||
2825 | 109 | def test_01_creation(self): | ||
2826 | 110 | self.set_backend() | ||
2827 | 111 | self.create_object() | ||
2828 | 112 | |||
2829 | 113 | def test_02_creation_raise_exception(self): | ||
2830 | 114 | self.set_backend(on_create=False) | ||
2831 | 115 | self.assertRaises( | ||
2832 | 116 | osv.except_osv, self.create_object) | ||
2833 | 117 | |||
2834 | 118 | def test_03_creation_without_write_permission(self): | ||
2835 | 119 | self.set_backend(on_write=False) | ||
2836 | 120 | self.create_object() | ||
2837 | 121 | |||
2838 | 122 | # def test_04_write(self): | ||
2839 | 123 | # self.set_backend() | ||
2840 | 124 | # pool_origin = self.registry(self.model_origin) | ||
2841 | 125 | # obj, obj_dest = self.create_object() | ||
2842 | 126 | # self.write_object(obj, obj_dest) | ||
2843 | 127 | |||
2844 | 128 | |||
2845 | 129 | class test_sale_so2po(common.TransactionCase, test_sale): | ||
2846 | 130 | |||
2847 | 131 | def setUp(self): | ||
2848 | 132 | super(test_sale_so2po, self).setUp() | ||
2849 | 133 | self.configure() | ||
2850 | 134 | self.concept = 'so2po' | ||
2851 | 135 | self.model_origin = 'sale.order' | ||
2852 | 136 | self.model_destination = 'purchase.order' | ||
2853 | 137 | self.data_obj = { | ||
2854 | 138 | 'partner_id': self.company_destination.partner_id.id, | ||
2855 | 139 | 'partner_invoice_id': self.company_destination.partner_id.id, | ||
2856 | 140 | 'partner_shipping_id': self.company_destination.partner_id.id, | ||
2857 | 141 | 'shop_id': self.shop_origin.id, | ||
2858 | 142 | 'date_order': datetime.now().strftime('%Y-%m-%d'), | ||
2859 | 143 | 'pricelist_id': self.user_origin.property_product_pricelist.id} | ||
2860 | 144 | |||
2861 | 145 | self.data_line = { | ||
2862 | 146 | 'name': 'Test product', | ||
2863 | 147 | 'product_uom': 1, | ||
2864 | 148 | 'product_uom_qty': 1, | ||
2865 | 149 | 'price_unit': 100 | ||
2866 | 150 | } | ||
2867 | 151 | |||
2868 | 152 | |||
2869 | 153 | class test_sale_so2so(common.TransactionCase, test_sale): | ||
2870 | 154 | |||
2871 | 155 | def setUp(self): | ||
2872 | 156 | super(test_sale_so2so, self).setUp() | ||
2873 | 157 | self.configure() | ||
2874 | 158 | self.concept = 'so2so' | ||
2875 | 159 | self.model_origin = 'sale.order' | ||
2876 | 160 | self.model_destination = 'sale.order' | ||
2877 | 161 | self.data_obj = { | ||
2878 | 162 | 'partner_id': self.company_destination.partner_id.id, | ||
2879 | 163 | 'partner_invoice_id': self.company_destination.partner_id.id, | ||
2880 | 164 | 'partner_shipping_id': self.company_destination.partner_id.id, | ||
2881 | 165 | 'shop_id': self.shop_origin.id, | ||
2882 | 166 | 'date_order': datetime.now().strftime('%Y-%m-%d'), | ||
2883 | 167 | 'pricelist_id': self.user_origin.property_product_pricelist.id} | ||
2884 | 168 | |||
2885 | 169 | self.data_line = { | ||
2886 | 170 | 'name': 'Test product', | ||
2887 | 171 | 'product_uom': 1, | ||
2888 | 172 | 'product_uom_qty': 1, | ||
2889 | 173 | 'price_unit': 100 | ||
2890 | 174 | } | ||
2891 | 175 | # class test_sale_po2so(common.TransactionCase, test_sale): | ||
2892 | 176 | |||
2893 | 177 | # def setUp(self): | ||
2894 | 178 | # super(test_sale_po2so, self).setUp() | ||
2895 | 179 | # self.configure() | ||
2896 | 180 | # self.model_origin = 'purchase.order' | ||
2897 | 181 | # self.model_destination = 'sale.order' |
This looks like a great module. However it needs some work before further
review is done:
1. this module will cause a crash at server startup if it is present in the addons path (not necessarily installed) and the connector module is not available in the addons path::
CRITICAL test_70 openerp. modules. module: Couldn't load module web modules. module: No module named connector afayolle/ work/oerp/ openobject- server/ 7.0/openerp/ cli/server. py", line 97, in preload_registry pooler. get_db_ and_pool( dbname, update_ module= update_ module) afayolle/ work/oerp/ openobject- server/ 7.0/openerp/ pooler. py", line 33, in get_db_and_pool .get(db_ name, force_demo, status, update_module) afayolle/ work/oerp/ openobject- server/ 7.0/openerp/ modules/ registry. py", line 203, in get
update_ module) afayolle/ work/oerp/ openobject- server/ 7.0/openerp/ modules/ registry. py", line 233, in new
openerp. modules. load_modules( registry. db, force_demo, status, update_module) afayolle/ work/oerp/ openobject- server/ 7.0/openerp/ modules/ loading. py", line 354, in load_modules
loaded_ modules, update_module) afayolle/ work/oerp/ openobject- server/ 7.0/openerp/ modules/ loading. py", line 256, in load_marked_modules graph(cr, graph, progressdict, report=report, skip_modules= loaded_ modules, perform_ checks= perform_ checks) afayolle/ work/oerp/ openobject- server/ 7.0/openerp/ modules/ loading. py", line 159, in load_module_graph
load_openerp_ module( package. name) afayolle/ work/oerp/ openobject- server/ 7.0/openerp/ modules/ module. py", line 415, in load_openerp_module
getattr( sys.modules[ 'openerp. addons. ' + module_name], info['post_ load']) () afayolle/ work/oerp/ web/7.0/ addons/ web/http. py", line 628, in wsgi_postload
openerp. wsgi.register_ wsgi_handler( Root()) afayolle/ work/oerp/ web/7.0/ addons/ web/http. py", line 517, in __init__
self.load_ addons( ) afayolle/ work/oerp/ web/7.0/ addons/ web/http. py", line 580, in load_addons _('openerp. addons. ' + module) afayolle/ work/oerp/ openobject- server/ 7.0/openerp/ modules/ module. py", line 133, in load_module module( 'openerp. addons. ' + module_part, f, path, descr) afayolle/ work/oca/ multi-company/ multi-company- add-0001/ base_intercompa ny/__init_ _.py", line 23, in <module> afayolle/ work/oca/ multi-company/ multi-company- add-0001/ base_intercompa ny/connector. py", line 25, in <module> addons. connector. connector import Environment afayolle/ work/oerp/ openobject- server/ 7.0/openerp/ modules/ module. py", line 132, in load_module module( module_ part, ad_paths)
CRITICAL test_70 openerp.
ERROR test_70 openerp: Failed to initialize database `test_70`.
Traceback (most recent call last):
File "/home/
db, registry = openerp.
File "/home/
registry = RegistryManager
File "/home/
File "/home/
File "/home/
File "/home/
loaded, processed = load_module_
File "/home/
File "/home/
File "/home/
File "/home/
File "/home/
m = __import_
File "/home/
mod = imp.load_
File "/home/
import connector
File "/home/
from openerp.
File "/home/
f, path, descr = imp.find_
ImportError: No module named connector
2. The addon has tests (good...