Merge lp:~magentoerpconnect-core-editors/magentoerpconnect/trunk-fix-876312 into lp:~magentoerpconnect-core-editors/magentoerpconnect/oerp7.0-refactor
- trunk-fix-876312
- Merge into oerp7.0-refactor
Status: | Superseded |
---|---|
Proposed branch: | lp:~magentoerpconnect-core-editors/magentoerpconnect/trunk-fix-876312 |
Merge into: | lp:~magentoerpconnect-core-editors/magentoerpconnect/oerp7.0-refactor |
Diff against target: |
4695 lines (+3433/-115) (has conflicts) 27 files modified
magento_sku_is_code/product.py (+29/-10) magentoerpconnect/__openerp__.py (+16/-1) magentoerpconnect/board_view.xml (+30/-0) magentoerpconnect/magerp_core.py (+28/-12) magentoerpconnect/magerp_menu.xml (+3/-27) magentoerpconnect/magerp_osv.py (+129/-20) magentoerpconnect/partner.py (+252/-0) magentoerpconnect/partner_view.xml (+38/-0) magentoerpconnect/product.py (+752/-19) magentoerpconnect/product_images.py (+54/-5) magentoerpconnect/sale.py (+594/-0) magentoerpconnect/sale_view.xml (+19/-0) magentoerpconnect/settings/1.3.2.4/external.mapping.template.csv (+1/-1) magentoerpconnect/settings/1.3.2.4/external.mappinglines.template.csv (+244/-20) magentoerpconnect/settings/1.4.0.0/external.mapping.template.csv (+14/-0) magentoerpconnect/settings/1.4.0.0/external.mappinglines.template.csv (+321/-0) magentoerpconnect/settings/1.4.0.0/external.referential.type.csv (+2/-0) magentoerpconnect/settings/1.4.2.0/external.mapping.template.csv (+14/-0) magentoerpconnect/settings/1.4.2.0/external.mappinglines.template.csv (+318/-0) magentoerpconnect/settings/1.4.2.0/external.referential.type.csv (+2/-0) magentoerpconnect/settings/1.5.0.0/external.mapping.template.csv (+17/-0) magentoerpconnect/settings/1.5.0.0/external.mappinglines.template.csv.OTHER (+330/-0) magentoerpconnect/settings/update/fix_product_categories.sql (+7/-0) magentoerpconnect/settings/update/magerp.product_category_attribute_options.xml (+16/-0) magentoerpconnect/stock.py (+19/-0) magentoerpconnect_payment/sale.py (+95/-0) magentoerpconnect_product_variant/product.py (+89/-0) Text conflict in magentoerpconnect/__openerp__.py Text conflict in magentoerpconnect/magerp_core.py Text conflict in magentoerpconnect/magerp_osv.py Text conflict in magentoerpconnect/partner.py Text conflict in magentoerpconnect/partner_view.xml Text conflict in magentoerpconnect/product.py Text conflict in magentoerpconnect/product_images.py Text conflict in magentoerpconnect/sale.py Text conflict in magentoerpconnect/sale_view.xml Text conflict in magentoerpconnect/settings/1.3.2.4/external.mappinglines.template.csv Text conflict in magentoerpconnect/settings/1.5.0.0/external.mapping.template.csv Contents conflict in magentoerpconnect/settings/1.5.0.0/external.mappinglines.template.csv Text conflict in magentoerpconnect/stock.py Text conflict in magentoerpconnect_product_variant/product.py |
To merge this branch: | bzr merge lp:~magentoerpconnect-core-editors/magentoerpconnect/trunk-fix-876312 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Guewen Baconnier @ Camptocamp | Pending | ||
Review via email: mp+113748@code.launchpad.net |
This proposal has been superseded by a proposal from 2012-07-06.
Commit message
Description of the change
Work around magento bug wrt product categories. Closes https:/
Unmerged revisions
- 647. By Alexandre Fayolle @ camptocamp <email address hidden>
-
[FIX] magentoerpconnect: fix export product.category issues
* the product.category meta_title has a max length of 255 char on magento
* add mappings for Magento 1.4.0.0 and 1.4.2.0, for the product.category available_sort_by bug (lp:876312)
* duplicate the option used for default value with an empty string and fix mappings (>> 1.4)I did not simply change the value of the option as there might be a chance that
the 'None' trick works with Magento 1.3.x (and I don't have such an instance to
run a test on it)In the mappings, the options are looked for by value, so the new option is used
with the new mappings.
* added settings/update/ fix_product_ categories. sql script to fix the related options on product_category on an existing database. Must be run manually - 646. By Alexandre Fayolle @ camptocamp <email address hidden>
-
bump up version number, reflecting schema change
- 645. By Alexandre Fayolle @ camptocamp <email address hidden>
-
[FIX] magentoerpconnect: the product.category metat_title has a max length of 255 char on magento
- 644. By Alexandre Fayolle @ camptocamp <email address hidden>
-
[FIX] magentoerpconnect: we can get a bool instead of a list of values to log. Don't truncate in that case
- 643. By Alexandre Fayolle @ camptocamp <email address hidden>
-
[IMP] magentoerpconnect: also truncate long strings in logging of returned value
- 642. By Alexandre Fayolle @ camptocamp <email address hidden>
-
[IMP] magentoerpconnect: enhance logging truncation by processing dict argument elements
- 641. By Alexandre Fayolle @ camptocamp <email address hidden>
-
[IMP] reduce verbosity logs for large strings such as images
- 640. By Guewen Baconnier @ Camptocamp <email address hidden>
-
[FIX] write the last_products_
export_ date only at the end of the products export to avoid locking sale.shop during the whole export - 639. By Guewen Baconnier @ Camptocamp <email address hidden>
-
[FIX] mappings for page_layout and default_sort_by fail when empty, force export of categories which are missing when exporting a product
- 638. By Alexandre Fayolle @ camptocamp <email address hidden>
-
[FIX] fix product_category export and stock sync problems
Preview Diff
1 | === modified file 'magento_sku_is_code/product.py' |
2 | --- magento_sku_is_code/product.py 2012-03-15 09:47:04 +0000 |
3 | +++ magento_sku_is_code/product.py 2012-07-06 14:53:18 +0000 |
4 | @@ -19,16 +19,26 @@ |
5 | # |
6 | ############################################################################## |
7 | |
8 | +import copy |
9 | + |
10 | from osv import osv, fields |
11 | |
12 | |
13 | class Product(osv.osv): |
14 | - """Inherit product to use the default code as the Magento SKU. Copy the default code into the magento_sku field.""" |
15 | + """Inherit product to use the default code as the Magento SKU. |
16 | + Copy the default code into the magento_sku field, but doesn't |
17 | + change it if the product has already been exported to an |
18 | + external referential.""" |
19 | + |
20 | _inherit = 'product.product' |
21 | |
22 | - _columns = {'magento_sku':fields.char('Magento SKU', size=64, readonly=True),} |
23 | + _columns = { |
24 | + 'magento_sku': fields.char('Magento SKU', size=64, readonly=True), |
25 | + } |
26 | |
27 | - _sql_constraints = [('code_uniq', 'unique(default_code)', 'The code must be unique')] |
28 | + _sql_constraints = [ |
29 | + ('code_uniq', 'unique(default_code)', 'The code must be unique') |
30 | + ] |
31 | |
32 | def _get_sku(self, cr, uid, vals, product=None, context=None): |
33 | """ |
34 | @@ -36,7 +46,7 @@ |
35 | @param vals: vals to be created / modified |
36 | @param product: optional browse instance of the product (when writing) |
37 | """ |
38 | - return vals['default_code'] |
39 | + return vals['default_code'].strip() |
40 | |
41 | def create(self, cr, uid, vals, context=None): |
42 | if vals.get('default_code'): |
43 | @@ -49,18 +59,27 @@ |
44 | ids_to_write = ids[:] |
45 | if vals.get('default_code'): |
46 | for product in self.browse(cr, uid, ids, context=context): |
47 | - # write separately on each product if they are not already exported |
48 | + # write separately on each product if they |
49 | + # are not already exported. because the sku value |
50 | + # will change for each product. Concretely, when a value |
51 | + # for default_code is given, we should have only one product |
52 | + # in the write |
53 | if not product.magento_exported: |
54 | - new_vals = vals.copy() |
55 | - new_vals['magento_sku'] = self._get_sku(cr, uid, new_vals, product=product, context=context) |
56 | - super(Product, self).write(cr, uid, [product.id], new_vals, context=context) |
57 | + atomic_vals = copy.deepcopy(vals) |
58 | + atomic_vals['magento_sku'] = self._get_sku( |
59 | + cr, uid, atomic_vals, product=product, context=context) |
60 | + |
61 | + super(Product, self).write( |
62 | + cr, uid, [product.id], atomic_vals, context=context) |
63 | ids_to_write.remove(product.id) |
64 | |
65 | - return super(Product, self).write(cr, uid, ids_to_write, vals, context=context) |
66 | + return super(Product, self).write( |
67 | + cr, uid, ids_to_write, vals, context=context) |
68 | |
69 | def copy(self, cr, uid, id, default=None, context=None): |
70 | if not default is None: default = {} |
71 | default['default_code'] = False |
72 | - return super(Product, self).copy(cr, uid, id, default=default, context=context) |
73 | + return super(Product, self).copy( |
74 | + cr, uid, id, default=default, context=context) |
75 | |
76 | Product() |
77 | |
78 | === modified file 'magentoerpconnect/__openerp__.py' |
79 | --- magentoerpconnect/__openerp__.py 2012-05-16 08:01:05 +0000 |
80 | +++ magentoerpconnect/__openerp__.py 2012-07-06 14:53:18 +0000 |
81 | @@ -18,7 +18,7 @@ |
82 | ######################################################################### |
83 | { |
84 | "name" : "Magento e-commerce", |
85 | - "version" : "1.0", |
86 | + "version" : "1.0.1", |
87 | "depends" : ["base", |
88 | "product", |
89 | "product_m2mcategories", |
90 | @@ -44,9 +44,22 @@ |
91 | "demo_xml" : [], |
92 | "update_xml" : [ |
93 | 'security/ir.model.access.csv', |
94 | +<<<<<<< TREE |
95 | 'settings/magerp.product_category_attribute_options.csv', |
96 | 'settings/external.referential.type.csv', |
97 | 'settings/1.5.0.0/external.referential.version.csv', |
98 | +======= |
99 | + 'settings/1.3.2.4/external.referential.type.csv', |
100 | + 'settings/1.3.2.4/external.mapping.template.csv', |
101 | + 'settings/1.3.2.4/external.mappinglines.template.csv', |
102 | + 'settings/1.4.0.0/external.referential.type.csv', |
103 | + 'settings/1.4.0.0/external.mapping.template.csv', |
104 | + 'settings/1.4.0.0/external.mappinglines.template.csv', |
105 | + 'settings/1.4.2.0/external.referential.type.csv', |
106 | + 'settings/1.4.2.0/external.mapping.template.csv', |
107 | + 'settings/1.4.2.0/external.mappinglines.template.csv', |
108 | + 'settings/1.5.0.0/external.referential.type.csv', |
109 | +>>>>>>> MERGE-SOURCE |
110 | 'settings/1.5.0.0/external.mapping.template.csv', |
111 | 'settings/1.5.0.0/external.shop.group/external.mappinglines.template.csv', |
112 | 'settings/1.5.0.0/magerp.storeviews/external.mappinglines.template.csv', |
113 | @@ -64,7 +77,9 @@ |
114 | 'settings/1.5.0.0/account.invoice/external.mappinglines.template.csv', |
115 | 'settings/1.5.0.0/product.link/external.mappinglines.template.csv', |
116 | 'settings/magerp_product_product_type.xml', |
117 | + 'settings/update/magerp.product_category_attribute_options.xml', |
118 | 'magerp_data.xml', |
119 | + 'board_view.xml', |
120 | 'magerp_core_view.xml', |
121 | 'product_view.xml', |
122 | 'partner_view.xml', |
123 | |
124 | === added file 'magentoerpconnect/board_view.xml' |
125 | --- magentoerpconnect/board_view.xml 1970-01-01 00:00:00 +0000 |
126 | +++ magentoerpconnect/board_view.xml 2012-07-06 14:53:18 +0000 |
127 | @@ -0,0 +1,30 @@ |
128 | +<?xml version="1.0" encoding="utf-8"?> |
129 | +<openerp> |
130 | + <data> |
131 | + |
132 | + <record id="board_magentoerpconnect_form" model="ir.ui.view"> |
133 | + <field name="name">board.magentoerpconnect.form</field> |
134 | + <field name="model">board.board</field> |
135 | + <field name="type">form</field> |
136 | + <field name="arch" type="xml"> |
137 | + <form string="Magentoerpconnect Dashboard"> |
138 | + <board style="2-1"> |
139 | + <column> |
140 | + <action name="%(base_external_referentials.ir_actions_act_window_external_report_line)d" string="Last Synchronizations Errors" /> |
141 | + </column> |
142 | + <column/> |
143 | + </board> |
144 | + </form> |
145 | + </field> |
146 | + </record> |
147 | + |
148 | + <record id="open_board_magentoerpconnect" model="ir.actions.act_window"> |
149 | + <field name="name">Magentoerpconnect Dashboard</field> |
150 | + <field name="res_model">board.board</field> |
151 | + <field name="view_type">form</field> |
152 | + <field name="view_mode">form</field> |
153 | + <field name="view_id" ref="board_magentoerpconnect_form"/> |
154 | + </record> |
155 | + |
156 | + </data> |
157 | +</openerp> |
158 | |
159 | === modified file 'magentoerpconnect/invoice.py' |
160 | === modified file 'magentoerpconnect/magerp_core.py' |
161 | --- magentoerpconnect/magerp_core.py 2012-05-25 15:37:26 +0000 |
162 | +++ magentoerpconnect/magerp_core.py 2012-07-06 14:53:18 +0000 |
163 | @@ -25,6 +25,10 @@ |
164 | from osv import osv, fields |
165 | import magerp_osv |
166 | import pooler |
167 | +<<<<<<< TREE |
168 | +======= |
169 | +import logging |
170 | +>>>>>>> MERGE-SOURCE |
171 | import base64, urllib |
172 | from magerp_osv import Connection |
173 | import tools |
174 | @@ -101,6 +105,10 @@ |
175 | def sync_attribs(self, cr, uid, ids, context=None): |
176 | attr_obj = self.pool.get('magerp.product_attributes') |
177 | attr_set_obj = self.pool.get('magerp.product_attribute_set') |
178 | +<<<<<<< TREE |
179 | +======= |
180 | + logger = logging.getLogger('ext synchro') |
181 | +>>>>>>> MERGE-SOURCE |
182 | for referential in self.browse(cr, uid, ids, context=context): |
183 | external_session = ExternalSession(referential, referential) |
184 | attr_conn = external_session.connection |
185 | @@ -130,7 +138,11 @@ |
186 | context=context, |
187 | ) |
188 | import_cr.commit() |
189 | +<<<<<<< TREE |
190 | _logger.info("All attributs for the attributs set id %s was succesfully imported", attr_set_id) |
191 | +======= |
192 | + logger.info("All attributs for the attributs set id %s was succesfully imported", attr_set_id) |
193 | +>>>>>>> MERGE-SOURCE |
194 | #Relate attribute sets & attributes |
195 | mage_inp = {} |
196 | #Pass in {attribute_set_id:{attributes},attribute_set_id2:{attributes}} |
197 | @@ -289,6 +301,8 @@ |
198 | filter = [filters] |
199 | return attr_conn.call('ol_customer.search', filter) |
200 | |
201 | + partner_obj = self.pool.get('res.partner') |
202 | + |
203 | for referential in self.browse(cr, uid, ids, context): |
204 | attr_conn = referential.external_connection(DEBUG) |
205 | last_imported_id = 0 |
206 | @@ -296,22 +310,24 @@ |
207 | last_imported_id = referential.last_imported_partner_id |
208 | |
209 | ext_customer_ids = next_partners(attr_conn, last_imported_id + 1, self.SYNC_PARTNER_STEP) |
210 | + |
211 | + context['use_external_log'] = True |
212 | import_cr = pooler.get_db(cr.dbname).cursor() |
213 | try: |
214 | while ext_customer_ids: |
215 | for ext_customer_id in ext_customer_ids: |
216 | - customer_info = attr_conn.call('customer.info', [ext_customer_id]) |
217 | - customer_address_info = attr_conn.call('customer_address.list', [ext_customer_id]) |
218 | - |
219 | - address_info = False |
220 | - if customer_address_info: |
221 | - address_info = customer_address_info[0] |
222 | - address_info['customer_id'] = ext_customer_id |
223 | - address_info['email'] = customer_info['email'] |
224 | - |
225 | - self.pool.get('res.partner').ext_import(import_cr, uid, [customer_info], referential.id, context=context) |
226 | - if address_info: |
227 | - self.pool.get('res.partner.address').ext_import(import_cr, uid, [address_info], referential.id, context=context) |
228 | + customer_info = attr_conn.call( |
229 | + 'customer.info', [ext_customer_id]) |
230 | + |
231 | + partner_obj.ext_import( |
232 | + import_cr, uid, [customer_info], |
233 | + referential.id, context=context) |
234 | + partner_id = partner_obj.extid_to_oeid( |
235 | + import_cr, uid, ext_customer_id, |
236 | + referential.id, context=context) |
237 | + partner_obj.import_magento_address_book( |
238 | + import_cr, uid, partner_id, |
239 | + referential.id, context=context) |
240 | |
241 | last_imported_id = int(ext_customer_id) |
242 | self.write(import_cr, uid, referential.id, {'last_imported_partner_id': last_imported_id}, context=context) |
243 | |
244 | === modified file 'magentoerpconnect/magerp_menu.xml' |
245 | --- magentoerpconnect/magerp_menu.xml 2012-03-15 09:47:04 +0000 |
246 | +++ magentoerpconnect/magerp_menu.xml 2012-07-06 14:53:18 +0000 |
247 | @@ -1,7 +1,7 @@ |
248 | <?xml version="1.0" encoding="utf-8"?> |
249 | <openerp> |
250 | <data> |
251 | - <menuitem id="menu_magerp" name="MagentoERPconnect" icon="terp-sale" |
252 | + <menuitem id="menu_magerp" name="MagentoERPconnect" icon="terp-sale" action="open_board_magentoerpconnect" |
253 | web_icon="images/magento.png" |
254 | web_icon_hover="images/magento-hover.png"/> |
255 | |
256 | @@ -25,41 +25,17 @@ |
257 | |
258 | <menuitem id="menu_magerp_reporting" name="Reporting" parent="menu_magerp" /> |
259 | |
260 | - <record id="action_magerp_external_report" model="ir.actions.act_window"> |
261 | - <field name="name">External Reports</field> |
262 | - <field name="type">ir.actions.act_window</field> |
263 | - <field name="res_model">external.report</field> |
264 | - <field name="view_type">form</field> |
265 | - <field name="domain">[('external_referential_id.type_id.name', 'like', 'Magento')]</field> <!-- erk --> |
266 | - <field name="view_id" ref="base_external_referentials.external_report_tree_view"/> |
267 | - <field name="search_view_id" ref="base_external_referentials.external_report_search_form_view"/> |
268 | - </record> |
269 | - <menuitem id="menu_magerp_reporting_report" name="Synchronisation Report" |
270 | - parent="menu_magerp_reporting" action="action_magerp_external_report" sequence="20"/> |
271 | - |
272 | - <record id="action_magerp_external_report_history" model="ir.actions.act_window"> |
273 | - <field name="name">External Report History</field> |
274 | - <field name="type">ir.actions.act_window</field> |
275 | - <field name="res_model">external.report.history</field> |
276 | - <field name="view_type">form</field> |
277 | - <field name="domain">[('external_report_id.external_referential_id.type_id.name', 'like', 'Magento')]</field> <!-- erk --> |
278 | - <field name="view_id" ref="base_external_referentials.external_report_history_tree_view"/> |
279 | - <field name="search_view_id" ref="base_external_referentials.external_report_history_search_view"/> |
280 | - </record> |
281 | - |
282 | - <menuitem id="menu_magerp_reporting_report_history" name="Synchronisation History" |
283 | - parent="menu_magerp_reporting" action="action_magerp_external_report_history" sequence="25" /> |
284 | |
285 | <record id="action_magerp_external_report_line" model="ir.actions.act_window"> |
286 | <field name="name">External Report Lines</field> |
287 | <field name="type">ir.actions.act_window</field> |
288 | <field name="res_model">external.report.line</field> |
289 | <field name="view_type">form</field> |
290 | - <field name="domain">[('external_report_id.external_referential_id.type_id.name', 'like', 'Magento')]</field> <!-- erk --> |
291 | + <field name="domain">[('referential_id.type_id.name', 'like', 'Magento')]</field> <!-- erk --> |
292 | <field name="view_id" ref="base_external_referentials.external_report_line_tree_view"/> |
293 | <field name="search_view_id" ref="base_external_referentials.external_report_line_search_view"/> |
294 | </record> |
295 | - <menuitem id="menu_magerp_reporting_report_line" name="Last Synchronisation Details" |
296 | + <menuitem id="menu_magerp_reporting_report_line" name="Synchronisation Errors" |
297 | parent="menu_magerp_reporting" action="action_magerp_external_report_line" sequence="30"/> |
298 | </data> |
299 | </openerp> |
300 | |
301 | === modified file 'magentoerpconnect/magerp_osv.py' |
302 | --- magentoerpconnect/magerp_osv.py 2012-05-24 20:52:38 +0000 |
303 | +++ magentoerpconnect/magerp_osv.py 2012-07-06 14:53:18 +0000 |
304 | @@ -23,9 +23,16 @@ |
305 | import time |
306 | import datetime |
307 | import xmlrpclib |
308 | +<<<<<<< TREE |
309 | +======= |
310 | +import logging |
311 | +>>>>>>> MERGE-SOURCE |
312 | import urllib2 |
313 | import base64 |
314 | +import pooler |
315 | from tools.translate import _ |
316 | +from openerp.addons.base_external_referentials.external_osv import MappingError |
317 | +from psycopg2 import IntegrityError |
318 | |
319 | |
320 | #NEW FEATURE |
321 | @@ -175,7 +182,7 @@ |
322 | def __init__(self, location, username, password, debug=False, logger=False): |
323 | #Append / if not there |
324 | if not location[-1] == '/': |
325 | - location += '/' |
326 | + location += '/' |
327 | self.corelocation = location |
328 | #Please do not remove the str indeed xmlrpc lib require a string for the location |
329 | #if an unicode is send it will raise you an error |
330 | @@ -184,26 +191,46 @@ |
331 | self.password = password |
332 | self.debug = debug |
333 | self.result = {} |
334 | +<<<<<<< TREE |
335 | self.logger = logger or _logger |
336 | |
337 | |
338 | +======= |
339 | + self.logger = logging.getLogger('Connection(%s)' % self.location) |
340 | + |
341 | + |
342 | +>>>>>>> MERGE-SOURCE |
343 | def connect(self): |
344 | if not self.location[-1] == '/': |
345 | self.location += '/' |
346 | if self.debug: |
347 | +<<<<<<< TREE |
348 | self.logger.info("Attempting connection with Settings:%s,%s,%s" % (self.location, self.username, self.password)) |
349 | +======= |
350 | + self.logger.info(_("Attempting connection with Settings:%s,%s,%s"), self.location, self.username, self.password) |
351 | +>>>>>>> MERGE-SOURCE |
352 | self.ser = xmlrpclib.ServerProxy(self.location) |
353 | for sleep_time in [1, 3, 6]: |
354 | try: |
355 | self.session = self.ser.login(self.username, self.password) |
356 | if self.debug: |
357 | +<<<<<<< TREE |
358 | self.logger.info("Login Successful") |
359 | +======= |
360 | + self.logger.info(_("Login Successful")) |
361 | +>>>>>>> MERGE-SOURCE |
362 | return True |
363 | except IOError, e: |
364 | +<<<<<<< TREE |
365 | self.logger.error("Error in connecting:%s" % e) |
366 | self.logger.warning("Webservice Failure, sleeping %s second before next attempt" % sleep_time) |
367 | +======= |
368 | + self.logger.error(_("Error in connecting:%s"), e, exc_info=True) |
369 | + self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time) |
370 | +>>>>>>> MERGE-SOURCE |
371 | time.sleep(sleep_time) |
372 | except Exception,e: |
373 | +<<<<<<< TREE |
374 | self.logger.error("Magento Connection" + netsvc.LOG_ERROR + "Error in connecting:%s" % e) |
375 | self.logger.warning("Webservice Failure, sleeping %s second before next attempt" % sleep_time) |
376 | time.sleep(sleep_time) |
377 | @@ -211,6 +238,34 @@ |
378 | |
379 | |
380 | def call(self, method, *arguments): |
381 | +======= |
382 | + self.logger.error(_("Error in connecting:%s"), e, exc_info=True) |
383 | + self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time) |
384 | + time.sleep(sleep_time) |
385 | + raise osv.except_osv(_('User Error'), _('Error connecting to magento, are your sure that your login is right? Did you configure API user in magento?')) |
386 | + |
387 | + def _truncate_arguments(self, arguments, max_length=128): |
388 | + """truncate long strings in arguments for logging purpose""" |
389 | + logged_args = [] |
390 | + try: |
391 | + for arg in arguments: |
392 | + # reduce verbosity of log for large strings (e.g. base64 encoded images...) |
393 | + if isinstance(arg, basestring) and len(arg) > max_length: |
394 | + arg = arg[:max_length] + '...' |
395 | + elif isinstance(arg, dict): |
396 | + new_arg = {} |
397 | + for key, value in arg.iteritems(): |
398 | + if isinstance(value, basestring) and len(value) > max_length: |
399 | + value = value[:max_length] + '...' |
400 | + new_arg[key] = value |
401 | + arg = new_arg |
402 | + logged_args.append(arg) |
403 | + return logged_args |
404 | + except TypeError: # arguments can be a bool |
405 | + return arguments |
406 | + |
407 | + def call(self, method, *arguments): |
408 | +>>>>>>> MERGE-SOURCE |
409 | if arguments: |
410 | arguments = list(arguments)[0] |
411 | else: |
412 | @@ -218,18 +273,37 @@ |
413 | for sleep_time in [1, 3, 6]: |
414 | try: |
415 | if self.debug: |
416 | +<<<<<<< TREE |
417 | self.logger.info(_("Calling Method:%s,Arguments:%s") % (method, arguments)) |
418 | +======= |
419 | + logged_args = self._truncate_arguments(arguments) |
420 | + self.logger.info(_("Calling Method:%s,Arguments:%s"), method, logged_args) |
421 | +>>>>>>> MERGE-SOURCE |
422 | res = self.ser.call(self.session, method, arguments) |
423 | if self.debug: |
424 | + logged_res = self._truncate_arguments(res) |
425 | if method=='catalog_product.list': |
426 | # the response of the method catalog_product.list can be very very long so it's better to see it only if debug log is activate |
427 | +<<<<<<< TREE |
428 | self.logger.debug(_("Query Returned:%s") % (res)) |
429 | +======= |
430 | + self.logger.debug(_("Query Returned:%s"), logged_res) |
431 | +>>>>>>> MERGE-SOURCE |
432 | else: |
433 | +<<<<<<< TREE |
434 | self.logger.info(_("Query Returned:%s") % (res)) |
435 | +======= |
436 | + self.logger.info(_("Query Returned:%s"), logged_res) |
437 | +>>>>>>> MERGE-SOURCE |
438 | return res |
439 | except IOError, e: |
440 | +<<<<<<< TREE |
441 | self.logger.error(_("Method: %s\nArguments:%s\nError:%s") % (method, arguments, e)) |
442 | self.logger.warning(_("Webservice Failure, sleeping %s second before next attempt") % (sleep_time)) |
443 | +======= |
444 | + self.logger.error(_("Method: %s\nArguments:%s\nError:%s"), method, arguments, e, exc_info=True) |
445 | + self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time) |
446 | +>>>>>>> MERGE-SOURCE |
447 | time.sleep(sleep_time) |
448 | raise |
449 | |
450 | @@ -254,7 +328,7 @@ |
451 | _DELETE_METHOD = False |
452 | _mapping = {} |
453 | DEBUG = False |
454 | - |
455 | + |
456 | #TODO deprecated, remove use |
457 | def mage_to_oe(self, cr, uid, mageid, instance, *arguments): |
458 | """given a record id in the Magento referential, returns a tuple (id, name) with the id in the OpenERP referential; Magento instance wise""" |
459 | @@ -279,7 +353,7 @@ |
460 | read = self.read(cr, uid, oeid, [self._rec_name]) |
461 | return (read[0]['id'], read[0][self._rec_name]) |
462 | return False |
463 | - |
464 | + |
465 | #TODO deprecated, remove use |
466 | def sync_import(self, cr, uid, magento_records, instance, debug=False, defaults=None, *attrs): |
467 | |
468 | @@ -314,7 +388,7 @@ |
469 | 'temp_vars':{}, |
470 | 'mage2oe_filters':mage2oe_filters |
471 | } |
472 | - |
473 | + |
474 | #now properly mapp known Magento attributes to OpenERP entity columns: |
475 | for each_valid_key in self._mapping: |
476 | if each_valid_key in magento_record.keys(): |
477 | @@ -347,13 +421,12 @@ |
478 | if self._mapping[each_valid_key][0]:#if not function mapping |
479 | vals[self._mapping[each_valid_key][0]] = magento_record[each_valid_key] or False |
480 | vals['referential_id'] = instance |
481 | - tools.debug(vals) |
482 | if self._MAGE_FIELD: |
483 | if self._MAGE_FIELD in vals.keys() and vals[self._MAGE_FIELD]: |
484 | self.record_save(cr, uid, rec_id, vals, defaults) |
485 | else: |
486 | self.record_save(cr, uid, rec_id, vals, defaults) |
487 | - |
488 | + |
489 | def record_save(self, cr, uid, rec_id, vals, defaults): |
490 | if defaults: |
491 | for key in defaults.keys(): |
492 | @@ -364,7 +437,7 @@ |
493 | else: |
494 | #Record is not there, create it |
495 | self.create(cr, uid, vals,) |
496 | - |
497 | + |
498 | def cast_string(self, subject): |
499 | """This function will convert string objects to the data type required. Example "0"/"1" to boolean conversion""" |
500 | for key in subject.keys(): |
501 | @@ -374,7 +447,7 @@ |
502 | else: |
503 | subject[key] = True |
504 | return subject |
505 | - |
506 | + |
507 | def mage_import_base(self,cr,uid,conn, external_referential_id, defaults=None, context=None): |
508 | if context is None: |
509 | context = {} |
510 | @@ -396,7 +469,7 @@ |
511 | list_method = self.pool.get('external.mapping').read(cr,uid,mapping_id[0],['external_list_method']).get('external_list_method',False) |
512 | if list_method: |
513 | data = conn.call(list_method, context['ids_or_filter']) |
514 | - |
515 | + |
516 | #it may happen that list method doesn't provide enough information, forcing us to use get_method on each record (case for sale orders) |
517 | if context.get('one_by_one', False): |
518 | self.mage_import_one_by_one(cr, uid, conn, external_referential_id, mapping_id[0], data, defaults, context) |
519 | @@ -405,24 +478,60 @@ |
520 | |
521 | return result |
522 | |
523 | + def _mage_import_one(self, cr, uid, conn, record, referential_id, mapping_id, defaults=None, context=None): |
524 | + ext_id = record[self.pool.get('external.mapping').read(cr, uid, mapping_id, ['external_key_name'])['external_key_name']] |
525 | + get_method = self.pool.get('external.mapping').read(cr, uid, mapping_id, ['external_get_method']).get('external_get_method',False) |
526 | + rec_data = [conn.call(get_method, [ext_id])] |
527 | + rec_result = self.ext_import(cr, uid, rec_data, referential_id, defaults, context) |
528 | + return rec_result['create_ids'], rec_result['write_ids'] |
529 | + |
530 | def mage_import_one_by_one(self, cr, uid, conn, external_referential_id, mapping_id, data, defaults=None, context=None): |
531 | if context is None: |
532 | context = {} |
533 | + report_line_obj = self.pool.get('external.report.line') |
534 | result = {'create_ids': [], 'write_ids': []} |
535 | - if context.get('one_by_one', False): |
536 | - del(context['one_by_one']) |
537 | + import_ctx = dict(context) |
538 | + import_ctx.pop('one_by_one', False) |
539 | + # avoid to use external logs in submethods as they are handle at this level |
540 | + import_ctx.pop('use_external_log', False) |
541 | + import_ctx['import_no_new_cr'] = True |
542 | for record in data: |
543 | - id = record[self.pool.get('external.mapping').read(cr, uid, mapping_id, ['external_key_name'])['external_key_name']] |
544 | - get_method = self.pool.get('external.mapping').read(cr, uid, mapping_id, ['external_get_method']).get('external_get_method',False) |
545 | - rec_data = [conn.call(get_method, [id])] |
546 | - rec_result = self.ext_import(cr, uid, rec_data, external_referential_id, defaults, context) |
547 | - result['create_ids'].append(rec_result['create_ids']) |
548 | - result['write_ids'].append(rec_result['write_ids']) |
549 | - # and let the import continue, because it will be imported on the next import |
550 | + record_cr = pooler.get_db(cr.dbname).cursor() |
551 | + try: |
552 | + ext_id = record[self.pool.get('external.mapping').read( |
553 | + record_cr, uid, mapping_id, ['external_key_name'])['external_key_name']] |
554 | + cids, wids = self._mage_import_one( |
555 | + record_cr, uid, conn, record, external_referential_id, mapping_id, defaults=defaults, context=import_ctx) |
556 | + except (MappingError, osv.except_osv, xmlrpclib.Fault, IntegrityError): |
557 | + record_cr.rollback() |
558 | + report_line_obj.log_failed( |
559 | + cr, uid, |
560 | + self._name, |
561 | + 'import', |
562 | + external_referential_id, |
563 | + external_id=ext_id, |
564 | + defaults=defaults, |
565 | + context=context) |
566 | + else: |
567 | + record_cr.commit() |
568 | + report_line_obj.log_success( |
569 | + cr, uid, |
570 | + self._name, |
571 | + 'import', |
572 | + external_referential_id, |
573 | + external_id=ext_id, |
574 | + context=context) |
575 | + result['create_ids'].append(cids) |
576 | + result['write_ids'].append(wids) |
577 | + finally: |
578 | + record_cr.close() |
579 | return result |
580 | |
581 | def get_external_data(self, cr, uid, conn, external_referential_id, defaults=None, context=None): |
582 | """Constructs data using WS or other synch protocols and then call ext_import on it""" |
583 | + if context is None: |
584 | + context = {} |
585 | + context = dict(context) |
586 | return self.mage_import_base(cr, uid, conn, external_referential_id, defaults, context)#TODO refactor mage_import_base calls to this interface |
587 | |
588 | #TODO deprecated, remove use |
589 | @@ -438,7 +547,7 @@ |
590 | self.sync_import(cr, uid, magento_records, instance, debug, defaults) |
591 | else: |
592 | raise osv.except_osv(_('Undefined List method !'), _("list method is undefined for this object!")) |
593 | - |
594 | + |
595 | #TODO deprecated, remove use |
596 | def get_all_mage_ids(self, cr, uid, ids, instance=False): |
597 | search_param = [] |
598 | @@ -451,4 +560,4 @@ |
599 | for each in reads: |
600 | mageids.append(each[self._MAGE_FIELD]) |
601 | return mageids |
602 | - |
603 | + |
604 | |
605 | === modified file 'magentoerpconnect/partner.py' |
606 | --- magentoerpconnect/partner.py 2012-05-19 13:37:23 +0000 |
607 | +++ magentoerpconnect/partner.py 2012-07-06 14:53:18 +0000 |
608 | @@ -22,6 +22,9 @@ |
609 | #along with this program. If not, see <http://www.gnu.org/licenses/>. # |
610 | ######################################################################### |
611 | |
612 | +import string |
613 | +import copy |
614 | + |
615 | from osv import osv, fields |
616 | from tools.translate import _ |
617 | import magerp_osv |
618 | @@ -52,6 +55,7 @@ |
619 | return res |
620 | |
621 | _columns = { |
622 | +<<<<<<< TREE |
623 | 'name': fields.function(_get_partner_name, obj="res.partner.address", type = 'char', size = 256, |
624 | store = { |
625 | 'res.partner.address' : (lambda self, cr, uid, ids, c={}: ids, |
626 | @@ -60,8 +64,22 @@ |
627 | 'firstname':fields.char('First Name', size=100), |
628 | 'lastname':fields.char('Last Name', size=100), |
629 | 'is_magento_order_address':fields.boolean('Magento Order Address?'), #TODO still needed? |
630 | +======= |
631 | + 'firstname':fields.char('First Name', size=100), |
632 | + 'lastname':fields.char('Last Name', size=100), |
633 | + 'is_magento_order_address': |
634 | + fields.boolean('Magento Order Address', |
635 | + help="Created for a Magento sale order", |
636 | + readonly=True), |
637 | + 'magento_address_book': |
638 | + fields.boolean('Magento Address Book', |
639 | + help="Part of the Magento Address Book", |
640 | + readonly=True) |
641 | +>>>>>>> MERGE-SOURCE |
642 | } |
643 | + |
644 | _defaults = { |
645 | +<<<<<<< TREE |
646 | 'is_magento_order_address': lambda * a:False, |
647 | } |
648 | |
649 | @@ -75,6 +93,19 @@ |
650 | ext_create_ids[resource_id] = ext_id |
651 | return ext_create_ids |
652 | |
653 | +======= |
654 | + 'is_magento_order_address': lambda * a: False, |
655 | + } |
656 | + |
657 | + def mage_import_base(self,cr,uid,conn, external_referential_id, defaults=None, context=None): |
658 | + # quick hack |
659 | + # remove the id so the address will be imported using "list method" |
660 | + # instead of "get method" because the entity_id field miss in the get method. |
661 | + context.pop('id', False) |
662 | + return super(res_partner_address, self).mage_import_base( |
663 | + cr, uid, conn, external_referential_id, defaults=defaults, context=context) |
664 | + |
665 | +>>>>>>> MERGE-SOURCE |
666 | res_partner_address() |
667 | |
668 | class res_partner(magerp_osv.magerp_osv): |
669 | @@ -107,11 +138,20 @@ |
670 | 'mag_birthday':fields.date('Birthday', help="To be able to receive customer birthday you must set it in Magento Admin Panel, menu System / Configuration / Client Configuration / Name and Address Options."), |
671 | 'mag_newsletter':fields.boolean('Newsletter'), |
672 | 'magento_exported': fields.function(_is_magento_exported, type="boolean", method=True, string="Exists on Magento"), |
673 | +<<<<<<< TREE |
674 | 'magento_pwd': fields.char('Magento Password', size=256), |
675 | +======= |
676 | + 'is_magento_guest': fields.boolean( |
677 | + 'Is a Magento guest', |
678 | + help="This partner has been created for a Magento " |
679 | + "guest sale order.", |
680 | + readonly=True) |
681 | +>>>>>>> MERGE-SOURCE |
682 | } |
683 | |
684 | _sql_constraints = [('emailid_uniq', 'unique(emailid, website_id)', 'A partner already exists with this email address on the selected website.')] |
685 | |
686 | +<<<<<<< TREE |
687 | @only_for_referential('magento') |
688 | def get_ids_and_update_date(self, cr, uid, external_session, ids=None, last_exported_date=None, context=None): |
689 | store_ids = [store.id for store in external_session.sync_from_object.storeview_ids] |
690 | @@ -143,5 +183,217 @@ |
691 | for resource_id in resource_ids: |
692 | result = address_obj._export_one_resource(cr, uid, external_session, resource_id, context=context) |
693 | return res |
694 | +======= |
695 | + def _import_magento_addresses(self, cr, uid, connection, ext_customer_id, |
696 | + referential_id, context=None): |
697 | + """ |
698 | + Import all the magento addresses of a magento customer's address book |
699 | + |
700 | + :param connection: connection to Magento |
701 | + :param int ext_customer_id: id on Magento of the customer |
702 | + :param int referential_id: id of the Magento external referential |
703 | + """ |
704 | + if context is None: |
705 | + context = {} |
706 | + address_obj = self.pool.get('res.partner.address') |
707 | + import_ctx = context.copy() |
708 | + import_ctx['ids_or_filter'] = [ext_customer_id] |
709 | + defaults = {'magento_address_book': True} |
710 | + return address_obj.get_external_data( |
711 | + cr, uid, connection, referential_id, |
712 | + defaults=defaults, context=import_ctx) |
713 | + |
714 | + def _disable_missing_addresses(self, cr, uid, partner_id, curr_address_ids, |
715 | + referential_id, context=None): |
716 | + """ |
717 | + Disable the addresses of the partner which have been deleted on |
718 | + Magento since last synchronization. |
719 | + |
720 | + :param int partner_id: id of the partner for whom we |
721 | + update the addresses |
722 | + :param list curr_address_ids: list of openerp ids of the addresses |
723 | + which currently exist in the magento address book |
724 | + :param int referential_id: id of the Magento external referential |
725 | + :return: True |
726 | + """ |
727 | + # list of the all the addresses in openerp which have been imported |
728 | + # from this referential |
729 | + address_obj = self.pool.get('res.partner.address') |
730 | + partner_address_ids = address_obj.search( |
731 | + cr, uid, [('partner_id', '=', partner_id)], context=context) |
732 | + all_ref_address_ids = \ |
733 | + [address_id for address_id in partner_address_ids |
734 | + if address_obj.oeid_to_extid( |
735 | + cr, uid, address_id, referential_id, context=context)] |
736 | + |
737 | + # do a diff to know which addresses does not anymore exist |
738 | + # on Magento |
739 | + del_address_ids = set(all_ref_address_ids).difference(curr_address_ids) |
740 | + address_obj.write( |
741 | + cr, uid, del_address_ids, {'active': False}, context=context) |
742 | + return True |
743 | + |
744 | + def import_magento_address_book(self, cr, uid, ids, referential_id, |
745 | + context=None): |
746 | + """ |
747 | + Import all the addresses from the Magento referential's address book |
748 | + Deactivate the addresses which have been deleted from Magento |
749 | + since the last import. |
750 | + |
751 | + :param int/list ids: ids or list of ids of partner to import the |
752 | + address book |
753 | + :param int referential_id: id of the Magento external referential |
754 | + """ |
755 | + if context is None: |
756 | + context = {} |
757 | + |
758 | + if isinstance(ids, (int, long)): |
759 | + ids = [ids] |
760 | + |
761 | + ref_obj = self.pool.get('external.referential') |
762 | + connection = context.get('conn_obj') or \ |
763 | + ref_obj.external_connection( |
764 | + cr, uid, referential_id, context=context) |
765 | + |
766 | + for partner_id in ids: |
767 | + ext_customer_id = self.oeid_to_extid( |
768 | + cr, uid, partner_id, referential_id, context=context) |
769 | + |
770 | + result = self._import_magento_addresses( |
771 | + cr, uid, connection, ext_customer_id, referential_id, |
772 | + context=context) |
773 | + |
774 | + # list of all addresses currently in the magento address book |
775 | + curr_address_ids = result['create_ids'] + result['write_ids'] |
776 | + self._disable_missing_addresses( |
777 | + cr, uid, partner_id, curr_address_ids, referential_id, |
778 | + context=context) |
779 | + |
780 | + return True |
781 | + |
782 | + def add_magento_vat_number(self, cr, uid, partner_id, tax_vat, country_code=None, context=None): |
783 | + """Adds vat number (country code+magento vat) if base_vat module is installed and Magento sends customer_taxvat |
784 | + TODO replace me by a generic function maybe the best solution will to have a field vat and a flag vat_ok and a flag force vat_ok |
785 | + And so it's will be possible to have an invalid vat number (imported from magento for exemple) but the flag will be not set |
786 | + Also we should think about the way to update customer. Indeed by default there are never updated""" |
787 | + partner_vals = {'mag_vat': tax_vat} |
788 | + cr.execute('select * from ir_module_module where name=%s and state=%s', ('base_vat','installed')) |
789 | + if cr.fetchone(): |
790 | + allchars = string.maketrans('', '') |
791 | + delchars = ''.join([c for c in allchars if c not in string.letters + string.digits]) |
792 | + vat = tax_vat.translate(allchars, delchars).upper() |
793 | + vat_country, vat_number = vat[:2].lower(), vat[2:] |
794 | + vat_ok = False |
795 | + if 'check_vat_' + vat_country in dir(self): |
796 | + check = getattr(self, 'check_vat_' + vat_country) |
797 | + vat_ok = check(vat_number) |
798 | + else: |
799 | + # Maybe magento vat number has not country code prefix. Take it from billing address. |
800 | + if country_code: |
801 | + fnct = 'check_vat_' + country_code.lower() |
802 | + if fnct in dir(self): |
803 | + check = getattr(self, fnct) |
804 | + vat_ok = check(vat) |
805 | + vat = country_code + vat |
806 | + else: |
807 | + vat_ok = False |
808 | + if vat_ok: |
809 | + partner_vals.update({'vat_subjected':True, 'vat':vat}) |
810 | + self.write(cr, uid, [partner_id], partner_vals) |
811 | + return True |
812 | + |
813 | + def write(self, cr, uid, ids, vals, context=None): |
814 | + if isinstance(ids, (int, long)): |
815 | + ids = [ids] |
816 | + if vals.get('store_id') and not vals.get('store_ids'): |
817 | + for partner_id in ids: |
818 | + # Add the last store id visited if |
819 | + # it is not in the list of store ids |
820 | + # partner store_id = last store where he bought (so this order) |
821 | + # partner store_ids = all stores where he bought |
822 | + atomic_vals = copy.deepcopy(vals) |
823 | + partner = self.browse(cr, uid, partner_id, context=context) |
824 | + if partner.store_id: |
825 | + last_store_id = partner.store_id.id |
826 | + if last_store_id not in [st.id for st in partner.store_ids]: |
827 | + atomic_vals['store_ids'] = [(4, last_store_id)] |
828 | + |
829 | + super(res_partner, self).write( |
830 | + cr, uid, partner_id, atomic_vals, context=context) |
831 | + else: |
832 | + return super(res_partner, self).write( |
833 | + cr, uid, ids, vals, context=context) |
834 | + return True |
835 | + |
836 | + def create(self, cr, uid, vals, context=None): |
837 | + if vals.get('store_id') and not vals.get('store_ids'): |
838 | + vals['store_ids'] = [(4, vals['store_id'])] |
839 | + return super(res_partner, self).create(cr, uid, vals, context=context) |
840 | + |
841 | + def search_magento_partner(self, cr, uid, magento_email, website_id, is_bound=None, context=None): |
842 | + """ |
843 | + Searches and returns the partners which are potentially the same |
844 | + based on the mail and the magento website id |
845 | + |
846 | + :param str magento_email: mail of the customer on magento |
847 | + :param int website_id: id of the website (openerp id!) |
848 | + :param bool is_bound: specify it the partner must already be bound |
849 | + with a magento customer (True) or not (False) |
850 | + When None value: all partners ids are returned |
851 | + :return: id of the found partner or False if any partner's found |
852 | + """ |
853 | + partner_ids = False |
854 | + if website_id: |
855 | + partner_ids = self.search(cr, uid, |
856 | + [('emailid', '=', magento_email), |
857 | + ('website_id', '=', website_id)], |
858 | + context=context) |
859 | + |
860 | + # when the partner has been created, the website is not necessarily |
861 | + # filled, in such case we search the first occurrence |
862 | + # with the same email not already bound with a magento customer |
863 | + if not partner_ids: |
864 | + partner_ids = self.search(cr, uid, |
865 | + [('emailid', '=', magento_email), |
866 | + ('website_id', '=', False)], |
867 | + context=context) |
868 | + # keep or exclude already bound partners according to argument is_bound |
869 | + if is_bound is not None: |
870 | + partner_ids = [partner.id for partner |
871 | + in self.browse(cr, uid, partner_ids[:], context=context) |
872 | + if bool(partner.magento_exported) is is_bound] |
873 | + |
874 | + return partner_ids and partner_ids[0] or False |
875 | + |
876 | + def _existing_oeid_for_extid_import(self, cr, uid, vals, external_id, external_referential_id, context=None): |
877 | + """ |
878 | + When importing a new customer from Magento (no external_id found in ir.model.data), we search |
879 | + for a partner with the same emailid and website than the imported one |
880 | + (fields must be filled in advance). |
881 | + |
882 | + The external customer will update the partner returned in the tuple. |
883 | + The external id will be created on this partner with the external resource |
884 | + if the value is False in the tuple. |
885 | + |
886 | + :param dict vals: vals to create in OpenERP, already evaluated by oevals_from_extdata |
887 | + :param int external_id: external id of the resource to create |
888 | + :param int external_referential_id: external referential id from where we import the resource |
889 | + :return: tuple of (ir.model.data id / False: external id to create, model resource id / False: resource to create) |
890 | + """ |
891 | + existing_ir_model_data_id, existing_res_id = super(res_partner, self)\ |
892 | + ._existing_oeid_for_extid_import(cr, uid, vals, external_id, external_referential_id, context=context) |
893 | + |
894 | + if existing_res_id: |
895 | + return existing_ir_model_data_id, existing_res_id |
896 | + |
897 | + partner_id = self.search_magento_partner( |
898 | + cr, uid, |
899 | + vals['emailid'], |
900 | + vals.get('website_id', False), |
901 | + is_bound=None, |
902 | + context=context) |
903 | + |
904 | + return False, partner_id |
905 | +>>>>>>> MERGE-SOURCE |
906 | |
907 | res_partner() |
908 | |
909 | === modified file 'magentoerpconnect/partner_view.xml' |
910 | --- magentoerpconnect/partner_view.xml 2012-05-19 13:37:23 +0000 |
911 | +++ magentoerpconnect/partner_view.xml 2012-07-06 14:53:18 +0000 |
912 | @@ -7,11 +7,15 @@ |
913 | <field name="type">form</field> |
914 | <field name="inherit_id" ref="base.view_partner_form" /> |
915 | <field name="arch" type="xml"> |
916 | +<<<<<<< TREE |
917 | <xpath expr="/form/notebook/page/field/form/group/field[@name='name']" position="replace" > |
918 | <field name="company" /> |
919 | <field name="firstname" /> |
920 | <field name="lastname" /> |
921 | </xpath> |
922 | +======= |
923 | + <data> |
924 | +>>>>>>> MERGE-SOURCE |
925 | <xpath expr="/form/notebook" position="inside"> |
926 | <page string="Magento Information"> |
927 | <field name="magento_exported" invisible="True"/> |
928 | @@ -23,11 +27,19 @@ |
929 | <field name="mag_birthday" /> |
930 | <field name="mag_newsletter" select="2"/> |
931 | <field name="store_id" /> |
932 | + <field name="is_magento_guest"/> |
933 | <newline/> |
934 | <separator string="Store views" colspan="4" /> |
935 | <field name="store_ids" colspan="4" nolabel="1" attrs="{'readonly': [('magento_exported', '=', True)]}"/> |
936 | </page> |
937 | </xpath> |
938 | + <xpath expr="//tree[@string='Partner Contacts']/field[@name='email']" position="after"> |
939 | + <field name="magento_address_book"/> |
940 | + </xpath> |
941 | + <xpath expr="//form[@string='Partner Contacts']/group[3]/field[@name='email']" position="after"> |
942 | + <field name="magento_address_book"/> |
943 | + </xpath> |
944 | + </data> |
945 | </field> |
946 | </record> |
947 | |
948 | @@ -50,11 +62,37 @@ |
949 | <field name="type">form</field> |
950 | <field name="inherit_id" ref="base.view_partner_address_form1" /> |
951 | <field name="arch" type="xml"> |
952 | +<<<<<<< TREE |
953 | <field name="name" position="replace"> |
954 | <field name="company" /> |
955 | <field name="firstname" /> |
956 | <field name="lastname" /> |
957 | </field> |
958 | +======= |
959 | + <data> |
960 | + <field name="active" position="after"> |
961 | + <field name="magento_address_book"/> |
962 | + </field> |
963 | + <field name="name" position="after"> |
964 | + <field name="firstname" /> |
965 | + <field name="lastname" /> |
966 | + </field> |
967 | + </data> |
968 | + </field> |
969 | + </record> |
970 | + |
971 | + <record id="view_partner_address_tree_mag" model="ir.ui.view"> |
972 | + <field name="name">res.partner.address.tree.mag</field> |
973 | + <field name="model">res.partner.address</field> |
974 | + <field name="inherit_id" ref="base.view_partner_address_tree"/> |
975 | + <field name="type">tree</field> |
976 | + <field name="arch" type="xml"> |
977 | + <data> |
978 | + <field name="type" position="after"> |
979 | + <field name="magento_address_book"/> |
980 | + </field> |
981 | + </data> |
982 | +>>>>>>> MERGE-SOURCE |
983 | </field> |
984 | </record> |
985 | |
986 | |
987 | === modified file 'magentoerpconnect/product.py' |
988 | --- magentoerpconnect/product.py 2012-05-25 19:24:00 +0000 |
989 | +++ magentoerpconnect/product.py 2012-07-06 14:53:18 +0000 |
990 | @@ -28,9 +28,14 @@ |
991 | import pooler |
992 | import magerp_osv |
993 | from tools.translate import _ |
994 | +<<<<<<< TREE |
995 | +======= |
996 | +import logging |
997 | +>>>>>>> MERGE-SOURCE |
998 | import unicodedata |
999 | import base64, urllib |
1000 | import os |
1001 | +import xmlrpclib |
1002 | from lxml import etree |
1003 | import xmlrpclib |
1004 | |
1005 | @@ -175,7 +180,7 @@ |
1006 | 'description': fields.text('Description'), |
1007 | 'image': fields.binary('Image'), |
1008 | 'image_name':fields.char('File Name', size=100), |
1009 | - 'meta_title': fields.char('Title (Meta)', size=75), |
1010 | + 'meta_title': fields.char('Title (Meta)', size=255), |
1011 | 'meta_keywords': fields.text('Meta Keywords'), |
1012 | 'meta_description': fields.text('Meta Description'), |
1013 | 'url_key': fields.char('URL-key', size=100), #Readonly |
1014 | @@ -209,6 +214,7 @@ |
1015 | vals['magerp_stamp'] = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT) |
1016 | return super(product_category, self).write(cr, uid, ids, vals, context) |
1017 | |
1018 | +<<<<<<< TREE |
1019 | def _get_external_resource_ids(self, cr, uid, external_session, resource_filter=None, mapping=None, context=None): |
1020 | def get_child_ids(tree): |
1021 | result=[] |
1022 | @@ -222,6 +228,77 @@ |
1023 | categ_tree = external_session.connection.call('catalog_category.tree') #Get the tree |
1024 | ids = get_child_ids(categ_tree) |
1025 | return ids |
1026 | +======= |
1027 | + def record_entire_tree(self, cr, uid, id, conn, categ_tree, DEBUG=False): |
1028 | + self.record_category(cr, uid, id, conn, int(categ_tree['category_id'])) |
1029 | + for each in categ_tree['children']: |
1030 | + self.record_entire_tree(cr, uid, id, conn, each) |
1031 | + return True |
1032 | + |
1033 | + def record_category(self, cr, uid, external_referential_id, conn, category_id): |
1034 | + #This function should record a category |
1035 | + #The parent has to be created before creating child |
1036 | + imp_vals = conn.call('category.info', [category_id]) |
1037 | + self.ext_import(cr, uid, [imp_vals], external_referential_id, defaults={}, context={'conn_obj':conn}) |
1038 | + |
1039 | + def ext_export(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None): # We export all the categories if at least one has been modified since last export |
1040 | + #TODO Move this function in base_sale_multichannels |
1041 | + if context is None: |
1042 | + context = {} |
1043 | + |
1044 | + if defaults is None: |
1045 | + defaults = {} |
1046 | + |
1047 | + res = False |
1048 | + orig_ids = ids[:] |
1049 | + ids_exportable = self.search(cr, uid, [('id', 'in', ids), ('magento_exportable', '=', True)]) #restrict export to only exportable products |
1050 | + ids = [id for id in ids if id in ids_exportable] #we need to keep the order of the categories |
1051 | + if not ids: |
1052 | + logger = logging.getLogger('magentoerpconnect') |
1053 | + logger.warning('called ext_export with ids %s, of which none were exportable', orig_ids) |
1054 | + return res |
1055 | + |
1056 | + shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id']) |
1057 | + |
1058 | + context_dic = [context.copy()] |
1059 | + context_dic[0]['export_url'] = True # for the magento version 1.3.2.4, only one url is autorized by category, so we only export with the MAPPING TEMPLATE the url of the default language |
1060 | + context_dic[0]['lang'] = shop.referential_id.default_lang_id.code |
1061 | + |
1062 | + for storeview in shop.storeview_ids: |
1063 | + if storeview.lang_id and storeview.lang_id.code != shop.referential_id.default_lang_id.code: |
1064 | + context_dic += [context.copy()] |
1065 | + context_dic[len(context_dic)-1].update({'storeview_code': storeview.code, 'lang': storeview.lang_id.code}) |
1066 | + |
1067 | + if shop.last_products_export_date and not context.get('force_export'): |
1068 | + last_exported_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(shop.last_products_export_date[:19], DEFAULT_SERVER_DATETIME_FORMAT))) |
1069 | + else: |
1070 | + last_exported_time = False |
1071 | + |
1072 | + if not last_exported_time: |
1073 | + for ctx_storeview in context_dic: |
1074 | + ctx_storeview['force'] = True |
1075 | + res = super(product_category, self).ext_export(cr, uid, ids, external_referential_ids, defaults, ctx_storeview) |
1076 | + else: |
1077 | + cr.execute("select write_date, create_date from product_category where id in %s", (tuple(ids),)) |
1078 | + read = cr.fetchall() |
1079 | + for categ in read: |
1080 | + last_updated_categ = categ[0] and categ[0].split('.')[0] or categ[1] and categ[1].split('.')[0] or False |
1081 | + last_updated_categ_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(last_updated_categ[:19], DEFAULT_SERVER_DATETIME_FORMAT))) |
1082 | + if last_updated_categ_time and last_exported_time: |
1083 | + if last_exported_time - datetime.timedelta(seconds=1) < last_updated_categ_time: |
1084 | + for ctx_storeview in context_dic: |
1085 | + ctx_storeview['force'] = True |
1086 | + res = super(product_category, self).ext_export(cr, uid, ids, external_referential_ids, defaults, ctx_storeview) |
1087 | + break |
1088 | + return res |
1089 | + |
1090 | + def try_ext_update(self, cr, uid, data, conn, method, oe_id, external_id, ir_model_data_id, create_method, context=None): |
1091 | + if context is None: context = {} |
1092 | + if context.get('storeview_code', False): |
1093 | + return conn.call(method, [external_id, data, context.get('storeview_code', False)]) |
1094 | + else: |
1095 | + return conn.call(method, [external_id, data]) |
1096 | +>>>>>>> MERGE-SOURCE |
1097 | |
1098 | product_category() |
1099 | |
1100 | @@ -255,6 +332,7 @@ |
1101 | ('gallery', 'Gallery'), |
1102 | ('weee', 'Fixed Product Tax'), |
1103 | ('file', 'File'), #this option is not a magento native field it will be better to found a generic solutionto manage this kind of custom option |
1104 | + ('weight', 'Weight'), |
1105 | ], 'Frontend Input' |
1106 | ), |
1107 | 'frontend_class':fields.char('Frontend Class', size=100), |
1108 | @@ -290,13 +368,20 @@ |
1109 | #These parameters are for automatic management |
1110 | 'field_name':fields.char('Open ERP Field name', size=100), |
1111 | 'attribute_set_info':fields.text('Attribute Set Information'), |
1112 | - 'based_on':fields.selection([('product_product', 'Product Product'), ('product_template', 'Product Template')], 'Based On'), |
1113 | + 'based_on':fields.selection([('product.product', 'Product Product'), ('product.template', 'Product Template')], 'Based On'), |
1114 | } |
1115 | |
1116 | _defaults = { |
1117 | - 'based_on': lambda*a: 'product_template', |
1118 | + 'based_on': lambda*a: 'product.template', |
1119 | } |
1120 | |
1121 | + def init(self, cr): |
1122 | + """ Replace product_product by product.product |
1123 | + and product_template by product.template for |
1124 | + consistency with model names""" |
1125 | + cr.execute("UPDATE magerp_product_attributes SET based_on = REPLACE(based_on, '_', '.')") |
1126 | + cr.execute("UPDATE magerp_product_attributes SET based_on = 'product.template' WHERE based_on IS NULL") |
1127 | + |
1128 | #mapping magentofield:(openerpfield,typecast,) |
1129 | #have an entry for each mapped field |
1130 | _no_create_list = [ |
1131 | @@ -372,6 +457,7 @@ |
1132 | 'visibility', |
1133 | ] |
1134 | |
1135 | +<<<<<<< TREE |
1136 | |
1137 | #TODO check if this field have to be in only one way and if yes add this feature |
1138 | _sync_way = { |
1139 | @@ -382,19 +468,25 @@ |
1140 | def _is_attribute_translatable(self, vals): |
1141 | """Tells if field associated to attribute should be translatable or not. |
1142 | For now we are using a default list, later we could say that any attribute |
1143 | +======= |
1144 | + MODEL_SERIALIZED_FIELD = { |
1145 | + 'product.template': 'magerp_tmpl', |
1146 | + 'product.product': 'magerp_variant', |
1147 | + } |
1148 | + |
1149 | + def _is_attribute_translatable(self, attribute): |
1150 | + """Tells if field associated to attribute |
1151 | + should be translatable or not. |
1152 | + For now we are using a default list, |
1153 | + later we could say that any attribute |
1154 | +>>>>>>> MERGE-SOURCE |
1155 | which scope in Magento is 'store' should be translated.""" |
1156 | - if vals['attribute_code'] in self._translatable_default_codes: |
1157 | - return True |
1158 | - else: |
1159 | - return False |
1160 | - |
1161 | - def write(self, cr, uid, ids, vals, context=None): |
1162 | - """Will recreate the mapping attributes, beware if you customized some!""" |
1163 | - if context is None: |
1164 | - context = {} |
1165 | - |
1166 | - if type(ids) == int: |
1167 | + return bool(attribute.attribute_code in self._translatable_default_codes) |
1168 | + |
1169 | + def create_ir_fields(self, cr, uid, ids, update_options=False, context=None): |
1170 | + if isinstance(ids, (int, long)): |
1171 | ids = [ids] |
1172 | +<<<<<<< TREE |
1173 | result = super(magerp_product_attributes, self).write(cr, uid, ids, vals, context) |
1174 | model_ids = self.pool.get('ir.model').search(cr, uid, [('model', 'in', ['product.product', 'product.template'])]) |
1175 | product_model_id = self.pool.get('ir.model').search(cr, uid, [('model', 'in', ['product.product'])])[0] |
1176 | @@ -402,11 +494,26 @@ |
1177 | for id in ids: |
1178 | all_vals = self.read(cr, uid, id, [], context) |
1179 | |
1180 | +======= |
1181 | + |
1182 | + for attribute in self.browse(cr, uid, ids, context=context): |
1183 | + if attribute.attribute_code in self._no_create_list: |
1184 | + continue |
1185 | +>>>>>>> MERGE-SOURCE |
1186 | #Fetch Options |
1187 | +<<<<<<< TREE |
1188 | if 'frontend_input' in all_vals.keys() and all_vals['frontend_input'] in ['select', 'multiselect']: |
1189 | core_imp_conn = self.pool.get('external.referential').external_connection(cr, uid, [referential_id]) |
1190 | options_data = core_imp_conn.call('ol_catalog_product_attribute.options', [all_vals['magento_id']]) |
1191 | +======= |
1192 | + if attribute.frontend_input in ['select', 'multiselect']: |
1193 | + core_imp_conn = self.pool.get('external.referential').connect( |
1194 | + cr, uid, [attribute.referential_id.id]) |
1195 | + options_data = core_imp_conn.call( |
1196 | + 'ol_catalog_product_attribute.options', [attribute.magento_id]) |
1197 | +>>>>>>> MERGE-SOURCE |
1198 | if options_data: |
1199 | +<<<<<<< TREE |
1200 | self.pool.get('magerp.product_attribute_options').data_to_save(cr, uid, options_data, update=True, context={'attribute_id': id, 'referential_id': referential_id}) |
1201 | |
1202 | |
1203 | @@ -415,20 +522,123 @@ |
1204 | field_ids = self.pool.get('ir.model.fields').search(cr, uid, [('name', '=', field_name), ('model_id', 'in', model_ids)]) |
1205 | if field_ids: |
1206 | self._create_mapping(cr, uid, self._type_conversion[all_vals.get('frontend_input', False)], field_ids[0], field_name, referential_id, product_model_id, all_vals, id) |
1207 | +======= |
1208 | + options_obj = self.pool.get('magerp.product_attribute_options') |
1209 | + ctx_opt = dict(context, |
1210 | + attribute_id=attribute.id, |
1211 | + referential_id=attribute.referential_id.id) |
1212 | + options_obj.data_to_save( |
1213 | + cr, uid, options_data, |
1214 | + update=update_options, |
1215 | + context=ctx_opt) |
1216 | + |
1217 | + # Create fields in ir.model.data if it does not already exist |
1218 | + # Create the field accordingly to the "based_on" |
1219 | + # configuration of the attribute (product.product or product.template) |
1220 | + if attribute.attribute_code and attribute.frontend_input: |
1221 | + model_ids = self.pool.get('ir.model').search( |
1222 | + cr, uid, [('model', '=', attribute.based_on)], context=context) |
1223 | + |
1224 | + fields_obj = self.pool.get('ir.model.fields') |
1225 | + # Check if field already exists |
1226 | + field_ids = fields_obj.search( |
1227 | + cr, uid, |
1228 | + [('name', '=', attribute.field_name), |
1229 | + ('model', '=', attribute.based_on)], |
1230 | + context=context) |
1231 | + field_vals = { |
1232 | + 'name': attribute.field_name, |
1233 | + 'model_id': model_ids[0], |
1234 | + 'model': attribute.based_on, |
1235 | + 'field_description': attribute.frontend_label or \ |
1236 | + attribute.attribute_code, |
1237 | + 'ttype': self._type_conversion[attribute.frontend_input], |
1238 | + 'translate': self._is_attribute_translatable(attribute), |
1239 | + } |
1240 | + if not attribute.attribute_code in self._not_store_in_json: |
1241 | + field_vals['serialization_field_id'] = fields_obj.search( |
1242 | + cr, uid, |
1243 | + [('name', '=', self.MODEL_SERIALIZED_FIELD[attribute.based_on]), |
1244 | + ('model', '=', attribute.based_on)], |
1245 | + context=context)[0] |
1246 | + if not field_ids: |
1247 | + #The field is not there create it |
1248 | + #IF char add size |
1249 | + if field_vals['ttype'] == 'char': |
1250 | + field_vals['size'] = 100 |
1251 | + elif field_vals['ttype'] == 'many2one': |
1252 | + field_vals['relation'] = 'magerp.product_attribute_options' |
1253 | + field_vals['domain'] = "[('attribute_id', '=', %s)]" % attribute.id |
1254 | + elif field_vals['ttype'] == 'many2many': |
1255 | + field_vals['relation'] = 'magerp.product_attribute_options' |
1256 | + field_vals['domain'] = "[('attribute_id', '=', %s)]" % attribute.id |
1257 | + field_vals['state'] = 'manual' |
1258 | + |
1259 | + #All field values are computed, now save |
1260 | + self.pool.get('ir.model.fields').create( |
1261 | + cr, uid, field_vals, context=context) |
1262 | + return True |
1263 | + |
1264 | + def update_mapping(self, cr, uid, ids, context=None): |
1265 | + """Create mappings for the attributes |
1266 | + if they have a field name |
1267 | + and a field in ir.model.data""" |
1268 | + if isinstance(ids, (int, long)): |
1269 | + ids = [ids] |
1270 | + |
1271 | + for attribute in self.browse(cr, uid, ids, context=context): |
1272 | + if not attribute.field_name: |
1273 | + continue |
1274 | + field_obj = self.pool.get('ir.model.fields') |
1275 | + field_ids = field_obj.search( |
1276 | + cr, uid, |
1277 | + [('name', '=', attribute.field_name), |
1278 | + ('model', '=', attribute.based_on)], |
1279 | + context=context) |
1280 | + if not field_ids: |
1281 | + continue |
1282 | + field = field_obj.browse( |
1283 | + cr, uid, field_ids[0], context=context) |
1284 | + self._create_mapping( |
1285 | + cr, uid, |
1286 | + attribute, |
1287 | + field, |
1288 | + context=context) |
1289 | + return True |
1290 | + |
1291 | + def write(self, cr, uid, ids, vals, context=None): |
1292 | + """Will recreate the mapping attributes, |
1293 | + beware if you customized some!""" |
1294 | + if context is None: |
1295 | + context = {} |
1296 | + |
1297 | + if isinstance(ids, (int, long)): |
1298 | + ids = [ids] |
1299 | + |
1300 | + result = super(magerp_product_attributes, self).write(cr, uid, ids, vals, context=context) |
1301 | + |
1302 | + self.create_ir_fields( |
1303 | + cr, uid, ids, update_options=True, context=context) |
1304 | + |
1305 | + self.update_mapping(cr, uid, ids, context=context) |
1306 | +>>>>>>> MERGE-SOURCE |
1307 | return result |
1308 | |
1309 | def create(self, cr, uid, vals, context=None): |
1310 | - """Will create product.template new fields accordingly to Magento product custom attributes and also create mappings for them""" |
1311 | + """Will create product.template new fields accordingly |
1312 | + to Magento product custom attributes |
1313 | + and also create mappings for them""" |
1314 | if context is None: |
1315 | context = {} |
1316 | if not vals['attribute_code'] in self._no_create_list: |
1317 | field_name = "x_magerp_" + vals['attribute_code'] |
1318 | field_name = convert_to_ascii(field_name) |
1319 | - vals['field_name']= field_name |
1320 | + vals['field_name'] = field_name |
1321 | if 'attribute_set_info' in vals.keys(): |
1322 | attr_set_info = eval(vals.get('attribute_set_info',{})) |
1323 | for each_key in attr_set_info.keys(): |
1324 | vals['group_id'] = attr_set_info[each_key].get('group_id', False) |
1325 | +<<<<<<< TREE |
1326 | |
1327 | crid = super(magerp_product_attributes, self).create(cr, uid, vals, context) |
1328 | if not vals['attribute_code'] in self._no_create_list: |
1329 | @@ -494,7 +704,31 @@ |
1330 | #If the field have restriction on domain |
1331 | #Maybe we can give the posibility to map directly m2m and m2o field_description |
1332 | #by filtrering directly with the domain and the string value |
1333 | +======= |
1334 | + |
1335 | + # By default some fields should be based on product variants |
1336 | + # instead of templates. |
1337 | + if vals['attribute_code'] in self._variant_fields: |
1338 | + vals['based_on'] = 'product.product' |
1339 | + |
1340 | + attribute_id = super(magerp_product_attributes, self).create( |
1341 | + cr, uid, vals, context=context) |
1342 | + |
1343 | + if attribute_id: |
1344 | + self.create_ir_fields( |
1345 | + cr, uid, |
1346 | + attribute_id, |
1347 | + update_options=False, |
1348 | + context=context) |
1349 | + self.update_mapping(cr, uid, attribute_id, context=context) |
1350 | + return attribute_id |
1351 | + |
1352 | + def _default_mapping(self, cr, uid, attribute, field, context=None): |
1353 | + in_function = out_function = False |
1354 | + ttype = field.ttype |
1355 | +>>>>>>> MERGE-SOURCE |
1356 | if ttype in ['char', 'text', 'date', 'float', 'weee', 'boolean']: |
1357 | +<<<<<<< TREE |
1358 | mapping_line['evaluation_type'] = 'direct' |
1359 | if ttype == 'float': |
1360 | mapping_line['external_type'] = 'float' |
1361 | @@ -503,7 +737,12 @@ |
1362 | else: |
1363 | mapping_line['external_type'] = 'unicode' |
1364 | |
1365 | +======= |
1366 | + in_function = "result = [('%s', ifield)]" % (field.name,) |
1367 | + out_function = "result = [('%s', record['%s'])]" % (attribute.attribute_code, field.name) |
1368 | +>>>>>>> MERGE-SOURCE |
1369 | elif ttype in ['many2one']: |
1370 | +<<<<<<< TREE |
1371 | mapping_line['evaluation_type'] = 'function' |
1372 | mapping_line['in_function'] = \ |
1373 | ("if '%(attribute_code)s' in resource:\n" |
1374 | @@ -518,7 +757,20 @@ |
1375 | " option = self.pool.get('magerp.product_attribute_options').browse(cr, uid, resource['%(field_name)s'][0])\n" |
1376 | " if option:\n" |
1377 | " result = [('%(attribute_code)s', option.value)]") % ({'field_name': field_name, 'attribute_code': vals['attribute_code']}) |
1378 | +======= |
1379 | + in_function = ("if ifield:\n" |
1380 | + " option_id = self.pool.get('magerp.product_attribute_options').search(cr, uid, [('attribute_id','=',%(attribute_id)s),('value','=',ifield)])\n" |
1381 | + " if option_id:\n" |
1382 | + " result = [('%(field_name)s', option_id[0])]") % ({'attribute_id': attribute.id, 'field_name': field.name}) |
1383 | + # we browse on record['%(field_name)s'][0] because record[field_name] is in the form (id, name) |
1384 | + out_function = ("result = [('%(attribute_code)s', False)]\n" |
1385 | + "if record.get('%(field_name)s'):\n" |
1386 | + " option = self.pool.get('magerp.product_attribute_options').browse(cr, uid, record['%(field_name)s'][0])\n" |
1387 | + " if option:\n" |
1388 | + " result = [('%(attribute_code)s', option.value)]") % ({'field_name': field.name, 'attribute_code': attribute.attribute_code}) |
1389 | +>>>>>>> MERGE-SOURCE |
1390 | elif ttype in ['many2many']: |
1391 | +<<<<<<< TREE |
1392 | mapping_line['evaluation_type'] = 'function' |
1393 | mapping_line['in_function'] = ("option_ids = []\n" |
1394 | "opt_obj = self.pool.get('magerp.product_attribute_options')\n" |
1395 | @@ -530,7 +782,20 @@ |
1396 | " options = self.pool.get('magerp.product_attribute_options').browse(cr, uid, resource['%(field_name)s'])\n" |
1397 | " result = [('%(attribute_code)s', [option.value for option in options])]") % \ |
1398 | ({'field_name': field_name, 'attribute_code': vals['attribute_code']}) |
1399 | +======= |
1400 | + in_function = ("option_ids = []\n" |
1401 | + "opt_obj = self.pool.get('magerp.product_attribute_options')\n" |
1402 | + "for ext_option_id in ifield:\n" |
1403 | + " option_ids.extend(opt_obj.search(cr, uid, [('attribute_id','=',%(attribute_id)s), ('value','=',ext_option_id)]))\n" |
1404 | + "result = [('%(field_name)s', [(6, 0, option_ids)])]") % ({'attribute_id': attribute.id, 'field_name': field.name}) |
1405 | + out_function = ("result=[('%(attribute_code)s', [])]\n" |
1406 | + "if record.get('%(field_name)s'):\n" |
1407 | + " options = self.pool.get('magerp.product_attribute_options').browse(cr, uid, record['%(field_name)s'])\n" |
1408 | + " result = [('%(attribute_code)s', [option.value for option in options])]") % \ |
1409 | + ({'field_name': field.name, 'attribute_code': attribute.attribute_code}) |
1410 | +>>>>>>> MERGE-SOURCE |
1411 | elif ttype in ['binary']: |
1412 | +<<<<<<< TREE |
1413 | warning_text = "Binary mapping is actually not supported (attribute: %s)" % (vals['attribute_code'],) |
1414 | _logger.warn(warning_text) |
1415 | warning_msg = ("import logging\n" |
1416 | @@ -538,11 +803,21 @@ |
1417 | "logger.warn('%s')") % (warning_text,) |
1418 | mapping_line['in_function'] = mapping_line['out_function'] = warning_msg |
1419 | return mapping_line |
1420 | +======= |
1421 | + logger = logging.getLogger('ext synchro mapping') |
1422 | + logger.warn("Binary mapping is actually not supported (attribute: %s)", attribute.attribute_code) |
1423 | + warning_msg = ("import logging\n" |
1424 | + "logger = logging.getLogger('ext synchro mapping')\n" |
1425 | + "logger.warn('Binary mapping is actually not supported (attribute: %%s)', %s)") % (attribute.attribute_code) |
1426 | + in_function = out_function = warning_msg |
1427 | + return in_function, out_function |
1428 | +>>>>>>> MERGE-SOURCE |
1429 | |
1430 | - def _create_mapping(self, cr, uid, ttype, field_id, field_name, referential_id, model_id, vals, attribute_id): |
1431 | - """Search & create mapping entries""" |
1432 | - if vals['attribute_code'] in self._no_create_list: |
1433 | + def _create_mapping(self, cr, uid, attribute, field, context=None): |
1434 | + """Search and create mapping entries""" |
1435 | + if attribute.attribute_code in self._no_create_list: |
1436 | return False |
1437 | +<<<<<<< TREE |
1438 | mapping_id = self.pool.get('external.mapping').search(cr, uid, [('referential_id', '=', referential_id), ('model_id', '=', model_id)]) |
1439 | if mapping_id: |
1440 | existing_line = self.pool.get('external.mapping.line').search(cr, uid, [('external_field', '=', vals['attribute_code']), ('mapping_id', '=', mapping_id[0])]) |
1441 | @@ -555,6 +830,38 @@ |
1442 | 'field_id': field_id, } |
1443 | mapping_line = self._default_mapping(cr, uid, ttype, field_name, vals, attribute_id, model_id, mapping_line, referential_id) |
1444 | self.pool.get('external.mapping.line').create(cr, uid, mapping_line) |
1445 | +======= |
1446 | + # the mapping should always be created on the product.product |
1447 | + # model, and not on product.template |
1448 | + mapping_ids = self.pool.get('external.mapping').search( |
1449 | + cr, uid, |
1450 | + [('referential_id', '=', attribute.referential_id.id), |
1451 | + ('model_id.model', '=', 'product.product')], |
1452 | + context=context) |
1453 | + if not mapping_ids: |
1454 | + raise osv.except_osv( |
1455 | + _('Error'), |
1456 | + _("No Object Mapping \"Product\"" |
1457 | + "for \"%s\"." % attribute.referential_id.name)) |
1458 | + existing_line = self.pool.get('external.mapping.line').search( |
1459 | + cr, uid, |
1460 | + [('external_field', '=', attribute.attribute_code), |
1461 | + ('mapping_id', '=', mapping_ids[0])], |
1462 | + context=context) |
1463 | + if not existing_line: |
1464 | + mapping_line = { |
1465 | + 'external_field': attribute.attribute_code, |
1466 | + 'mapping_id': mapping_ids[0], |
1467 | + 'type': 'in_out', |
1468 | + 'external_type': self._type_casts[attribute.frontend_input], |
1469 | + 'field_id': field.id, |
1470 | + 'evaluation_type': 'function', |
1471 | + } |
1472 | + mapping_line['in_function'], mapping_line['out_function'] = \ |
1473 | + self._default_mapping(cr, uid, attribute, field, context=context) |
1474 | + self.pool.get('external.mapping.line').create( |
1475 | + cr, uid, mapping_line, context=context) |
1476 | +>>>>>>> MERGE-SOURCE |
1477 | return True |
1478 | |
1479 | magerp_product_attributes() |
1480 | @@ -683,6 +990,11 @@ |
1481 | cr.execute(query) |
1482 | return True |
1483 | |
1484 | +<<<<<<< TREE |
1485 | +======= |
1486 | + return True |
1487 | + |
1488 | +>>>>>>> MERGE-SOURCE |
1489 | magerp_product_attribute_set() |
1490 | |
1491 | class magerp_product_attribute_groups(magerp_osv.magerp_osv): |
1492 | @@ -695,11 +1007,15 @@ |
1493 | for attribute_group in self.browse(cr, uid, ids, context): |
1494 | res[attribute_group.id] = self.pool.get('magerp.product_attribute_set').extid_to_oeid(cr, uid, attribute_group.attribute_set_id, attribute_group.referential_id.id) |
1495 | return res |
1496 | +<<<<<<< TREE |
1497 | |
1498 | def _get_filter(self, cr, uid, external_session, step, previous_filter=None, context=None): |
1499 | attrset_ids = self.pool.get('magerp.product_attribute_set').get_all_extid_from_referential(cr, uid, external_session.referential_id.id, context=context) |
1500 | return {'attribute_set_id':{'in':attrset_ids}} |
1501 | |
1502 | +======= |
1503 | + |
1504 | +>>>>>>> MERGE-SOURCE |
1505 | _columns = { |
1506 | 'attribute_set_id':fields.integer('Attribute Set ID'), |
1507 | 'attribute_set':fields.function(_get_set, type="many2one", relation="magerp.product_attribute_set", method=True, string="Attribute Set"), |
1508 | @@ -1133,12 +1449,25 @@ |
1509 | #TODO base the import on the mapping and the function ext_import |
1510 | def import_product_image(self, cr, uid, id, referential_id, conn, ext_id=None, context=None): |
1511 | image_obj = self.pool.get('product.images') |
1512 | +<<<<<<< TREE |
1513 | +======= |
1514 | + logger = logging.getLogger('ext synchro') |
1515 | +>>>>>>> MERGE-SOURCE |
1516 | if not ext_id: |
1517 | +<<<<<<< TREE |
1518 | ext_id = self.get_extid(cr, uid, id, referential_id, context=context) |
1519 | # TODO everythere will should pass the params 'id' for magento api in order to force |
1520 | +======= |
1521 | + ext_id = self.oeid_to_extid(cr, uid, id, referential_id, context=None) |
1522 | + # TODO everythere will should pass the params 'id' for magento api in order to force |
1523 | +>>>>>>> MERGE-SOURCE |
1524 | # to use the id as external key instead of mixed id/sku |
1525 | img_list = conn.call('catalog_product_attribute_media.list', [ext_id, False, 'id']) |
1526 | +<<<<<<< TREE |
1527 | _logger.info("Magento image for product ext_id %s: %s", ext_id, img_list) |
1528 | +======= |
1529 | + logger.info("Magento image for product ext_id %s: %s", ext_id, img_list) |
1530 | +>>>>>>> MERGE-SOURCE |
1531 | images_name = [] |
1532 | for image in img_list: |
1533 | img=False |
1534 | @@ -1148,13 +1477,21 @@ |
1535 | data = f.read() |
1536 | f.close() |
1537 | if "DOCTYPE html PUBLIC" in data: |
1538 | +<<<<<<< TREE |
1539 | _logger.warn("failed to open the image %s from Magento", image['url']) |
1540 | +======= |
1541 | + logger.warn("Failed to open the image %s from Magento", image['url']) |
1542 | +>>>>>>> MERGE-SOURCE |
1543 | continue |
1544 | else: |
1545 | img = base64.encodestring(data) |
1546 | except Exception, e: |
1547 | #TODO raise correctly the error |
1548 | +<<<<<<< TREE |
1549 | _logger.error("failed to open the image %s from Magento, error : %s", image['url'], e, exc_info=True) |
1550 | +======= |
1551 | + logger.error("Failed to open the image %s from Magento, error : %s", image['url'], e, exc_info=True) |
1552 | +>>>>>>> MERGE-SOURCE |
1553 | continue |
1554 | mag_filename, extention = os.path.splitext(os.path.basename(image['file'])) |
1555 | data = {'name': image['label'] and not image['label'] in images_name and image['label'] or mag_filename, |
1556 | @@ -1180,6 +1517,7 @@ |
1557 | new_image_id = image_obj.create(cr, uid, data, context=context) |
1558 | image_obj.create_external_id_vals(cr, uid, new_image_id, image['file'], referential_id, context=context) |
1559 | return True |
1560 | +<<<<<<< TREE |
1561 | |
1562 | def get_field_to_export(self, cr, uid, ids, mapping, mapping_id, context=None): |
1563 | res = super(product_product, self).get_field_to_export(cr, uid, ids, mapping, mapping_id, context=context) |
1564 | @@ -1215,6 +1553,21 @@ |
1565 | context=context |
1566 | )) |
1567 | return resources |
1568 | +======= |
1569 | + |
1570 | + def extid_to_existing_oeid(self, cr, uid, id, external_referential_id, context=None): |
1571 | + """Returns the OpenERP id of a resource by its external id. |
1572 | + Returns False if the resource does not exist.""" |
1573 | + if not context: |
1574 | + context={} |
1575 | + res = super(product_mag_osv, self).extid_to_existing_oeid(cr, uid, id, external_referential_id, context=context) |
1576 | + # TODO : check if this can be replaced by _existing_oeid_for_extid_import (see example in res.partner) |
1577 | + # thus when importing a product which do not already exists in OpenERP, ext_import will create the binding and update it directly |
1578 | + if not res and context.get('magento_sku', False): |
1579 | + product_id = self.search(cr, uid, [('magento_sku', '=', context['magento_sku'])], context=context) |
1580 | + return product_id and product_id[0] or False |
1581 | + return res |
1582 | +>>>>>>> MERGE-SOURCE |
1583 | |
1584 | def _product_type_get(self, cr, uid, context=None): |
1585 | ids = self.pool.get('magerp.product_product_type').search(cr, uid, [], order='id') |
1586 | @@ -1344,6 +1697,266 @@ |
1587 | raise osv.except_osv(_('Warning!'), _('This product is related to Magento. It can not be deleted!\nYou can change it Magento status to "Disabled" and uncheck the active box to hide it from OpenERP.')) |
1588 | else: |
1589 | return super(product_product, self).unlink(cr, uid, ids, context) |
1590 | +<<<<<<< TREE |
1591 | +======= |
1592 | + |
1593 | + #TODO move part of this to declarative mapping CSV template |
1594 | + def extdata_from_oevals(self, cr, uid, external_referential_id, data_record, mapping_lines, defaults, context=None): |
1595 | + product_data = super(product_product, self).extdata_from_oevals(cr, uid, external_referential_id, data_record, mapping_lines, defaults, context) #Aapply custom/attributes mappings |
1596 | + if context is None: context = {} |
1597 | + product = self.browse(cr, uid, data_record['id'], context) |
1598 | + shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id'], context) |
1599 | + |
1600 | + if not product_data.get('price', False): |
1601 | + pl_default_id = shop.pricelist_id and shop.pricelist_id.id or self.pool.get('product.pricelist').search(cr, uid, [('type', '=', 'sale')]) |
1602 | + if isinstance(pl_default_id, int): |
1603 | + pl_default_id = [pl_default_id] |
1604 | + product_data.update({'price': self.pool.get('product.pricelist').price_get(cr, uid, pl_default_id, product.id, 1.0)[pl_default_id[0]]}) |
1605 | + |
1606 | + if not product_data.get('tax_class_id', False): |
1607 | + product_data.update({'tax_class_id': 2}) #FIXME hugly! |
1608 | + |
1609 | + if not product_data.get('status', False): |
1610 | + product_data.update({'status': product.active and 1 or 0}) |
1611 | + |
1612 | + if not product_data.get('description', False): |
1613 | + product_data.update({'description': product.description or _("description")}) |
1614 | + if not product_data.get('short_description', False): |
1615 | + product_data.update({'short_description': product.description_sale or _("short description")}) |
1616 | + if not product_data.get('meta_title', False): |
1617 | + product_data.update({'meta_title': product.name}) |
1618 | + if not product_data.get('meta_keyword', False): |
1619 | + product_data.update({'meta_keyword': product.name}) |
1620 | + if not product_data.get('meta_description', False): |
1621 | + product_data.update({'meta_description': product.description_sale and product.description_sale[:255]}) |
1622 | + |
1623 | + return product_data |
1624 | + |
1625 | + def oevals_from_extdata(self, cr, uid, external_referential_id, data_record, mapping_lines, key_for_external_id=None, parent_data=None, previous_lines=None, defaults=None, context=None): |
1626 | + res = super(product_product, self).oevals_from_extdata(cr, uid, external_referential_id, data_record, mapping_lines, key_for_external_id=key_for_external_id, parent_data=parent_data, previous_lines=previous_lines, defaults=defaults, context=context) |
1627 | + # assign a default product type (Procurement, not the magento's one) |
1628 | + if not res.get('type'): |
1629 | + magerp_type_obj = self.pool.get('magerp.product_product_type') |
1630 | + magerp_type_ids = magerp_type_obj.search(cr, uid, [('product_type', '=', data_record['type_id'])], context=context) |
1631 | + if magerp_type_ids: |
1632 | + res['type'] = magerp_type_obj.read(cr, uid, magerp_type_ids[0], ['default_type'], context=context)['default_type'] |
1633 | + return res |
1634 | + |
1635 | + def product_to_sku(self, cr, uid, product): |
1636 | + if product.magento_sku: |
1637 | + sku = product.magento_sku |
1638 | + else: |
1639 | + code = product.code or 'mag' |
1640 | + same_codes = self.search(cr, uid, [('magento_sku', '=', code)]) |
1641 | + if same_codes and len(same_codes) > 0: |
1642 | + sku = code + "_" + str(product.id) |
1643 | + else: |
1644 | + sku = code |
1645 | + return sku |
1646 | + |
1647 | + def _ext_update_and_rebind(self, cr, uid, data, conn, oe_id, sku=None, context=None): |
1648 | + if sku is None: |
1649 | + product = self.browse(cr, uid, oe_id, context=context) |
1650 | + sku = product.sku |
1651 | + ext_data = conn.call('catalog_product.info', [sku, False, 'sku']) |
1652 | + ext_id = ext_data['product_id'] |
1653 | + conn.call('ol_catalog_product.update', [ext_id, data, False, 'id']) |
1654 | + return ext_id |
1655 | + |
1656 | + def ext_create(self, cr, uid, data, conn, method, oe_id, context=None): |
1657 | + if context is None: context = {} |
1658 | + product = self.browse(cr, uid, oe_id, context=context) |
1659 | + sku = self.product_to_sku(cr, uid, product) |
1660 | + shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id']) |
1661 | + attr_set_id = product.set and self.pool.get('magerp.product_attribute_set').oeid_to_extid(cr, uid, product.set.id, shop.referential_id.id) or context.get('default_set_id', 1) |
1662 | + |
1663 | + product_type = self.read(cr, uid, oe_id, ['product_type'])['product_type'] or 'simple' |
1664 | + |
1665 | + try: |
1666 | + ext_id = super(magerp_osv.magerp_osv, self).ext_create( |
1667 | + cr, uid, [product_type, attr_set_id, sku, data], conn, method, oe_id, context) |
1668 | + except xmlrpclib.Fault, e: |
1669 | + # Magento raise error 1 when we try to create |
1670 | + # a product with a SKU which already exists |
1671 | + if e.faultCode == 1: |
1672 | + ext_id = self._ext_update_and_rebind( |
1673 | + cr, uid, data, conn, oe_id, sku=sku, context=context) |
1674 | + else: |
1675 | + raise |
1676 | + self.write(cr, uid, oe_id, {'magento_sku': sku}) |
1677 | + return ext_id |
1678 | + |
1679 | + def action_before_exporting_grouped_product(self, cr, uid, id, external_referential_ids=None, defaults=None, context=None): |
1680 | + logger = logging.getLogger('ext synchro') |
1681 | + if context.get('mrp_is_installed', False): |
1682 | + bom_ids = self.read(cr, uid, id, ['bom_ids'])['bom_ids'] |
1683 | + if len(bom_ids): # it has or is part of a BoM |
1684 | + cr.execute("SELECT product_id, product_qty FROM mrp_bom WHERE bom_id = %s", (bom_ids[0],)) #FIXME What if there is more than a materials list? |
1685 | + results = cr.dictfetchall() |
1686 | + child_ids = [] |
1687 | + quantities = {} |
1688 | + for row in results: |
1689 | + child_ids.append(row['product_id']) |
1690 | + quantities.update({row['product_id']: row['product_qty']}) |
1691 | + if child_ids: #it is an assembly and it contains the products child_ids: |
1692 | + self.ext_export(cr, uid, child_ids, external_referential_ids, defaults, context) #so we export them |
1693 | + else: |
1694 | + return False |
1695 | + else: |
1696 | + logger.error("OpenERP 'grouped' products will export to Magento as 'grouped products' only if they have a BOM and if the 'mrp' BOM module is installed") |
1697 | + return quantities, child_ids |
1698 | + |
1699 | + def action_before_exporting(self, cr, uid, id, product_type, external_referential_ids=None, defaults=None, context=None): |
1700 | + '''Hook to allow your external module to execute some code before exporting a product''' |
1701 | + return True |
1702 | + |
1703 | + #todo move this code to a generic module |
1704 | + def get_last_update_date(self, cr, uid, product_read, context=None): |
1705 | + """if a product have a depends on other object like bom for grouped product, or other product for configurable |
1706 | + the date of last update should be based on the last update of the dependence object""" |
1707 | + conn = context.get('conn_obj', False) |
1708 | + last_updated_date = product_read['write_date'] or product_read['create_date'] or False |
1709 | + if product_read['product_type'] == 'grouped': |
1710 | + if context.get('mrp_is_installed', False): |
1711 | + #TODO improve this part of code as the group product can be based on nan_product_pack |
1712 | + cr.execute("select id, write_date, create_date from mrp_bom where product_id = %s", (product_read['id'],)) |
1713 | + read_bom = cr.dictfetchall() |
1714 | + for bom in read_bom: |
1715 | + last_updated_bom_date = bom['write_date'] or bom['create_date'] or False |
1716 | + if last_updated_bom_date > last_updated_date: |
1717 | + last_updated_date=last_updated_bom_date |
1718 | + else: |
1719 | + conn.logger.error("OpenERP 'grouped' products will export to Magento as 'grouped products' only if they have a BOM and if the 'mrp' BOM module is installed") |
1720 | + return last_updated_date |
1721 | + |
1722 | + |
1723 | + def get_ordered_ids(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None): |
1724 | + #TODO pass the shop better than the referentials |
1725 | + dates_2_ids = [] |
1726 | + ids_2_dates = {} |
1727 | + shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id']) |
1728 | + if shop.last_products_export_date: |
1729 | + last_exported_date = shop.last_products_export_date |
1730 | + else: |
1731 | + last_exported_date = False |
1732 | + #strangely seems that on inherits structure, write_date/create_date are False for children |
1733 | + #TODO check previous comment and check the write date on product template also for variant of product |
1734 | + cr.execute("select id, write_date, create_date, product_type from product_product where id in %s", (tuple(ids),)) |
1735 | + read = cr.dictfetchall() |
1736 | + ids = [] |
1737 | + context['force']=True |
1738 | + |
1739 | + for product_read in read: |
1740 | + last_updated_date = self.get_last_update_date(cr, uid, product_read, context=context) |
1741 | + if last_exported_date and last_updated_date < last_exported_date: |
1742 | + continue |
1743 | + dates_2_ids += [(last_updated_date, product_read['id'])] |
1744 | + ids_2_dates[product_read['id']] = last_updated_date |
1745 | + |
1746 | + dates_2_ids.sort() |
1747 | + ids = [x[1] for x in dates_2_ids] |
1748 | + |
1749 | + return ids, ids_2_dates |
1750 | + |
1751 | + def _ext_export_one(self, cr, uid, record_data, referential_id, defaults=None, context=None): |
1752 | + res = super(product_product, self)._ext_export_one( |
1753 | + cr, uid, record_data, referential_id, defaults=defaults, context=context) |
1754 | + |
1755 | + self.ext_assign_links( |
1756 | + cr, uid, |
1757 | + record_data['id'], |
1758 | + external_referential_ids=[referential_id], |
1759 | + defaults=defaults, |
1760 | + context=context) |
1761 | + |
1762 | + return res |
1763 | + |
1764 | + def ext_export(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None): |
1765 | + #check if mrp is installed |
1766 | + cr.execute('select * from ir_module_module where name=%s and state=%s', ('mrp','installed')) |
1767 | + data_record = cr.fetchone() |
1768 | + if data_record and 'mrp' in data_record: |
1769 | + context['mrp_is_installed']=True |
1770 | + |
1771 | + if context is None: |
1772 | + context = {} |
1773 | + |
1774 | + if defaults is None: |
1775 | + defaults = {} |
1776 | + #TODO Is external_referential_ids is still used? |
1777 | + if external_referential_ids is None: |
1778 | + external_referential_ids = [] |
1779 | + |
1780 | + result = {'create_ids':[], 'write_ids':[]} |
1781 | + shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id']) |
1782 | + context['external_referential_id'] = shop.referential_id.id |
1783 | + #TODO It will be better if this check was done before |
1784 | + #restrict export to only exportable products |
1785 | + ids = self.search(cr, uid, [('id', 'in', ids), ('magento_exportable', '=', True)]) |
1786 | + if not ids: |
1787 | + return result |
1788 | + |
1789 | + if not context.get('force_export', False): |
1790 | + ids, ids_2_dates = self.get_ordered_ids(cr, uid, ids, external_referential_ids, defaults, context) |
1791 | + |
1792 | + #set the default_set_id in context and avoid extra request for each product upload |
1793 | + |
1794 | + conn = context.get('conn_obj', False) |
1795 | + attr_sets = conn.call('product_attribute_set.list') |
1796 | + default_set_id = 1 |
1797 | + for attr_set in attr_sets: |
1798 | + if attr_set['name'] == 'Default': |
1799 | + default_set_id = attr_set['set_id'] |
1800 | + break |
1801 | + context['default_set_id'] = default_set_id |
1802 | + |
1803 | + context_dic = [context.copy()] |
1804 | + context_dic[0]['export_url'] = True # for the magento version 1.3.2.4, only one url is autorized by product, so we only export with the MAPPING TEMPLATE the url of the default language |
1805 | + context_dic[0]['lang'] = shop.referential_id.default_lang_id.code |
1806 | + |
1807 | + for storeview in shop.storeview_ids: |
1808 | + if storeview.lang_id and storeview.lang_id.code != shop.referential_id.default_lang_id.code: |
1809 | + context_dic += [context.copy()] |
1810 | + context_dic[len(context_dic)-1].update({'storeview_code': storeview.code, 'lang': storeview.lang_id.code}) |
1811 | + |
1812 | + last_export_date = None |
1813 | + try: |
1814 | + for id in ids: |
1815 | + child_ids = [] |
1816 | + product_type = self.read(cr, uid, id, ['product_type'])['product_type'] |
1817 | + if product_type == 'grouped': # lookup for Magento "grouped product" |
1818 | + quantities, child_ids = self.action_before_exporting_grouped_product(cr, uid, id, external_referential_ids, defaults, context) |
1819 | + |
1820 | + self.action_before_exporting(cr, uid, id, product_type, external_referential_ids, defaults, context=context) |
1821 | + |
1822 | + for context_storeview in context_dic: |
1823 | + temp_result = super(magerp_osv.magerp_osv, self).ext_export(cr, uid, [id], external_referential_ids, defaults, context_storeview) |
1824 | + #TODO maybe refactor this part, did we need to assign and make the link for every store? |
1825 | + if child_ids: |
1826 | + self.ext_product_assign(cr, uid, 'grouped', id, child_ids, quantities=quantities, external_referential_ids=external_referential_ids, defaults=defaults, context=context_storeview) |
1827 | + if not context.get('force_export'): |
1828 | + last_export_date = ids_2_dates[id] |
1829 | + |
1830 | + result['create_ids'] += temp_result['create_ids'] |
1831 | + result['write_ids'] += temp_result['write_ids'] |
1832 | + finally: |
1833 | + if last_export_date is not None: |
1834 | + self.pool.get('sale.shop').write( |
1835 | + cr, uid, context['shop_id'], {'last_products_export_date': last_export_date}, context=context) |
1836 | + return result |
1837 | + |
1838 | + def try_ext_update(self, cr, uid, data, conn, method, oe_id, external_id, ir_model_data_id, create_method, context=None): |
1839 | + if context is None: context = {} |
1840 | + if context.get('storeview_code', False): |
1841 | + return conn.call(method, [external_id, data, context.get('storeview_code', False)]) |
1842 | + else: |
1843 | + return conn.call(method, [external_id, data]) |
1844 | + |
1845 | + def ext_update(self, cr, uid, data, conn, method, oe_id, external_id, ir_model_data_id, create_method, context=None): |
1846 | + product = self.browse(cr, uid, oe_id) |
1847 | + sku = self.product_to_sku(cr, uid, product) |
1848 | + return super(magerp_osv.magerp_osv, self).ext_update(cr, uid, data, conn, method, oe_id, sku, ir_model_data_id, create_method, context) |
1849 | +>>>>>>> MERGE-SOURCE |
1850 | |
1851 | def _prepare_inventory_magento_vals(self, cr, uid, product, stock, shop, |
1852 | context=None): |
1853 | @@ -1380,6 +1993,10 @@ |
1854 | #TODO get also the list of product which the option mag_manage_stock have changed |
1855 | #This can be base on the group_fields that can try tle last write date of a group of fields |
1856 | if context is None: context = {} |
1857 | +<<<<<<< TREE |
1858 | +======= |
1859 | + logger = logging.getLogger('ext synchro') |
1860 | +>>>>>>> MERGE-SOURCE |
1861 | |
1862 | shop = external_session.sync_from_object |
1863 | |
1864 | @@ -1400,6 +2017,7 @@ |
1865 | cr, uid, stock_product_ids, context=location_ctx) |
1866 | |
1867 | for product in products: |
1868 | +<<<<<<< TREE |
1869 | self._export_inventory(cr, uid, external_session, product, stock, context=location_ctx) |
1870 | return True |
1871 | |
1872 | @@ -1424,6 +2042,30 @@ |
1873 | # ol_catalog_product.update |
1874 | def ext_update_link_data(self, cr, uid, external_session, resources, mapping=None, mapping_id=None, context=None): |
1875 | for resource_id, resource in resources.items(): |
1876 | +======= |
1877 | + mag_product_id = self.oeid_to_extid( |
1878 | + cr, uid, product.id, referential.id, context=context) |
1879 | + if not mag_product_id: |
1880 | + continue # skip products which are not exported |
1881 | + inventory_vals = self._prepare_inventory_magento_vals( |
1882 | + cr, uid, product, stock, shop, context=location_ctx) |
1883 | + |
1884 | + connection.call('product_stock.update', |
1885 | + [mag_product_id, inventory_vals]) |
1886 | + |
1887 | + logger.info( |
1888 | + "Successfully updated stock level at %s for product with SKU %s", |
1889 | + inventory_vals.get('qty', 'N/A'), |
1890 | + product.magento_sku |
1891 | + ) |
1892 | + return True |
1893 | + |
1894 | + def ext_assign_links(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None): |
1895 | + """ Assign links of type up-sell, cross-sell, related """ |
1896 | + if isinstance(ids, (int, long)): |
1897 | + ids = [ids] |
1898 | + for product in self.browse(cr, uid, ids, context): |
1899 | +>>>>>>> MERGE-SOURCE |
1900 | for type_selection in self.pool.get('product.link').get_link_type_selection(cr, uid, context): |
1901 | link_type = type_selection[0] |
1902 | position = {} |
1903 | @@ -1442,6 +2084,7 @@ |
1904 | context = context or {} |
1905 | position = position or {} |
1906 | quantities = quantities or {} |
1907 | +<<<<<<< TREE |
1908 | |
1909 | |
1910 | #Patch for magento api prototype |
1911 | @@ -1493,6 +2136,83 @@ |
1912 | 'qty': quantities.get(c_ext_id, 1)}]) |
1913 | external_session.logger.info(("Successfully updated assignment of type %s of" |
1914 | "product %s to product %s") %(link_type, ext_parent_id, c_ext_id)) |
1915 | +======= |
1916 | + external_referential_ids = external_referential_ids or [] |
1917 | + logger = logging.getLogger('ext assign') |
1918 | + conn = context.get('conn_obj', False) |
1919 | + |
1920 | + for ref_id in external_referential_ids: |
1921 | + # ensure that the product to link is exported before assigning it, |
1922 | + # export it if necessary |
1923 | + ids_to_export = [] |
1924 | + for child_id in child_ids: |
1925 | + if not self.oeid_to_extid(cr, uid, child_id, ref_id, context=context): |
1926 | + ids_to_export.append(child_id) |
1927 | + export_ctx = context.copy() |
1928 | + export_ctx['force_export'] = True |
1929 | + self.ext_export( |
1930 | + cr, uid, ids_to_export, [ref_id], defaults=defaults, context=export_ctx) |
1931 | + |
1932 | + ext_id = self.oeid_to_extid( |
1933 | + cr, uid, parent_id, ref_id, context=context) |
1934 | + if not ext_id: |
1935 | + continue |
1936 | + |
1937 | + # get the sku of the products already assigned |
1938 | + magento_args = [type, ext_id] |
1939 | + |
1940 | + # magento existing children ids |
1941 | + child_list = conn.call('product_link.list', magento_args) |
1942 | + old_child_ext_ids = [x['product_id'] for x in child_list] |
1943 | + |
1944 | + ext_id_to_remove = [] |
1945 | + ext_id_to_assign = [] |
1946 | + ext_id_to_update = [] |
1947 | + |
1948 | + # list of children setup on openerp |
1949 | + new_child_ext_ids = dict([(self.oeid_to_extid(cr, uid, child_id, ref_id, context=context), |
1950 | + child_id) |
1951 | + for child_id in child_ids]) |
1952 | + |
1953 | + skus = dict([(p.id, p.magento_sku) |
1954 | + for p in |
1955 | + self.browse( |
1956 | + cr, uid, child_ids + [parent_id], context=context)]) |
1957 | + |
1958 | + # compute the diff between openerp and magento |
1959 | + for c_ext_id in old_child_ext_ids: |
1960 | + if c_ext_id not in new_child_ext_ids: |
1961 | + ext_id_to_remove.append(c_ext_id) |
1962 | + for c_ext_id in new_child_ext_ids.keys(): |
1963 | + if c_ext_id in old_child_ext_ids: |
1964 | + ext_id_to_update.append(c_ext_id) |
1965 | + else: |
1966 | + ext_id_to_assign.append(c_ext_id) |
1967 | + |
1968 | + # calls to magento to delete, create or update the links |
1969 | + for c_ext_id in ext_id_to_remove: |
1970 | + # remove the product links that are no more setup on openerp |
1971 | + conn.call('product_link.remove', magento_args + [c_ext_id]) |
1972 | + logger.info("Successfully removed assignment of type %s for product %s to product %s", type, skus[parent_id], c_ext_id) |
1973 | + for child_ext_id in ext_id_to_assign: |
1974 | + # assign new product links |
1975 | + product_id = new_child_ext_ids[child_ext_id] |
1976 | + conn.call('product_link.assign', |
1977 | + magento_args + |
1978 | + [child_ext_id, |
1979 | + {'position': position.get(product_id, 0), |
1980 | + 'qty': quantities.get(product_id, 1)}]) |
1981 | + logger.info("Successfully assigned product %s to product %s with type %s", skus[parent_id], skus[product_id], type) |
1982 | + for child_ext_id in ext_id_to_update: |
1983 | + # update products links already assigned |
1984 | + product_id = new_child_ext_ids[child_ext_id] |
1985 | + conn.call('product_link.update', |
1986 | + magento_args + |
1987 | + [child_ext_id, |
1988 | + {'position': position.get(product_id, 0), |
1989 | + 'qty': quantities.get(product_id, 1)}]) |
1990 | + logger.info("Successfully updated assignment of type %s of product %s to product %s", type, skus[parent_id], skus[product_id]) |
1991 | +>>>>>>> MERGE-SOURCE |
1992 | return True |
1993 | |
1994 | #TODO move this code (get exportable image) and also some code in product_image.py and sale.py in base_sale_multichannel or in a new module in order to be more generic |
1995 | @@ -1508,7 +2228,11 @@ |
1996 | |
1997 | def _mag_import_product_links_type(self, cr, uid, product, link_type, external_session, context=None): |
1998 | if context is None: context = {} |
1999 | +<<<<<<< TREE |
2000 | conn = external_session.connection |
2001 | +======= |
2002 | + logger = logging.getLogger('ext synchro') |
2003 | +>>>>>>> MERGE-SOURCE |
2004 | product_link_obj = self.pool.get('product.link') |
2005 | selection_link_types = product_link_obj.get_link_type_selection(cr, uid, context) |
2006 | mag_product_id = self.get_extid( |
2007 | @@ -1520,8 +2244,13 @@ |
2008 | try: |
2009 | product_links = conn.call('product_link.list', [link_type, mag_product_id]) |
2010 | except Exception, e: |
2011 | +<<<<<<< TREE |
2012 | self.log(cr, uid, product.id, "Error when retrieving the list of links in Magento for product with reference %s and product id %s !" % (product.default_code, product.id,)) |
2013 | conn.logger.debug("Error when retrieving the list of links in Magento for product with reference %s and product id %s !" % (product.magento_sku, product.id,)) |
2014 | +======= |
2015 | + self.log(cr, uid, product.id, "Error when retrieving the list of links in Magento for product with sku %s and product id %s !" % (product.magento_sku, product.id,)) |
2016 | + logger.debug("Error when retrieving the list of links in Magento for product with sku %s and product id %s !", product.magento_sku, product.id) |
2017 | +>>>>>>> MERGE-SOURCE |
2018 | |
2019 | for product_link in product_links: |
2020 | linked_product_id = self.get_or_create_oeid( |
2021 | @@ -1545,7 +2274,11 @@ |
2022 | product_link_obj.write(cr, uid, existing_link, link_data, context=context) |
2023 | else: |
2024 | product_link_obj.create(cr, uid, link_data, context=context) |
2025 | +<<<<<<< TREE |
2026 | conn.logger.info("Successfully imported product link of type %s on product %s to product %s" %(link_type, product.id, linked_product_id)) |
2027 | +======= |
2028 | + logger.info("Successfully imported product link of type %s on product %s to product %s", link_type, product.id, linked_product_id) |
2029 | +>>>>>>> MERGE-SOURCE |
2030 | return True |
2031 | |
2032 | def mag_import_product_links_types(self, cr, uid, ids, link_types, external_session, context=None): |
2033 | |
2034 | === modified file 'magentoerpconnect/product_images.py' |
2035 | --- magentoerpconnect/product_images.py 2012-05-09 15:40:38 +0000 |
2036 | +++ magentoerpconnect/product_images.py 2012-07-06 14:53:18 +0000 |
2037 | @@ -23,7 +23,7 @@ |
2038 | from osv import osv, fields |
2039 | import magerp_osv |
2040 | import mimetypes |
2041 | -import netsvc |
2042 | +import logging |
2043 | from tools.translate import _ |
2044 | import base64 |
2045 | |
2046 | @@ -52,12 +52,12 @@ |
2047 | 'thumbnail':lambda * a:True, |
2048 | 'exclude':lambda * a:False |
2049 | } |
2050 | - |
2051 | + |
2052 | def get_changed_ids(self, cr, uid, start_date=False): |
2053 | proxy = self.pool.get('product.images') |
2054 | domain = start_date and ['|', ('create_date', '>', start_date), ('write_date', '>', start_date)] or [] |
2055 | return proxy.search(cr, uid, domain) |
2056 | - |
2057 | + |
2058 | def del_image_name(self, cr, uid, id, context=None): |
2059 | if context is None: context = {} |
2060 | image_ext_name_obj = self.pool.get('product.images.external.name') |
2061 | @@ -69,6 +69,13 @@ |
2062 | def update_remote_images(self, cr, uid, external_session, ids, context=None): |
2063 | if context is None: |
2064 | context = {} |
2065 | +<<<<<<< TREE |
2066 | +======= |
2067 | + logger = logging.getLogger('ext synchro') |
2068 | + conn = context.get('conn_obj', False) |
2069 | + if not conn: |
2070 | + return False |
2071 | +>>>>>>> MERGE-SOURCE |
2072 | |
2073 | ir_model_data_obj = self.pool.get('ir.model.data') |
2074 | |
2075 | @@ -112,12 +119,13 @@ |
2076 | image_2_date[image['id']] = image['write_date'] or image['create_date'] |
2077 | list_date = date_2_image.keys() |
2078 | list_date.sort() |
2079 | - |
2080 | + |
2081 | ids = [date_2_image[date] for date in list_date] |
2082 | |
2083 | while ids: |
2084 | product_images = self.browse_w_order(cr, uid, ids[:1000], context=context) |
2085 | for each in product_images: |
2086 | +<<<<<<< TREE |
2087 | product_extid = each.product_id.get_extid(external_session.referential_id.id) |
2088 | if not product_extid: |
2089 | external_session.logger.info("The product %s do not exist on magento" %(each.product_id.default_code)) |
2090 | @@ -163,10 +171,51 @@ |
2091 | |
2092 | |
2093 | if context.get('last_images_export_date') and image_2_date[each.id] > context['last_images_export_date']: #indeed if a product was created a long time ago and checked as exportable recently, the write date of the image can be far away in the past |
2094 | +======= |
2095 | + need_to_be_created = True |
2096 | + ext_file_name = each.oeid_to_extid(context['external_referential_id']) |
2097 | + if ext_file_name: #If update |
2098 | + try: |
2099 | + logger.info("Updating %s's image: %s", each.product_id.magento_sku, each.name) |
2100 | + result = update_image(ext_file_name, each) |
2101 | + logger.info("%s's image updated with sucess: %s", each.product_id.magento_sku, each.name) |
2102 | + need_to_be_created = False |
2103 | + except Exception, e: |
2104 | + logger.error(_("Error in connecting:%s"), e, exc_info=True) |
2105 | + if not "Fault 103" in str(e): |
2106 | + logger.error(_("Unknow error stop export")) |
2107 | + raise |
2108 | + else: |
2109 | + #If the image was deleded in magento, the external name is automatically deleded before trying to re-create the image in magento |
2110 | + model_data_ids = ir_model_data_obj.search(cr, uid, [('model', '=', self._name), ('res_id', '=', each.id), ('external_referential_id', '=', context['external_referential_id'])]) |
2111 | + if model_data_ids and len(model_data_ids) > 0: |
2112 | + ir_model_data_obj.unlink(cr, uid, model_data_ids, context=context) |
2113 | + logger.error(_("The image don't exist in magento, try to create it")) |
2114 | + if need_to_be_created: |
2115 | + if each.product_id.magento_sku: |
2116 | + logger.info("Sending %s's image: %s", each.product_id.magento_sku, each.name) |
2117 | + result = conn.call('catalog_product_attribute_media.create', |
2118 | + [each.product_id.magento_sku, |
2119 | + {'file':{ |
2120 | + 'name':each.name, |
2121 | + 'content': each.file, |
2122 | + 'mime': each.link and each.url and mimetypes.guess_type(each.url)[0] or each.extention and mimetypes.guess_type(each.extention)[0] or 'image/jpeg', |
2123 | + } |
2124 | + } |
2125 | + ]) |
2126 | + self.create_external_id_vals(cr, uid, each.id, result, context['external_referential_id'], context=context) |
2127 | + result = update_image(result, each) |
2128 | + logger.info("%s's image send with sucess: %s", each.product_id.magento_sku, each.name) |
2129 | + if image_2_date[each.id] > context['last_images_export_date']: #indeed if a product was created a long time ago and checked as exportable recently, the write date of the image can be far away in the past |
2130 | +>>>>>>> MERGE-SOURCE |
2131 | self.pool.get('sale.shop').write(cr,uid,context['shop_id'],{'last_images_export_date':image_2_date[each.id]}) |
2132 | cr.commit() |
2133 | ids = ids[1000:] |
2134 | +<<<<<<< TREE |
2135 | external_session.logger.info("still %s image to export" %len(ids)) |
2136 | +======= |
2137 | + logger.info("still %s image to export", len(ids)) |
2138 | +>>>>>>> MERGE-SOURCE |
2139 | return True |
2140 | - |
2141 | + |
2142 | product_images() |
2143 | |
2144 | === modified file 'magentoerpconnect/sale.py' |
2145 | --- magentoerpconnect/sale.py 2012-05-28 19:39:10 +0000 |
2146 | +++ magentoerpconnect/sale.py 2012-07-06 14:53:18 +0000 |
2147 | @@ -26,6 +26,7 @@ |
2148 | import pooler |
2149 | import magerp_osv |
2150 | import netsvc |
2151 | +import logging |
2152 | from tools.translate import _ |
2153 | import string |
2154 | import tools |
2155 | @@ -56,6 +57,7 @@ |
2156 | |
2157 | class sale_shop(magerp_osv.magerp_osv): |
2158 | _inherit = "sale.shop" |
2159 | +<<<<<<< TREE |
2160 | |
2161 | @only_for_referential('magento') |
2162 | def init_context_before_exporting_resource(self, cr, uid, external_session, object_id, resource_name, context=None): |
2163 | @@ -73,6 +75,9 @@ |
2164 | |
2165 | |
2166 | |
2167 | +======= |
2168 | + |
2169 | +>>>>>>> MERGE-SOURCE |
2170 | def _get_exportable_product_ids(self, cr, uid, ids, name, args, context=None): |
2171 | res = super(sale_shop, self)._get_exportable_product_ids(cr, uid, ids, name, args, context=None) |
2172 | for shop_id in res: |
2173 | @@ -95,6 +100,10 @@ |
2174 | |
2175 | def export_images(self, cr, uid, ids, context=None): |
2176 | if context is None: context = {} |
2177 | +<<<<<<< TREE |
2178 | +======= |
2179 | + logger = logging.getLogger('ext synchro') |
2180 | +>>>>>>> MERGE-SOURCE |
2181 | start_date = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT) |
2182 | image_obj = self.pool.get('product.images') |
2183 | for shop in self.browse(cr, uid, ids): |
2184 | @@ -102,11 +111,19 @@ |
2185 | exportable_product_ids = self.read(cr, uid, shop.id, ['exportable_product_ids'], context=context)['exportable_product_ids'] |
2186 | res = self.pool.get('product.product').get_exportable_images(cr, uid, external_session, exportable_product_ids, context=context) |
2187 | if res: |
2188 | +<<<<<<< TREE |
2189 | _logger.info("Creating %s images", len(res['to_create'])) |
2190 | _logger.info("Updating %s images", len(res['to_update'])) |
2191 | image_obj.update_remote_images(cr, uid, external_session, res['to_update']+res['to_create'], context) |
2192 | shop.write({'last_images_export_date': start_date}) |
2193 | +======= |
2194 | + logger.info("Creating %s images", len(res['to_create'])) |
2195 | + logger.info("Updating %s images", len(res['to_update'])) |
2196 | + image_obj.update_remote_images(cr, uid, res['to_update']+res['to_create'], context) |
2197 | + self.write(cr,uid,context['shop_id'],{'last_images_export_date': start_date}) |
2198 | +>>>>>>> MERGE-SOURCE |
2199 | return True |
2200 | +<<<<<<< TREE |
2201 | |
2202 | #TODO refactor the ay to export images |
2203 | #No time for doing it now so I just overwrite the generic function |
2204 | @@ -119,6 +136,11 @@ |
2205 | return super(sale_shop, self).export_resources(cr, uid, ids, resource_name, context=context) |
2206 | |
2207 | def _get_rootcategory(self, cr, uid, ids, name, value, context=None): |
2208 | +======= |
2209 | + |
2210 | + |
2211 | + def _get_rootcategory(self, cr, uid, ids, prop, unknow_none, context=None): |
2212 | +>>>>>>> MERGE-SOURCE |
2213 | res = {} |
2214 | for shop in self.browse(cr, uid, ids, context): |
2215 | if shop.root_category_id and shop.shop_group_id.referential_id: |
2216 | @@ -175,12 +197,66 @@ |
2217 | 'allow_magento_notification': lambda * a: False, |
2218 | } |
2219 | |
2220 | +<<<<<<< TREE |
2221 | def _get_magento_status(self, cr, uid, order, context=None): |
2222 | return ORDER_STATUS_MAPPING.get(order.state) |
2223 | |
2224 | def update_shop_orders(self, cr, uid, external_session, order, ext_id, context=None): |
2225 | if context is None: context = {} |
2226 | result = False |
2227 | +======= |
2228 | + |
2229 | + def import_shop_orders(self, cr, uid, shop, defaults, context=None): |
2230 | + if context is None: context = {} |
2231 | + result = super(sale_shop, self).import_shop_orders(cr, uid, shop, defaults=defaults, context=context) |
2232 | + [result.setdefault(key, []) for key in ['create_ids', 'write_ids', 'unchanged_ids']] |
2233 | + if shop.magento_shop: |
2234 | + self.check_need_to_update(cr, uid, [shop.id], context=context) |
2235 | + for storeview in shop.storeview_ids: |
2236 | + magento_storeview_id = self.pool.get('magerp.storeviews').oeid_to_extid(cr, uid, storeview.id, shop.referential_id.id, context={}) |
2237 | + ids_or_filter = {'store_id': {'eq': magento_storeview_id}, 'state': {'neq': 'canceled'}} |
2238 | + if shop.import_orders_from_date: |
2239 | + ids_or_filter.update({'created_at' : {'gt': shop.import_orders_from_date}}) |
2240 | + nb_last_created_ids = SALE_ORDER_IMPORT_STEP |
2241 | + while nb_last_created_ids: |
2242 | + defaults['magento_storeview_id'] = storeview.id |
2243 | + ctx = context.copy() |
2244 | + ctx['ids_or_filter'] = ids_or_filter |
2245 | + resp = self.pool.get('sale.order').mage_import_base(cr, uid, context.get('conn_obj', False), |
2246 | + shop.referential_id.id, defaults=defaults, |
2247 | + context=ctx) |
2248 | + result['create_ids'] += resp.get('create_ids', []) |
2249 | + result['write_ids'] += resp.get('write_ids', []) |
2250 | + result['unchanged_ids'] += resp.get('unchanged_ids', []) |
2251 | + nb_last_created_ids = len(resp.get('create_ids', []) + resp.get('write_ids', []) + resp.get('unchanged_ids', [])) |
2252 | + print nb_last_created_ids |
2253 | + return result |
2254 | + |
2255 | + def check_need_to_update(self, cr, uid, ids, context=None): |
2256 | + """ This function will update the order status in OpenERP for |
2257 | + the order which are in the state 'need to update' """ |
2258 | + so_obj = self.pool.get('sale.order') |
2259 | + |
2260 | + for shop in self.browse(cr, uid, ids): |
2261 | + conn = shop.referential_id.external_connection() |
2262 | + # Update the state of orders in OERP that are in "need_to_update":True |
2263 | + # from the Magento's corresponding orders |
2264 | + |
2265 | + # Get all need_to_update orders in OERP |
2266 | + orders_to_update = so_obj.search( |
2267 | + cr, uid, |
2268 | + [('need_to_update', '=', True), |
2269 | + ('shop_id', '=', shop.id)], |
2270 | + context=context) |
2271 | + so_obj.check_need_to_update( |
2272 | + cr, uid, orders_to_update, conn, context=context) |
2273 | + return False |
2274 | + |
2275 | + def update_shop_orders(self, cr, uid, order, ext_id, context=None): |
2276 | + if context is None: context = {} |
2277 | + result = {} |
2278 | + |
2279 | +>>>>>>> MERGE-SOURCE |
2280 | if order.shop_id.allow_magento_order_status_push: |
2281 | sale_obj = self.pool.get('sale.order') |
2282 | #status update: |
2283 | @@ -252,6 +328,7 @@ |
2284 | cr.execute("ALTER TABLE account_invoice_line ALTER COLUMN discount TYPE numeric(16,6);") |
2285 | self.pool.get('sale.report').init(cr) |
2286 | super(sale_order, self)._auto_init(cr, context) |
2287 | +<<<<<<< TREE |
2288 | |
2289 | #TODO reimplement the check on tva in a good way |
2290 | # # Adds vat number (country code+magento vat) if base_vat module is installed and Magento sends customer_taxvat |
2291 | @@ -296,6 +373,389 @@ |
2292 | vals['paid'] = True |
2293 | vals['amount'] = float(payment_info['amount_paid']) |
2294 | return vals |
2295 | +======= |
2296 | + |
2297 | + def get_order_addresses(self, cr, uid, referential_id, data_record, context=None): |
2298 | + partner_obj = self.pool.get('res.partner') |
2299 | + partner_address_obj = self.pool.get('res.partner.address') |
2300 | + res = {} |
2301 | + |
2302 | + # Magento allows to create a sale order |
2303 | + # without register as a user |
2304 | + is_guest_order = bool(int(data_record.get('customer_is_guest', 0))) |
2305 | + |
2306 | + # for a guest order or when magento |
2307 | + # does not provide customer_id on a normal order |
2308 | + # (it happens magento inconsistencies are common) |
2309 | + if (is_guest_order or |
2310 | + (data_record.get('website_id') and |
2311 | + not data_record.get('customer_id'))): |
2312 | + |
2313 | + website_obj = self.pool.get('external.shop.group') |
2314 | + oerp_website_id = website_obj.extid_to_oeid( |
2315 | + cr, uid, data_record['website_id'], referential_id, context=context) |
2316 | + |
2317 | + # first, try to find an already bound partner |
2318 | + # with same mail for same website |
2319 | + partner_id = partner_obj.search_magento_partner( |
2320 | + cr, uid, |
2321 | + data_record['customer_email'], |
2322 | + oerp_website_id, |
2323 | + is_bound=True, # search only for partners already bound |
2324 | + context=context) |
2325 | + |
2326 | + # if we have found one, we "fix" the data_record |
2327 | + # with the magento customer id |
2328 | + if partner_id: |
2329 | + ext_customer_id = partner_obj.oeid_to_extid( |
2330 | + cr, uid, partner_id, referential_id, context=context) |
2331 | + data_record['customer_id'] = ext_customer_id |
2332 | + |
2333 | + # no bound partner matching |
2334 | + # means that we have to consider it as a guest order |
2335 | + else: |
2336 | + is_guest_order = True |
2337 | + |
2338 | + # if we do not have a customer_id, the sale order |
2339 | + # is a guest sale order, so we cannot link the customer |
2340 | + if is_guest_order: |
2341 | + # when we import a guest sale order, we create the partner |
2342 | + # on the fly and we do not bind it ir.model.data |
2343 | + |
2344 | + # as we do not have a customer data record in the sale order |
2345 | + # data record, we manually populate one from the magento |
2346 | + # sale order record and import it with the standard mappings |
2347 | + address = data_record['billing_address'] |
2348 | + |
2349 | + customer_record = { |
2350 | + 'firstname': address['firstname'], |
2351 | + 'middlename': address['middlename'], |
2352 | + 'lastname': address['lastname'], |
2353 | + 'prefix': address['prefix'], |
2354 | + 'suffix': address.get('suffix', False), |
2355 | + 'email': data_record.get('customer_email', False), |
2356 | + 'taxvat': data_record.get('customer_taxvat', False), |
2357 | + 'group_id': data_record.get('customer_group_id', False), |
2358 | + 'gender': data_record.get('customer_gender', False), |
2359 | + 'store_id': data_record['store_id'], |
2360 | + 'created_at': data_record['created_at'], |
2361 | + 'updated_at': False, |
2362 | + 'created_in': False, |
2363 | + 'dob': data_record.get('customer_dob', False), |
2364 | + 'website_id': data_record.get('website_id', False), |
2365 | + } |
2366 | + partner_defaults = {'is_magento_guest': True} |
2367 | + partner_id = partner_obj.ext_import_unbound( |
2368 | + cr, uid, customer_record, referential_id, |
2369 | + defaults=partner_defaults, context=context) |
2370 | + else: |
2371 | + # always update the customer when importing an order |
2372 | + imp_ctx = dict(context) |
2373 | + imp_ctx['id'] = data_record['customer_id'] |
2374 | + partner_obj.get_external_data( |
2375 | + cr, uid, |
2376 | + context.get('conn_obj'), |
2377 | + referential_id, |
2378 | + defaults={}, |
2379 | + context=imp_ctx) |
2380 | + partner_id = partner_obj.extid_to_oeid( |
2381 | + cr, uid, data_record['customer_id'], referential_id) |
2382 | + |
2383 | + # update the address book of the customer, this addresses |
2384 | + # will be available in the partner form and the searches |
2385 | + partner_obj.import_magento_address_book( |
2386 | + cr, uid, partner_id, referential_id, context=context) |
2387 | + |
2388 | + # The addresses of the sale order are imported as active=false |
2389 | + # so they are linked with the sale order but they are not displayed |
2390 | + # in the customer form and the searches. |
2391 | + |
2392 | + # We import the addresses of the sale order as Active = False |
2393 | + # so they will be available in the documents generated as the |
2394 | + # sale order or the picking, but they won't be available on |
2395 | + # the partner form or the searches. Too many adresses would |
2396 | + # be displayed. |
2397 | + # They are never synchronized, |
2398 | + # we keep the revision of the sale order |
2399 | + # For the orders which are from guests, we let the addresses |
2400 | + # as active because they doesn't have an address book. |
2401 | + addresses_defaults = {'partner_id': partner_id, |
2402 | + 'email': data_record.get('customer_email', False), |
2403 | + 'active': is_guest_order, |
2404 | + 'is_magento_order_address': True} |
2405 | + # We import the addresses as unbound becauses Magento is not able to |
2406 | + # give us an ID when the address is created during the order. |
2407 | + # It gives an empty id, a 0 or worse, a wrong id. |
2408 | + billing_address = data_record['billing_address'].copy() |
2409 | + # remove customer_id because we force it in the defaults |
2410 | + # it avoid to try to import the partner by customer_id |
2411 | + billing_address.pop('customer_id', False) |
2412 | + billing_id = partner_address_obj.ext_import_unbound( |
2413 | + cr, uid, billing_address, |
2414 | + referential_id, defaults=addresses_defaults, |
2415 | + context=context) |
2416 | + |
2417 | + shipping_id = False |
2418 | + if data_record['shipping_address']: |
2419 | + shipping_address = data_record['shipping_address'].copy() |
2420 | + # remove customer_id because we force it in the defaults |
2421 | + # it avoid to try to import the partner by customer_id |
2422 | + shipping_address.pop('customer_id', False) |
2423 | + shipping_id = partner_address_obj.ext_import_unbound( |
2424 | + cr, uid, shipping_address, |
2425 | + referential_id, defaults=addresses_defaults, |
2426 | + context=context) |
2427 | + |
2428 | + # default addresses ids for the sale order |
2429 | + res['partner_id'] = partner_id |
2430 | + res['partner_order_id'] = res['partner_invoice_id'] = billing_id |
2431 | + res['partner_shipping_id'] = shipping_id or billing_id |
2432 | + |
2433 | + if data_record.get('customer_taxvat'): |
2434 | + partner_obj.add_magento_vat_number( |
2435 | + cr, uid, partner_id, |
2436 | + data_record['customer_taxvat'], |
2437 | + data_record['billing_address'].get('country_id'), |
2438 | + context=context) |
2439 | + return res |
2440 | + |
2441 | + def add_order_extra_line(self, cr, uid, res, data_record, ext_field, product_ref, defaults, context=None): |
2442 | + """ Add or substract amount on order as a separate line item with single quantity for each type of amounts like : |
2443 | + shipping, cash on delivery, discount, gift certificates... |
2444 | + |
2445 | + @param res: dict of the order to create |
2446 | + @param data_record: full data dict of the order |
2447 | + @param ext_field: name of the field in data_record where the amount of the extra lineis stored |
2448 | + @param product_ref: tuple with module and xml_id (module, xml_id) of the product to use for the extra line |
2449 | + |
2450 | + Optional arguments in context: |
2451 | + sign: multiply the amount with the sign to add or substract it from the sale order |
2452 | + ext_tax_field: name of the field in data_record where the tax amount is stored |
2453 | + ext_code_field: name of the field in data_record containing a code (for coupons and gift certificates) which will be printed on the product name |
2454 | + """ |
2455 | + if context is None: context = {} |
2456 | + model_data_obj = self.pool.get('ir.model.data') |
2457 | + sign = 'sign' in context and context['sign'] or 1 |
2458 | + ext_tax_field = 'ext_tax_field' in context and context['ext_tax_field'] or None |
2459 | + ext_code_field = 'ext_code_field' in context and context['ext_code_field'] or None |
2460 | + |
2461 | + model, product_id = model_data_obj.get_object_reference(cr, uid, *product_ref) |
2462 | + product = self.pool.get('product.product').browse(cr, uid, product_id, context) |
2463 | + is_tax_included = context.get('price_is_tax_included', False) |
2464 | + amount = float(data_record[ext_field]) * sign |
2465 | + name = product.name |
2466 | + if ext_code_field and data_record.get(ext_code_field, False): |
2467 | + name = "%s [%s]" % (name, data_record[ext_code_field]) |
2468 | + |
2469 | + if is_tax_included: |
2470 | + price_unit = float(amount) + float(data_record[ext_tax_field]) |
2471 | + else: |
2472 | + price_unit = float(amount) |
2473 | + |
2474 | + extra_line = { |
2475 | + 'product_id': product.id, |
2476 | + 'name': name, |
2477 | + 'product_uom': product.uom_id.id, |
2478 | + 'product_uom_qty': 1, |
2479 | + 'price_unit': price_unit, |
2480 | + } |
2481 | + |
2482 | + if not res.get('order_line'): |
2483 | + res['order_line'] = [] |
2484 | + |
2485 | + if context.get('use_external_tax'): |
2486 | + # get the tax computed by the external system |
2487 | + tax_vat = abs(float(data_record[ext_tax_field]) / amount) |
2488 | + line_tax_id = self.pool.get('account.tax').get_tax_from_rate(cr, uid, tax_vat, context.get('is_tax_included'), context=context) |
2489 | + extra_line['tax_id'] = [(6, 0, line_tax_id)] |
2490 | + else: |
2491 | + # compute the taxes, apply fiscal positions, default values and so on |
2492 | + extra_line = self.pool.get('sale.order.line').play_sale_order_line_onchange(cr, uid, extra_line, res, res['order_line'], defaults, context=context) |
2493 | + res['order_line'].append((0, 0, extra_line)) |
2494 | + |
2495 | + return res |
2496 | + |
2497 | + def add_order_shipping(self, cr, uid, res, external_referential_id, data_record, defaults, context=None): |
2498 | + if context is None: context = {} |
2499 | + if data_record.get('shipping_amount', False) and float(data_record.get('shipping_amount', False)) > 0: |
2500 | + ctx = context.copy() |
2501 | + ctx.update({ |
2502 | + 'ext_tax_field': 'shipping_tax_amount', |
2503 | + }) |
2504 | + product_ref = ('base_sale_multichannels', 'product_product_shipping') |
2505 | + res = self.add_order_extra_line(cr, uid, res, data_record, 'shipping_amount', product_ref, defaults, ctx) |
2506 | + return res |
2507 | + |
2508 | + def add_gift_certificates(self, cr, uid, res, external_referential_id, data_record, defaults, context=None): |
2509 | + if context is None: context = {} |
2510 | + if data_record.get('giftcert_amount', False) and float(data_record.get('giftcert_amount', False)) > 0: |
2511 | + ctx = context.copy() |
2512 | + ctx.update({ |
2513 | + 'ext_code_field': 'giftcert_code', |
2514 | + 'sign': -1, |
2515 | + }) |
2516 | + product_ref = ('magentoerpconnect', 'product_product_gift') |
2517 | + res = self.add_order_extra_line(cr, uid, res, data_record, 'giftcert_amount', product_ref, defaults, ctx) |
2518 | + return res |
2519 | + |
2520 | + def add_discount(self, cr, uid, res, external_referential_id, data_record, defaults, context=None): |
2521 | + #TODO fix me rev 476 |
2522 | + #if data_record.get('discount_amount', False) and float(data_record.get('discount_amount', False)) < 0: |
2523 | + # ctx = context.copy() |
2524 | + # ctx.update({ |
2525 | + # 'ext_code_field': 'coupon_code', |
2526 | + # }) |
2527 | + # product_ref = ('magentoerpconnect', 'product_product_discount') |
2528 | + # res = self.add_order_extra_line(cr, uid, res, data_record, 'discount_amount', product_ref, defaults, ctx) |
2529 | + return res |
2530 | + |
2531 | + def add_cash_on_delivery(self, cr, uid, res, external_referential_id, data_record, defaults, context=None): |
2532 | + if context is None: context = {} |
2533 | + if data_record.get('cod_fee', False) and float(data_record.get('cod_fee', False)) > 0: |
2534 | + ctx = context.copy() |
2535 | + ctx.update({ |
2536 | + 'ext_tax_field': 'cod_tax_amount', |
2537 | + }) |
2538 | + product_ref = ('magentoerpconnect', 'product_product_cash_on_delivery') |
2539 | + res = self.add_order_extra_line(cr, uid, res, data_record, 'cod_fee', product_ref, defaults, ctx) |
2540 | + return res |
2541 | + |
2542 | + def convert_extdata_into_oedata(self, cr, uid, external_data, external_referential_id, parent_data=None, defaults=None, context=None): |
2543 | + res = super(sale_order, self).convert_extdata_into_oedata(cr, uid, external_data, external_referential_id, parent_data=parent_data, defaults=defaults, context=context) |
2544 | + res=res[0] |
2545 | + external_data = external_data[0] |
2546 | + res = self.add_order_shipping(cr, uid, res, external_referential_id, external_data, defaults, context) |
2547 | + res = self.add_gift_certificates(cr, uid, res, external_referential_id, external_data, defaults, context) |
2548 | + res = self.add_discount(cr, uid, res, external_referential_id, external_data, defaults, context) |
2549 | + res = self.add_cash_on_delivery(cr, uid, res, external_referential_id, external_data, defaults, context) |
2550 | + return [res] |
2551 | + |
2552 | + def _merge_sub_items(self, cr, uid, product_type, top_item, child_items, context=None): |
2553 | + """ |
2554 | + Manage the sub items of the magento sale order lines. A top item contains one |
2555 | + or many child_items. For some product types, we want to merge them in the main |
2556 | + item, or keep them as order line. |
2557 | + |
2558 | + A list may be returned to add many items (ie to keep all child_items as items. |
2559 | + |
2560 | + :param top_item: main item (bundle, configurable) |
2561 | + :param child_items: list of childs of the top item |
2562 | + :return: item or list of items |
2563 | + """ |
2564 | + if product_type == 'configurable': |
2565 | + item = top_item.copy() |
2566 | + # For configurable product all information regarding the price is in the configurable item |
2567 | + # In the child a lot of information is empty, but contains the right sku and product_id |
2568 | + # So the real product_id and the sku and the name have to be extracted from the child |
2569 | + for field in ['sku', 'product_id', 'name']: |
2570 | + item[field] = child_items[0][field] |
2571 | + return item |
2572 | + return top_item |
2573 | + |
2574 | + def data_record_filter(self, cr, uid, data_record, context=None): |
2575 | + child_items = {} # key is the parent item id |
2576 | + top_items = [] |
2577 | + |
2578 | + # Group the childs with their parent |
2579 | + for item in data_record['items']: |
2580 | + if item.get('parent_item_id'): |
2581 | + child_items.setdefault(item['parent_item_id'], []).append(item) |
2582 | + else: |
2583 | + top_items.append(item) |
2584 | + |
2585 | + all_items = [] |
2586 | + for top_item in top_items: |
2587 | + if top_item['item_id'] in child_items: |
2588 | + item_modified = self._merge_sub_items(cr, uid, |
2589 | + top_item['product_type'], |
2590 | + top_item, |
2591 | + child_items[top_item['item_id']], |
2592 | + context=context) |
2593 | + if not isinstance(item_modified, list): |
2594 | + item_modified = [item_modified] |
2595 | + all_items.extend(item_modified) |
2596 | + else: |
2597 | + all_items.append(top_item) |
2598 | + |
2599 | + data_record['items'] = all_items |
2600 | + return data_record |
2601 | + |
2602 | + def oevals_from_extdata(self, cr, uid, external_referential_id, data_record, key_field, mapping_lines, parent_data=None, previous_lines=None, defaults=None, context=None): |
2603 | + if context is None: context = {} |
2604 | + if data_record.get('items', False): |
2605 | + data_record = self.data_record_filter(cr, uid, data_record, context=context) |
2606 | + #TODO refactor this code regarding the new feature of sub-mapping in base_external_referential |
2607 | + if not context.get('one_by_one', False): |
2608 | + # we fix the website_id when it is empty because we need it to |
2609 | + # find the correct partner (based on email + website_id) |
2610 | + # website is based on the store_id which is: |
2611 | + # website m2o -> store |
2612 | + if not data_record.get('website_id') and data_record.get('store_id'): |
2613 | + store_obj = self.pool.get('magerp.storeviews') |
2614 | + store_id = store_obj.extid_to_oeid( |
2615 | + cr, uid, data_record['store_id'], external_referential_id) |
2616 | + store = store_obj.browse(cr, uid, store_id, context=context) |
2617 | + data_record['website_id'] = store.website_id.oeid_to_extid( |
2618 | + external_referential_id=external_referential_id, context=context) |
2619 | + |
2620 | + defaults.update(self.get_order_addresses( |
2621 | + cr, uid, external_referential_id, data_record, context=context)) |
2622 | + res = super(magerp_osv.magerp_osv, self).oevals_from_extdata(cr, uid, external_referential_id, data_record, key_field, mapping_lines, parent_data, previous_lines, defaults, context) |
2623 | + |
2624 | + #Move me in a mapping |
2625 | + if not context.get('one_by_one', False): |
2626 | + if data_record.get('status_history', False) and len(data_record['status_history']) > 0: |
2627 | + res['date_order'] = data_record['status_history'][len(data_record['status_history'])-1]['created_at'] |
2628 | + return res |
2629 | + |
2630 | + def _parse_external_payment(self, cr, uid, order_data, context=None): |
2631 | + """ |
2632 | + Parse the external order data and return if the sale order |
2633 | + has been paid and the amount to pay or to be paid |
2634 | + |
2635 | + :param dict order_data: payment information of the magento sale |
2636 | + order |
2637 | + :return: tuple where : |
2638 | + - first item indicates if the payment has been done (True or False) |
2639 | + - second item represents the amount paid or to be paid |
2640 | + """ |
2641 | + paid = amount = False |
2642 | + payment_info = order_data.get('payment') |
2643 | + if payment_info: |
2644 | + amount = False |
2645 | + if payment_info.get('amount_paid', False): |
2646 | + amount = payment_info.get('amount_paid', False) |
2647 | + paid = True |
2648 | + elif payment_info.get('amount_ordered', False): |
2649 | + amount = payment_info.get('amount_ordered', False) |
2650 | + return paid, amount |
2651 | + |
2652 | + def create_payments(self, cr, uid, order_id, data_record, context=None): |
2653 | + if context is None: |
2654 | + context = {} |
2655 | + |
2656 | + if 'Magento' in context.get('external_referential_type', ''): |
2657 | + payment_info = data_record.get('payment') |
2658 | + paid, amount = self._parse_external_payment( |
2659 | + cr, uid, data_record, context=context) |
2660 | + if paid: |
2661 | + order = self.pool.get('sale.order').browse( |
2662 | + cr, uid, order_id, context) |
2663 | + self.generate_payment_with_pay_code( |
2664 | + cr, uid, |
2665 | + payment_info['method'], |
2666 | + order.partner_id.id, |
2667 | + float(amount), |
2668 | + "mag_" + payment_info['payment_id'], |
2669 | + "mag_" + data_record['increment_id'], |
2670 | + order.date_order, |
2671 | + paid, |
2672 | + context=context) |
2673 | + else: |
2674 | + paid = super(sale_order, self).create_payments( |
2675 | + cr, uid, order_id, data_record, context=context) |
2676 | + return paid |
2677 | +>>>>>>> MERGE-SOURCE |
2678 | |
2679 | def _chain_cancel_orders(self, cr, uid, external_id, external_referential_id, defaults=None, context=None): |
2680 | """ Get all the chain of edited orders (an edited order is canceled on Magento) |
2681 | @@ -304,6 +764,10 @@ |
2682 | """ |
2683 | if context is None: |
2684 | context = {} |
2685 | +<<<<<<< TREE |
2686 | +======= |
2687 | + logger = logging.getLogger('ext synchro') |
2688 | +>>>>>>> MERGE-SOURCE |
2689 | conn = context.get('conn_obj', False) |
2690 | parent_list = [] |
2691 | # get all parents orders (to cancel) of the sale orders |
2692 | @@ -319,7 +783,11 @@ |
2693 | try: |
2694 | wf_service.trg_validate(uid, 'sale.order', canceled_order_id, 'cancel', cr) |
2695 | self.log(cr, uid, canceled_order_id, "order %s canceled when updated from external system" % (canceled_order_id,)) |
2696 | +<<<<<<< TREE |
2697 | _logger.info("Order %s canceled when updated from external system because it has been replaced by a new one", canceled_order_id) |
2698 | +======= |
2699 | + logger.info("Order %s canceled when updated from external system because it has been replaced by a new one", canceled_order_id) |
2700 | +>>>>>>> MERGE-SOURCE |
2701 | except osv.except_osv, e: |
2702 | #TODO: generic reporting of errors in magentoerpconnect |
2703 | # except if the sale order has been confirmed for example, we cannot cancel the order |
2704 | @@ -342,6 +810,7 @@ |
2705 | 'priority': '2' |
2706 | }) |
2707 | |
2708 | +<<<<<<< TREE |
2709 | #NEW FEATURE |
2710 | |
2711 | #TODO reimplement chain cancel orders |
2712 | @@ -433,6 +902,118 @@ |
2713 | |
2714 | @only_for_referential('magento') |
2715 | def _check_need_to_update_single(self, cr, uid, external_session, order, context=None): |
2716 | +======= |
2717 | + def _ext_import_one(self, cr, uid, external_id, vals, external_data, referential_id, defaults=None, context=None): |
2718 | + """ |
2719 | + Inherit the method to flag the order to "Imported" on Magento right after the importation |
2720 | + Before the import, check if the order is already imported and in a such case, skip the import |
2721 | + and flag "imported" on Magento. |
2722 | + """ |
2723 | + if context is None: context = {} |
2724 | + if not (context.get('external_referential_type', False) and 'Magento' in context['external_referential_type']): |
2725 | + return super(sale_order, self)._ext_import_one( |
2726 | + cr, uid, external_id, vals, external_data, referential_id, defaults=defaults, context=context) |
2727 | + |
2728 | + res = False, False |
2729 | + if not self.extid_to_existing_oeid(cr, uid, external_id, referential_id, context=context): |
2730 | + res = super(sale_order, self)._ext_import_one( |
2731 | + cr, uid, external_id, vals, external_data, referential_id, defaults=defaults, context=context) |
2732 | + |
2733 | + if any(res): |
2734 | + # if a created order has a relation_parent_real_id, |
2735 | + # the new one replaces the original, so we have to cancel the old ones |
2736 | + if external_data.get('relation_parent_real_id', False): |
2737 | + self._chain_cancel_orders(cr, uid, external_id, referential_id, defaults=defaults, context=context) |
2738 | + |
2739 | + return res |
2740 | + |
2741 | + def _ext_import_one_cr(self, cr, uid, external_data, referential_id, defaults=None, context=None): |
2742 | + """ Import one external resource, with cursor management, open a new cursor |
2743 | + which is commited on each import |
2744 | + |
2745 | + This method can be inherited to do an action which have to be done after |
2746 | + that the imported resource is commited in database. |
2747 | + |
2748 | + @param dict external_data: vals of the external resource before conversion |
2749 | + @param external_referential_id: external referential id from where we import the resource |
2750 | + @param defaults: defaults value for fields which are not in vals |
2751 | + @return: tuple created id / updated id |
2752 | + """ |
2753 | + |
2754 | + cid, wid = super(sale_order, self)._ext_import_one_cr( |
2755 | + cr, uid, external_data, referential_id, defaults=defaults, context=context) |
2756 | + |
2757 | + if (cid or wid and |
2758 | + (context.get('external_referential_type') and |
2759 | + 'Magento' in context['external_referential_type'])): |
2760 | + ext_id = self.oeid_to_extid(cr, uid, cid or wid, referential_id, |
2761 | + context=context) |
2762 | + # set the "imported" flag to true on Magento |
2763 | + self.ext_set_order_imported(cr, uid, ext_id, referential_id, context=context) |
2764 | + return cid, wid |
2765 | + |
2766 | + def ext_set_order_imported(self, cr, uid, external_id, external_referential_id, context=None): |
2767 | + if context is None: |
2768 | + context = {} |
2769 | + logger = logging.getLogger('ext synchro') |
2770 | + conn = context.get('conn_obj', False) |
2771 | + conn.call('sales_order.done', [external_id]) |
2772 | + logger.info("Successfully set the imported flag on Magento on sale order %s", external_id) |
2773 | + return True |
2774 | + |
2775 | + def mage_import_base(self, cr, uid, conn, external_referential_id, defaults=None, context=None): |
2776 | + """ Inherited method for Sales orders in order to import only order not flagged as "imported" on Magento |
2777 | + """ |
2778 | + if context is None: |
2779 | + context = {} |
2780 | + if not 'ids_or_filter' in context.keys(): |
2781 | + context['ids_or_filter'] = [] |
2782 | + result = {'create_ids': [], 'write_ids': []} |
2783 | + |
2784 | + # returns the non already imported order (limit returns the n first orders) |
2785 | + order_retrieve_params = { |
2786 | + 'imported': False, |
2787 | + 'limit': SALE_ORDER_IMPORT_STEP, |
2788 | + 'filters': context['ids_or_filter'], |
2789 | + } |
2790 | + ext_order_ids = conn.call('sales_order.search', [order_retrieve_params]) |
2791 | + result = self._import_orders( |
2792 | + cr, uid, conn, ext_order_ids, external_referential_id, defaults=defaults, context=context) |
2793 | + return result |
2794 | + |
2795 | + def _import_orders(self, cr, uid, conn, external_ids, referential_id, defaults=None, context=None): |
2796 | + if context is None: |
2797 | + context = {} |
2798 | + |
2799 | + logger = logging.getLogger('ext synchro') |
2800 | + mapping_id = self.pool.get('external.mapping').search( |
2801 | + cr, uid, |
2802 | + [('model', '=', self._name), |
2803 | + ('referential_id', '=', referential_id)], |
2804 | + context=context) |
2805 | + |
2806 | + context = dict(context) |
2807 | + # we will need the connection to set the flag to "imported" on magento after each order import |
2808 | + context['conn_obj'] = conn |
2809 | + # use the external log for the orders import |
2810 | + context['use_external_log'] = True |
2811 | + order_ids_filtred = [] |
2812 | + unchanged_ids = [] |
2813 | + for ext_order_id in external_ids: |
2814 | + existing_id = self.extid_to_existing_oeid(cr, uid, ext_order_id, referential_id, context=context) |
2815 | + if existing_id: |
2816 | + unchanged_ids.append(existing_id) |
2817 | + logger.info("the order %s already exist in OpenERP", ext_order_id) |
2818 | + self.ext_set_order_imported(cr, uid, ext_order_id, referential_id, context=context) |
2819 | + else: |
2820 | + order_ids_filtred.append({'increment_id' : ext_order_id}) |
2821 | + result = self.mage_import_one_by_one( |
2822 | + cr, uid, conn, referential_id, mapping_id[0], order_ids_filtred, defaults, context) |
2823 | + result['unchanged_ids'] = unchanged_ids |
2824 | + return result |
2825 | + |
2826 | + def _check_need_to_update_single(self, cr, uid, order, conn, context=None): |
2827 | +>>>>>>> MERGE-SOURCE |
2828 | """ |
2829 | For one order, check on Magento if it has been paid since last |
2830 | check. If so, it will launch the defined flow based on the |
2831 | @@ -535,6 +1116,7 @@ |
2832 | |
2833 | return created |
2834 | |
2835 | +<<<<<<< TREE |
2836 | ######################################################################################################################## |
2837 | # |
2838 | # CODE THAT CLEAN MAGENTO DATA BEFORE IMPORTING IT THE BEST WILL BE TO REFACTOR MAGENTO API |
2839 | @@ -632,6 +1214,18 @@ |
2840 | resource['shipping_address']['customer_id'] = resource['customer_id'] |
2841 | return resource |
2842 | |
2843 | +======= |
2844 | + def retry_import(self, cr, uid, id, ext_id, external_referential_id, defaults=None, context=None): |
2845 | + """ When we import again a previously failed import""" |
2846 | + conn = self.pool.get('external.referential').external_connection( |
2847 | + cr, uid, external_referential_id) |
2848 | + res = self._import_orders( |
2849 | + cr, uid, conn, [ext_id], external_referential_id, defaults=defaults, context=context) |
2850 | + if any(res.values()): |
2851 | + return True |
2852 | + return False |
2853 | + |
2854 | +>>>>>>> MERGE-SOURCE |
2855 | sale_order() |
2856 | |
2857 | |
2858 | |
2859 | === modified file 'magentoerpconnect/sale_view.xml' |
2860 | --- magentoerpconnect/sale_view.xml 2012-05-11 15:14:05 +0000 |
2861 | +++ magentoerpconnect/sale_view.xml 2012-07-06 14:53:18 +0000 |
2862 | @@ -55,6 +55,25 @@ |
2863 | </field> |
2864 | </record> |
2865 | |
2866 | +<<<<<<< TREE |
2867 | +======= |
2868 | + <record id="magerp_view_shop_auto_import_form" model="ir.ui.view"> |
2869 | + <field name="name">magerp_view_shop_auto_import_form</field> |
2870 | + <field name="model">sale.shop</field> |
2871 | + <field name="type">form</field> |
2872 | + <field name="inherit_id" ref="base_sale_multichannels.base_sale_multichannels_view_shop_form"/> |
2873 | + <field name="arch" type="xml"> |
2874 | + <xpath expr="/form/notebook" position="inside"> |
2875 | + <page string="Magento Information" attrs="{'invisible': [('magento_shop','=',False)]}"> |
2876 | + <field name="magento_shop" /> |
2877 | + <field name="allow_magento_order_status_push" /> |
2878 | + <field name="allow_magento_notification"/> |
2879 | + </page> |
2880 | + </xpath> |
2881 | + </field> |
2882 | + </record> |
2883 | + |
2884 | +>>>>>>> MERGE-SOURCE |
2885 | <record id="base_sale_multichannel_view_order_form_magento" model="ir.ui.view"> |
2886 | <field name="name">base_sale_multichannel_view_order_form.magento</field> |
2887 | <field name="model">sale.order</field> |
2888 | |
2889 | === modified file 'magentoerpconnect/settings/1.3.2.4/external.mapping.template.csv' |
2890 | --- magentoerpconnect/settings/1.3.2.4/external.mapping.template.csv 2012-03-27 09:52:57 +0000 |
2891 | +++ magentoerpconnect/settings/1.3.2.4/external.mapping.template.csv 2012-07-06 14:53:18 +0000 |
2892 | @@ -10,5 +10,5 @@ |
2893 | "magento_1324_attr","magento1324","model_magerp_product_attributes","ol_catalog_product_attribute.list",,,,,"attribute_id" |
2894 | "magento_1324_prd","magento1324","product.model_product_product","catalog_product.list","catalog_product.info","ol_catalog_product.update","ol_catalog_product.create",,"product_id" |
2895 | "magento_1324_cst_grp","magento1324","base.model_res_partner_category","ol_customer_groups.list",,,,,"customer_group_id" |
2896 | -"magento_1324_prt_adr","magento1324","base.model_res_partner_address","ol_customer_address.list","ol_customer_address.info",,,,"customer_address_id" |
2897 | +"magento_1324_prt_adr","magento1324","base.model_res_partner_address","ol_customer_address.list","ol_customer_address.info",,,,"entity_id" |
2898 | "magento_1324_prt","magento1324","base.model_res_partner","customer.list","customer.info","customer.update",,,"customer_id" |
2899 | |
2900 | === modified file 'magentoerpconnect/settings/1.3.2.4/external.mappinglines.template.csv' |
2901 | --- magentoerpconnect/settings/1.3.2.4/external.mappinglines.template.csv 2012-05-24 19:50:22 +0000 |
2902 | +++ magentoerpconnect/settings/1.3.2.4/external.mappinglines.template.csv 2012-07-06 14:53:18 +0000 |
2903 | @@ -1,3 +1,4 @@ |
2904 | +<<<<<<< TREE |
2905 | "id","version_id:id","model_id:id","external_field","field_id:id","type","evaluation_type","external_type","child_mapping_id:id","in_function","out_function" |
2906 | "mag_1324_erp_s_name","magento1324","base_sale_multichannels.model_external_shop_group","name",,"in_out","function","unicode",,"result=[('name',ifield)]","result=[('name',record['name'])]" |
2907 | "mag_1324_erp_s_code","magento1324","base_sale_multichannels.model_external_shop_group","code",,"in_out","function","unicode",,"result=[('code',ifield)]", |
2908 | @@ -19,6 +20,29 @@ |
2909 | "mag_1324_erp_so_total_amount","magento1324","sale.model_sale_order","grand_total",,"in_out","function","float",,"result=[('ext_total_amount',str(ifield))]", |
2910 | "mag_1324_erp_so_name","magento1324","sale.model_sale_order","increment_id",,"in_out","function","unicode",,"result=[('magento_incrementid',str(ifield)), ('name','mag_' + str(ifield))]", |
2911 | "mag_1324_erp_so_carrier_id","magento1324","sale.model_sale_order","shipping_method",,"in_out","function","unicode",,"if ifield: |
2912 | +======= |
2913 | +id,type_id:id,model_id:id,external_field,field_id:id,type,evaluation_type,external_type,child_mapping_id:id,in_function,out_function |
2914 | +mag_1324_erp_s_name,magento1324,base_sale_multichannels.model_external_shop_group,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
2915 | +mag_1324_erp_s_code,magento1324,base_sale_multichannels.model_external_shop_group,code,,in_out,function,unicode,,"result=[('code',ifield)]", |
2916 | +mag_1324_erp_s_web,magento1324,base_sale_multichannels.model_external_shop_group,website_id,,in_out,function,int,,"result=[('website_id',ifield)]", |
2917 | +mag_1324_erp_s_isa,magento1324,base_sale_multichannels.model_external_shop_group,is_default,,in_out,function,unicode,,"result=[('is_default',bool(eval(ifield)))]", |
2918 | +mag_1324_erp_s_stord,magento1324,base_sale_multichannels.model_external_shop_group,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]", |
2919 | +mag_1324_erp_s_gpid,magento1324,base_sale_multichannels.model_external_shop_group,default_group_id,,in_out,function,int,,"result=[('default_shop_integer_id',ifield)]", |
2920 | +mag_1324_erp_sv_name,magento1324,model_magerp_storeviews,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
2921 | +mag_1324_erp_sv_code,magento1324,model_magerp_storeviews,code,,in_out,function,unicode,,"result=[('code',ifield)]", |
2922 | +mag_1324_erp_sv_sg,magento1324,model_magerp_storeviews,website_id,,in_out,function,int,,"result=[('website_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
2923 | +mag_1324_erp_sv_isa,magento1324,model_magerp_storeviews,is_active,,in_out,function,unicode,,"result=[('is_active',bool(eval(ifield)))]", |
2924 | +mag_1324_erp_sv_stord,magento1324,model_magerp_storeviews,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]", |
2925 | +mag_1324_erp_sv_gpid,magento1324,model_magerp_storeviews,group_id,,in_out,function,int,,"result=[('shop_id',self.pool.get('sale.shop').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
2926 | +mag_1324_erp_st_name,magento1324,sale.model_sale_shop,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
2927 | +mag_1324_erp_st_gpid,magento1324,sale.model_sale_shop,group_id,,in_out,function,int,,"result=[('group_id',ifield)]", |
2928 | +mag_1324_erp_st_grp,magento1324,sale.model_sale_shop,website_id,,in_out,function,int,,"result=[('shop_group_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
2929 | +mag_1324_erp_st_default_st,magento1324,sale.model_sale_shop,default_store_id,,in_out,function,int,,"result=[('default_storeview_integer_id',ifield)]", |
2930 | +mag_1324_erp_st_root_categ,magento1324,sale.model_sale_shop,root_category_id,,in_out,function,int,,"result=[('root_category_id',ifield)]", |
2931 | +mag_1324_erp_so_total_amount,magento1324,sale.model_sale_order,grand_total,,in_out,function,float,,"result=[('ext_total_amount',str(ifield))]", |
2932 | +mag_1324_erp_so_name,magento1324,sale.model_sale_order,increment_id,,in_out,function,unicode,,"result=[('magento_incrementid',str(ifield)), ('name','mag_' + str(ifield))]", |
2933 | +mag_1324_erp_so_carrier_id,magento1324,sale.model_sale_order,shipping_method,,in_out,function,unicode,,"if ifield: |
2934 | +>>>>>>> MERGE-SOURCE |
2935 | carrier_ids = self.pool.get('delivery.carrier').search(cr, uid, [('magento_code', '=', ifield)]) |
2936 | if carrier_ids: |
2937 | result=[('carrier_id', carrier_ids[0])] |
2938 | @@ -41,16 +65,24 @@ |
2939 | clean = re.sub('\w:\w:|\w:\w+;', '', ifield) |
2940 | for each in clean.split('{'): |
2941 | if each.startswith('""label""'): |
2942 | - split_info = each.split(';') |
2943 | + split_info = each.split(';') |
2944 | options_label.append('%s: %s [%s]' % (split_info[1], split_info[3], data['sku'])) |
2945 | - |
2946 | + |
2947 | result=[('notes', """".join(options_label).replace('""""', '\n').replace('""', ''))] |
2948 | ", |
2949 | +<<<<<<< TREE |
2950 | "mag_1324_erp_soline_pid","magento1324","sale.model_sale_order_line","product_id",,"in_out","function","unicode",,"context['alternative_key'] = data['sku'] |
2951 | result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, external_session, ifield, referential_id))]", |
2952 | "mag_1324_erp_soline_uomqty","magento1324","sale.model_sale_order_line","qty_ordered",,"in_out","function","unicode",,"result=[('product_uom_qty',ifield)]", |
2953 | "mag_1324_erp_soline_uosqty","magento1324","sale.model_sale_order_line","qty_ordered",,"in","function","unicode",,"result=[('product_uos_qty',ifield)]", |
2954 | "mag_1324_erp_soline_price","magento1324","sale.model_sale_order_line","price",,"in","function","unicode",,"if context.get('price_is_tax_included', False): |
2955 | +======= |
2956 | +mag_1324_erp_soline_pid,magento1324,sale.model_sale_order_line,product_id,,in_out,function,unicode,,"context['alternative_key'] = data['sku'] |
2957 | +result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
2958 | +mag_1324_erp_soline_uomqty,magento1324,sale.model_sale_order_line,qty_ordered,,in_out,function,unicode,,"result=[('product_uom_qty',ifield)]", |
2959 | +mag_1324_erp_soline_uosqty,magento1324,sale.model_sale_order_line,qty_ordered,,in,function,unicode,,"result=[('product_uos_qty',ifield)]", |
2960 | +mag_1324_erp_soline_price,magento1324,sale.model_sale_order_line,price,,in,function,unicode,,"if context.get('price_is_tax_included', False): |
2961 | +>>>>>>> MERGE-SOURCE |
2962 | result=[('price_unit', (float(data['row_total']) + float(data['tax_amount']))/float(data['qty_ordered']))] |
2963 | else: |
2964 | result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]", |
2965 | @@ -60,15 +92,23 @@ |
2966 | "mag_1324_erp_procat_3","magento1324","product.model_product_category","parent_id",,"in_out","function","int",,"record_id = self.pool.get('ir.model.data').search(cr, uid, [('model', '=', self._name), ('name', '=', self.prefixed_id(ifield))]) |
2967 | parent_id = False |
2968 | if record_id: |
2969 | - parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[]) |
2970 | - parent_id=parent_rec.get('res_id',False) |
2971 | + parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[]) |
2972 | + parent_id=parent_rec.get('res_id',False) |
2973 | result=[('magento_parent_id',ifield),('parent_id',parent_id)]","magento_parent_id = False |
2974 | if record.get('parent_id',False): |
2975 | +<<<<<<< TREE |
2976 | magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], referential_id) |
2977 | if not magento_parent_id: |
2978 | self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[referential_id],{},context=context) |
2979 | magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], referential_id) |
2980 | +======= |
2981 | + magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) |
2982 | + if not magento_parent_id: |
2983 | + self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[external_referential_id],{},context=context) |
2984 | + magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) |
2985 | +>>>>>>> MERGE-SOURCE |
2986 | if magento_parent_id: |
2987 | +<<<<<<< TREE |
2988 | result = [('parent_id',magento_parent_id)]" |
2989 | "mag_1324_erp_procat_4","magento1324","product.model_product_category","is_active",,"in_out","function","unicode",,"result=[('is_active',ifield and (eval(ifield)) or False)]","result=[('is_active',record['is_active'])]" |
2990 | "mag_1324_erp_procat_5","magento1324","product.model_product_category","description",,"in_out","function","unicode",,"result=[('description',ifield)]","result=[('description',record['description'])]" |
2991 | @@ -76,6 +116,15 @@ |
2992 | "mag_1324_erp_procat_7","magento1324","product.model_product_category","meta_keywords",,"in_out","function","unicode",,"result=[('meta_keywords',ifield)]","result=[('meta_keywords',record['meta_keywords'])]" |
2993 | "mag_1324_erp_procat_8","magento1324","product.model_product_category","meta_description",,"in_out","function","unicode",,"result=[('meta_description',ifield)]","result=[('meta_description',record['meta_description'])]" |
2994 | "mag_1324_erp_procat_9","magento1324","product.model_product_category","url_key",,"in_out","function","unicode",,"result=[('url_key',ifield)]","if context.get('export_url', False) : |
2995 | +======= |
2996 | + result = [('parent_id',magento_parent_id)]" |
2997 | +mag_1324_erp_procat_4,magento1324,product.model_product_category,is_active,,in_out,function,unicode,,"result=[('is_active',ifield and (eval(ifield)) or False)]","result=[('is_active',record['is_active'])]" |
2998 | +mag_1324_erp_procat_5,magento1324,product.model_product_category,description,,in_out,function,unicode,,"result=[('description',ifield)]","result=[('description',record['description'])]" |
2999 | +mag_1324_erp_procat_6,magento1324,product.model_product_category,meta_title,,in_out,function,unicode,,"result=[('meta_title',ifield)]","result=[('meta_title',record['meta_title'])]" |
3000 | +mag_1324_erp_procat_7,magento1324,product.model_product_category,meta_keywords,,in_out,function,unicode,,"result=[('meta_keywords',ifield)]","result=[('meta_keywords',record['meta_keywords'])]" |
3001 | +mag_1324_erp_procat_8,magento1324,product.model_product_category,meta_description,,in_out,function,unicode,,"result=[('meta_description',ifield)]","result=[('meta_description',record['meta_description'])]" |
3002 | +mag_1324_erp_procat_9,magento1324,product.model_product_category,url_key,,in_out,function,unicode,,"result=[('url_key',ifield)]","if context.get('export_url', False) : |
3003 | +>>>>>>> MERGE-SOURCE |
3004 | result=[('url_key',record['url_key'])]" |
3005 | "mag_1324_erp_procat_10","magento1324","product.model_product_category","name",,"in_out","function","unicode",,"result=[('name',ifield or 'UNDEFINED'),('magento_exportable',True)]","result=[('name',record['name'])]" |
3006 | "mag_1324_erp_procat_11","magento1324","product.model_product_category","is_anchor",,"in_out","function","unicode",,"result=[('is_anchor',ifield and bool(eval(ifield)) or False)]","result=[('is_anchor',record['is_anchor'])]" |
3007 | @@ -97,30 +146,44 @@ |
3008 | att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'sort_by', context=context) |
3009 | else: |
3010 | att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, 'None','sort_by', context=context) |
3011 | -result=[('default_sort_by',att_id)]","cat_attr_option = self.pool.get('magerp.product_category_attribute_options').browse(cr, uid, record['default_sort_by'][0], context=context) |
3012 | +result=[('default_sort_by',att_id)]","options_obj = self.pool.get('magerp.product_category_attribute_options') |
3013 | +cat_attr_option_id = record['default_sort_by'] |
3014 | +if cat_attr_option_id: |
3015 | + cat_attr_option_id = cat_attr_option_id[0] |
3016 | +else: |
3017 | + cat_attr_option_id = options_obj._get_default_option(cr, uid, 'sort_by', 'None', context=context) |
3018 | + |
3019 | +cat_attr_option = options_obj.browse(cr, uid, cat_attr_option_id, context=context) |
3020 | result=[('default_sort_by', cat_attr_option.value)]" |
3021 | "mag_1324_erp_procat_14","magento1324","product.model_product_category","updated_at",,"in","function","unicode",,"result=[('magerp_stamp',ifield)]", |
3022 | "mag_1324_erp_procat_15","magento1324","product.model_product_category","image",,"in_out","function","unicode",,"image_binary = False |
3023 | if ifield and not ifield=='None': |
3024 | - try: |
3025 | - image_binary = conn.call('ol_catalog_category_media.info', [int(data['category_id'])]) |
3026 | - except Exception, e: |
3027 | - print e |
3028 | - pass |
3029 | - if image_binary: |
3030 | - image_binary = base64.encodestring(base64.urlsafe_b64decode(image_binary[0]['image_data'])) |
3031 | + try: |
3032 | + image_binary = conn.call('ol_catalog_category_media.info', [int(data['category_id'])]) |
3033 | + except Exception, e: |
3034 | + print e |
3035 | + pass |
3036 | + if image_binary: |
3037 | + image_binary = base64.encodestring(base64.urlsafe_b64decode(image_binary[0]['image_data'])) |
3038 | result=[('image_name',ifield),('image',image_binary)]","if record['image']: |
3039 | - img = base64.decodestring(record['image']) |
3040 | - img_bin_enc = base64.encodestring(img) |
3041 | - conn.call('ol_catalog_category_media.create', [record['image_name'], img_bin_enc]) |
3042 | - result = [('image',record['image_name'])] |
3043 | + img = base64.decodestring(record['image']) |
3044 | + img_bin_enc = base64.encodestring(img) |
3045 | + conn.call('ol_catalog_category_media.create', [record['image_name'], img_bin_enc]) |
3046 | + result = [('image',record['image_name'])] |
3047 | else: |
3048 | +<<<<<<< TREE |
3049 | result=[]" |
3050 | "mag_1324_erp_procat_16","magento1324","product.model_product_category","include_in_menu",,"in_out","function","unicode",,"result=[('include_in_menu', ifield and (eval(ifield)) or False)]","result=[('include_in_menu',record['include_in_menu'])]" |
3051 | "mag_1324_erp_procat_17","magento1324","product.model_product_category","page_layout",,"in_out","function","unicode",,"if ifield: |
3052 | +======= |
3053 | + result=[]" |
3054 | +mag_1324_erp_procat_16,magento1324,product.model_product_category,include_in_menu,,in_out,function,unicode,,"result=[('include_in_menu', ifield and (eval(ifield)) or False)]","result=[('include_in_menu',record['include_in_menu'])]" |
3055 | +mag_1324_erp_procat_17,magento1324,product.model_product_category,page_layout,,in_out,function,unicode,,"if ifield: |
3056 | +>>>>>>> MERGE-SOURCE |
3057 | att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'page_layout', context=context) |
3058 | else: |
3059 | att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, 'None','page_layout', context=context) |
3060 | +<<<<<<< TREE |
3061 | result=[('page_layout',att_id)]","result=[('page_layout', record['page_layout'][1] or '')]" |
3062 | "mag_1324_erp_attrgrp_2","magento1324","model_magerp_product_attribute_groups","attribute_set_id",,"in_out","function","int",,"result=[('attribute_set_id', ifield)]","result=[('attribute_set_id', record['attribute_set_id'])]" |
3063 | "mag_1324_erp_attrgrp_3","magento1324","model_magerp_product_attribute_groups","attribute_group_name",,"in_out","function","unicode",,"result=[('attribute_group_name', ifield)]","result=[('attribute_group_name', record['attribute_group_name'])]" |
3064 | @@ -155,6 +218,43 @@ |
3065 | "mag_1324_erp_attr_24","magento1324","model_magerp_product_attributes","entity_type_id",,"in_out","function","int",,"result=[('entity_type_id', ifield)]","result=[('entity_type_id', record['entity_type_id'])]" |
3066 | "mag_1324_erp_attr_25","magento1324","model_magerp_product_attributes","apply_to",,"in_out","function","unicode",,"result=[('apply_to', str(ifield))]","result=[('apply_to', eval(record['%s']))]" |
3067 | "mag_1324_erp_prd_1","magento1324","product.model_product_product","url_key",,"in_out","function","unicode",,"result=[('x_magerp_url_key',ifield)]","if context.get('export_url', False) : |
3068 | +======= |
3069 | +result=[('page_layout',att_id)]","page_layout = record['page_layout'] and record['page_layout'][1] or '' |
3070 | +result=[('page_layout', page_layout)]" |
3071 | +mag_1324_erp_attrgrp_2,magento1324,model_magerp_product_attribute_groups,attribute_set_id,,in_out,function,int,,"result=[('attribute_set_id', ifield)]","result=[('attribute_set_id', record['attribute_set_id'])]" |
3072 | +mag_1324_erp_attrgrp_3,magento1324,model_magerp_product_attribute_groups,attribute_group_name,,in_out,function,unicode,,"result=[('attribute_group_name', ifield)]","result=[('attribute_group_name', record['attribute_group_name'])]" |
3073 | +mag_1324_erp_attrgrp_4,magento1324,model_magerp_product_attribute_groups,sort_order,,in_out,function,int,,"result=[('sort_order', ifield)]","result=[('sort_order', record['sort_order'])]" |
3074 | +mag_1324_erp_attrgrp_5,magento1324,model_magerp_product_attribute_groups,default_id,,in_out,function,int,,"result=[('default_id', ifield)]","result=[('default_id', record['default_id'])]" |
3075 | +mag_1324_erp_attrset_1,magento1324,model_magerp_product_attribute_set,attribute_set_id,,in_out,function,int,,"result=[('magento_id', ifield)]","result=[('attribute_set_id', record['magento_id'])]" |
3076 | +mag_1324_erp_attrset_2,magento1324,model_magerp_product_attribute_set,sort_order,,in_out,function,int,,"result=[('sort_order', ifield)]","result=[('sort_order', record['sort_order'])]" |
3077 | +mag_1324_erp_attrset_3,magento1324,model_magerp_product_attribute_set,attribute_set_name,,in_out,function,unicode,,"result=[('attribute_set_name', ifield)]","result=[('attribute_set_name', record['attribute_set_name'])]" |
3078 | +mag_1324_erp_attr_1,magento1324,model_magerp_product_attributes,attribute_code,,in_out,function,unicode,,"result=[('attribute_code', ifield)]","result=[('code', record['attribute_code'])]" |
3079 | +mag_1324_erp_attr_2,magento1324,model_magerp_product_attributes,attribute_id,,in_out,function,int,,"result=[('magento_id', ifield)]", |
3080 | +mag_1324_erp_attr_3,magento1324,model_magerp_product_attributes,frontend_input,,in_out,function,unicode,,"result=[('frontend_input', ifield)]","result=[('frontend_input', record['frontend_input'])]" |
3081 | +mag_1324_erp_attr_4,magento1324,model_magerp_product_attributes,frontend_class,,in_out,function,unicode,,"result=[('frontend_class', ifield)]","result=[('frontend_class', record['frontend_class'])]" |
3082 | +mag_1324_erp_attr_5,magento1324,model_magerp_product_attributes,backend_model,,in_out,function,unicode,,"result=[('backend_model', ifield)]","result=[('backend_model', record['backend_model'])]" |
3083 | +mag_1324_erp_attr_6,magento1324,model_magerp_product_attributes,backend_type,,in_out,function,unicode,,"result=[('backend_type', ifield)]","result=[('backend_type', record['backend_type'])]" |
3084 | +mag_1324_erp_attr_7,magento1324,model_magerp_product_attributes,frontend_label,,in_out,function,unicode,,"result=[('frontend_label', ifield)]","result=[('frontend_label', record['frontend_label'])]" |
3085 | +mag_1324_erp_attr_8,magento1324,model_magerp_product_attributes,is_visible_in_advanced_search,,in_out,function,unicode,,"result=[('is_visible_in_advanced_search', bool(eval(ifield)))]","result=[('is_visible_in_advanced_search', record['is_visible_in_advanced_search'])]" |
3086 | +mag_1324_erp_attr_9,magento1324,model_magerp_product_attributes,is_global,,in_out,function,unicode,,"result=[('is_global', bool(eval(ifield)))]","result=[('is_global', record['is_global'])]" |
3087 | +mag_1324_erp_attr_10,magento1324,model_magerp_product_attributes,is_filterable,,in_out,function,unicode,,"result=[('is_filterable', bool(eval(ifield)))]","result=[('is_filterable', record['is_filterable'])]" |
3088 | +mag_1324_erp_attr_11,magento1324,model_magerp_product_attributes,is_comparable,,in_out,function,unicode,,"result=[('is_comparable', bool(eval(ifield)))]","result=[('is_comparable', record['is_comparable'])]" |
3089 | +mag_1324_erp_attr_12,magento1324,model_magerp_product_attributes,is_visible,,in_out,function,unicode,,"result=[('is_visible', bool(eval(ifield)))]","result=[('is_visible', record['is_visible'])]" |
3090 | +mag_1324_erp_attr_13,magento1324,model_magerp_product_attributes,is_searchable,,in_out,function,unicode,,"result=[('is_searchable', bool(eval(ifield)))]","result=[('is_searchable', record['is_searchable'])]" |
3091 | +mag_1324_erp_attr_14,magento1324,model_magerp_product_attributes,is_user_defined,,in_out,function,unicode,,"result=[('is_user_defined', bool(eval(ifield)))]","result=[('is_user_defined', record['is_user_defined'])]" |
3092 | +mag_1324_erp_attr_15,magento1324,model_magerp_product_attributes,is_configurable,,in_out,function,unicode,,"result=[('is_configurable', bool(eval(ifield)))]","result=[('is_configurable', record['is_configurable'])]" |
3093 | +mag_1324_erp_attr_16,magento1324,model_magerp_product_attributes,is_visible_on_front,,in_out,function,unicode,,"result=[('is_visible_on_front', bool(eval(ifield)))]","result=[('is_visible_on_front', record['is_visible_on_front'])]" |
3094 | +mag_1324_erp_attr_17,magento1324,model_magerp_product_attributes,is_used_for_price_rules,,in_out,function,unicode,,"result=[('is_used_for_price_rules', bool(eval(ifield)))]","result=[('is_used_for_price_rules', record['is_used_for_price_rules'])]" |
3095 | +mag_1324_erp_attr_18,magento1324,model_magerp_product_attributes,is_unique,,in_out,function,unicode,,"result=[('is_unique', bool(eval(ifield)))]","result=[('is_unique', record['is_unique'])]" |
3096 | +mag_1324_erp_attr_19,magento1324,model_magerp_product_attributes,is_required,,in_out,function,unicode,,"result=[('is_required', bool(eval(ifield)))]","result=[('is_required', record['is_required'])]" |
3097 | +mag_1324_erp_attr_20,magento1324,model_magerp_product_attributes,position,,in_out,function,int,,"result=[('position', ifield)]","result=[('position', record['position'])]" |
3098 | +mag_1324_erp_attr_21,magento1324,model_magerp_product_attributes,attribute_set_info,,in_out,function,unicode,,"result=[('attribute_set_info', ifield)]","result=[('attribute_set_info', record['attribute_set_info'])]" |
3099 | +mag_1324_erp_attr_22,magento1324,model_magerp_product_attributes,default_value,,in_out,function,unicode,,"result=[('default_value', ifield)]","result=[('default_value', record['default_value'])]" |
3100 | +mag_1324_erp_attr_23,magento1324,model_magerp_product_attributes,note,,in_out,function,unicode,,"result=[('note', ifield)]","result=[('note', record['note'])]" |
3101 | +mag_1324_erp_attr_24,magento1324,model_magerp_product_attributes,entity_type_id,,in_out,function,int,,"result=[('entity_type_id', ifield)]","result=[('entity_type_id', record['entity_type_id'])]" |
3102 | +mag_1324_erp_attr_25,magento1324,model_magerp_product_attributes,apply_to,,in_out,function,unicode,,"result=[('apply_to', str(ifield))]","result=[('apply_to', eval(record['%s']))]" |
3103 | +mag_1324_erp_prd_1,magento1324,product.model_product_product,url_key,,in_out,function,unicode,,"result=[('x_magerp_url_key',ifield)]","if context.get('export_url', False) : |
3104 | +>>>>>>> MERGE-SOURCE |
3105 | result=[('url_key',record['x_magerp_url_key'])]" |
3106 | "mag_1324_erp_prd_2","magento1324","product.model_product_product","name",,"in_out","function","unicode",,"result = [('name',ifield)]","result = [('name',record['name'])]" |
3107 | "mag_1324_erp_prd_3","magento1324","product.model_product_product","description",,"in_out","function","unicode",,"result = [('description',ifield)]", |
3108 | @@ -164,13 +264,18 @@ |
3109 | "mag_1324_erp_prd_7","magento1324","product.model_product_product","category_ids",,"in_out","function","list",,"categ_ids =[] |
3110 | if ifield and len(ifield) > 0: |
3111 | for category_ids in ifield: |
3112 | +<<<<<<< TREE |
3113 | categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, external_session, category_ids, referential_id)) |
3114 | +======= |
3115 | + categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, category_ids, external_referential_id, context=context)) |
3116 | +>>>>>>> MERGE-SOURCE |
3117 | categ_id = categ_ids.pop() |
3118 | else: |
3119 | categ_id = self.pool.get('external.referential').browse(cr, uid, referential_id).default_pro_cat.id |
3120 | result = [('categ_id', categ_id), ('categ_ids',[(6, 0, categ_ids)])]"," |
3121 | cat_obj = self.pool.get('product.category') |
3122 | product = self.browse(cr, uid, record['id']) |
3123 | +<<<<<<< TREE |
3124 | categ_ids = [product.categ_id.id] + [categ.id for categ in product.categ_ids] |
3125 | mag_categ_ids = [] |
3126 | for categ_id in categ_ids: |
3127 | @@ -186,6 +291,23 @@ |
3128 | "mag_1324_erp_prd_11","magento1324","product.model_product_product","special_price",,"in_out","function","float",,"result = [('x_magerp_special_price',ifield)]", |
3129 | "mag_1324_erp_prd_12","magento1324","product.model_product_product","tier_price",,"in_out","function","unicode",,"result=[]#no mapping by default","result=[]#no mapping by default" |
3130 | "mag_1324_erp_prd_13","magento1324","product.model_product_product","minimal_price",,"in_out","function","float",,"result = [('x_magerp_minimal_price',ifield)]"," |
3131 | +======= |
3132 | +categ_ids = [categ.id for categ in ([product.categ_id] + product.categ_ids) if categ.magento_exportable] |
3133 | +mag_categ_ids = [] |
3134 | +for categ_id in categ_ids: |
3135 | + mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id) |
3136 | + if not mag_categ_id: |
3137 | + cat_obj.ext_export(cr, uid, [categ_id], [external_referential_id], context=context) |
3138 | + mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id) |
3139 | + mag_categ_ids.append(mag_categ_id) |
3140 | +result=[('category_ids', mag_categ_ids)]" |
3141 | +mag_1324_erp_prd_8,magento1324,product.model_product_product,price,,in_out,function,float,,"result=[('list_price',ifield)]",result=[]#map later |
3142 | +mag_1324_erp_prd_9,magento1324,product.model_product_product,cost,,in_out,function,float,,"result=[('standard_price',ifield)]","result = [('cost',record['standard_price'] or 0)]" |
3143 | +mag_1324_erp_prd_10,magento1324,product.model_product_product,set,,in_out,function,unicode,,"result=[('set',self.pool.get('magerp.product_attribute_set').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
3144 | +mag_1324_erp_prd_11,magento1324,product.model_product_product,special_price,,in_out,function,float,,"result = [('x_magerp_special_price',ifield)]", |
3145 | +mag_1324_erp_prd_12,magento1324,product.model_product_product,tier_price,,in_out,function,unicode,,result=[]#no mapping by default,result=[]#no mapping by default |
3146 | +mag_1324_erp_prd_13,magento1324,product.model_product_product,minimal_price,,in_out,function,float,,"result = [('x_magerp_minimal_price',ifield)]"," |
3147 | +>>>>>>> MERGE-SOURCE |
3148 | if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0: |
3149 | result = [('minimal_price',record['x_magerp_minimal_price'])] |
3150 | else: |
3151 | @@ -199,7 +321,11 @@ |
3152 | result = [('type_id','simple')]" |
3153 | "mag_1324_erp_prd_15","magento1324","product.model_product_product","websites",,"in_out","function","list",,"websites_ids = [] |
3154 | for ext_id in ifield: |
3155 | +<<<<<<< TREE |
3156 | websites_ids.append(self.pool.get('external.shop.group').extid_to_oeid(cr, uid, external_session, ext_id, context=context)) |
3157 | +======= |
3158 | + websites_ids.append(self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ext_id, external_referential_id, context=context)) |
3159 | +>>>>>>> MERGE-SOURCE |
3160 | |
3161 | ##### OPTION START, with this if the field websites of the product is empty the product is exported on every website |
3162 | all_oe_websites_ids = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', referential_id)]) |
3163 | @@ -217,6 +343,7 @@ |
3164 | ext_websites_ids.append(self.pool.get('external.shop.group').oeid_to_extid(cr, uid, oe_id, referential_id)) |
3165 | |
3166 | result=[('websites', ext_websites_ids)]" |
3167 | +<<<<<<< TREE |
3168 | "mag_1324_erp_prd_16","magento1324","product.model_product_product","has_options",,"in","function","unicode",,"result =[('x_magerp_has_options',ifield)]", |
3169 | "magento_1324_cst_grp_1","magento1324","base.model_res_partner_category","customer_group_code",,"in","function","unicode",,"result=[('name',ifield)]", |
3170 | "magento_1324_cst_grp_3","magento1324","base.model_res_partner_category","tax_class_id",,"in","function","int",,"result=[('tax_class_id',ifield)]", |
3171 | @@ -225,17 +352,39 @@ |
3172 | "magento_1324_prt_adr_4","magento1324","base.model_res_partner_address","firstname",,"in_out","function","unicode",,"result = [('name', (data.get('company', False) and (data['company'] + ' ; ') or '') + ifield + ' ' + (data['lastname'] or '')), ('firstname', ifield), ('lastname', (data['lastname'] or ''))]", |
3173 | "magento_1324_prt_adr_6","magento1324","base.model_res_partner_address","is_active",,"in_out","function","unicode",,"result=[('active',bool(eval(ifield)))]", |
3174 | "magento_1324_prt_adr_7","magento1324","base.model_res_partner_address","country_id",,"in_out","function","unicode",,"result = self.pool.get('res.country').search(cr,uid,[('code','=',ifield)]) |
3175 | +======= |
3176 | +mag_1324_erp_prd_16,magento1324,product.model_product_product,has_options,,in,function,unicode,,"result =[('x_magerp_has_options',ifield)]", |
3177 | +magento_1324_cst_grp_1,magento1324,base.model_res_partner_category,customer_group_code,,in,function,unicode,,"result=[('name',ifield)]", |
3178 | +magento_1324_cst_grp_3,magento1324,base.model_res_partner_category,tax_class_id,,in,function,int,,"result=[('tax_class_id',ifield)]", |
3179 | +magento_1324_prt_adr_2,magento1324,base.model_res_partner_address,city,,in_out,function,unicode,,"result=[('city',ifield)]", |
3180 | +magento_1324_prt_adr_3,magento1324,base.model_res_partner_address,fax,,in_out,function,unicode,,"result=[('fax',ifield)]", |
3181 | +magento_1324_prt_adr_4,magento1324,base.model_res_partner_address,firstname,,in_out,function,unicode,,"name = ' '.join([ f for f in (data['firstname'], data['lastname']) if f]) |
3182 | +if data.get('company'): |
3183 | + name = ""%s ; %s"" % (data['company'], name) |
3184 | +result = [('name', name), ('firstname', ifield), ('lastname', data['lastname'])]", |
3185 | +magento_1324_prt_adr_6,magento1324,base.model_res_partner_address,is_active,,in_out,function,unicode,,"result=[('active',bool(eval(ifield)))]", |
3186 | +magento_1324_prt_adr_7,magento1324,base.model_res_partner_address,country_id,,in_out,function,unicode,,"result = self.pool.get('res.country').search(cr,uid,[('code','=',ifield)]) |
3187 | +>>>>>>> MERGE-SOURCE |
3188 | if result and len(result)==1: |
3189 | - result=[('country_id',result[0])] |
3190 | + result=[('country_id',result[0])] |
3191 | else: |
3192 | - result=[] |
3193 | + result=[] |
3194 | ", |
3195 | +<<<<<<< TREE |
3196 | "magento_1324_prt_adr_8","magento1324","base.model_res_partner_address","street",,"in_out","function","unicode",,"if ifield: |
3197 | if len(ifield.split('\n')) ==2 : |
3198 | result = [('street', ifield.split('\n')[0]) , ('street2', ifield.split('\n')[1])] |
3199 | else : |
3200 | result = [('street',ifield.replace('\\n',','))] |
3201 | +======= |
3202 | +magento_1324_prt_adr_8,magento1324,base.model_res_partner_address,street,,in_out,function,unicode,,"if ifield: |
3203 | + if len(ifield.split('\n')) ==2 : |
3204 | + result = [('street', ifield.split('\n')[0]) , ('street2', ifield.split('\n')[1])] |
3205 | + else : |
3206 | + result = [('street',ifield.replace('\\n',','))] |
3207 | +>>>>>>> MERGE-SOURCE |
3208 | else: |
3209 | +<<<<<<< TREE |
3210 | result = []", |
3211 | "magento_1324_prt_adr_9","magento1324","base.model_res_partner_address","postcode",,"in_out","function","unicode",,"result=[('zip',ifield)]", |
3212 | "magento_1324_prt_adr_10","magento1324","base.model_res_partner_address","telephone",,"in_out","function","unicode",,"result=[('phone',ifield)]", |
3213 | @@ -245,16 +394,39 @@ |
3214 | result = [('state_id',result[0])] |
3215 | else: |
3216 | result=[] |
3217 | +======= |
3218 | + result = []", |
3219 | +magento_1324_prt_adr_9,magento1324,base.model_res_partner_address,postcode,,in_out,function,unicode,,"result=[('zip',ifield)]", |
3220 | +magento_1324_prt_adr_10,magento1324,base.model_res_partner_address,telephone,,in_out,function,unicode,,"result=[('phone',ifield)]", |
3221 | +magento_1324_prt_adr_11,magento1324,base.model_res_partner_address,region,,in_out,function,unicode,,"if ifield: |
3222 | + result = self.pool.get('res.country.state').search(cr,uid,[('name','=ilike',ifield)]) |
3223 | + if result and len(result)==1: |
3224 | + result = [('state_id',result[0])] |
3225 | + else: |
3226 | + result=[] |
3227 | +>>>>>>> MERGE-SOURCE |
3228 | else: |
3229 | +<<<<<<< TREE |
3230 | result=[]", |
3231 | "magento_1324_prt_adr_13","magento1324","base.model_res_partner_address","customer_id",,"in_out","function","int",,"result=self.pool.get('res.partner').extid_to_oeid(cr,uid,ifield,referential_id) |
3232 | +======= |
3233 | + result=[]", |
3234 | +magento_1324_prt_adr_13,magento1324,base.model_res_partner_address,customer_id,,in_out,function,int,,"result=self.pool.get('res.partner').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
3235 | +>>>>>>> MERGE-SOURCE |
3236 | if result: |
3237 | - result=[('partner_id',result)] |
3238 | + result=[('partner_id',result)] |
3239 | else: |
3240 | +<<<<<<< TREE |
3241 | result=[('partner_id',False)]", |
3242 | "magento_1324_prt_adr_14","magento1324","base.model_res_partner_address","address_type",,"in_out","function","unicode",,"if ifield=='billing': |
3243 | result=[('type','invoice')] |
3244 | +======= |
3245 | + result=[('partner_id',False)]", |
3246 | +magento_1324_prt_adr_14,magento1324,base.model_res_partner_address,address_type,,in_out,function,unicode,,"if ifield=='billing': |
3247 | + result=[('type','invoice')] |
3248 | +>>>>>>> MERGE-SOURCE |
3249 | elif ifield=='shipping': |
3250 | +<<<<<<< TREE |
3251 | result=[('type','delivery')] |
3252 | else: |
3253 | result=[]", |
3254 | @@ -276,15 +448,67 @@ |
3255 | "magento_1324_prt_6","magento1324","base.model_res_partner","created_at",,"in_out","function","unicode",,"result=[('created_at',ifield)]", |
3256 | "magento_1324_prt_7","magento1324","base.model_res_partner","updated_at",,"in_out","function","unicode",,"result=[('updated_at',ifield)]", |
3257 | "magento_1324_prt_8","magento1324","base.model_res_partner","firstname",,"in_out","function","unicode",,"result = [('name', ifield + ' ' + data['lastname'])]","add_id = self.browse(cr, uid, record['id']) |
3258 | +======= |
3259 | + result=[('type','delivery')] |
3260 | +else: |
3261 | + result=[]", |
3262 | +magento_1324_prt_adr_15,magento1324,base.model_res_partner_address,email,,in_out,function,unicode,,"result = [('email', False)] |
3263 | +if ifield: |
3264 | + result = [('email', ifield)] |
3265 | +else: |
3266 | + partner_obj = self.pool.get('res.partner') |
3267 | + partner_id = partner_obj.extid_to_existing_oeid(cr, uid, data['customer_id'] ,external_referential_id) |
3268 | + if partner_id: |
3269 | + result = [('email', partner_obj.browse(cr, uid, partner_id).emailid)]", |
3270 | +magento_1324_prt_adr_17,magento1324,base.model_res_partner_address,default_billing,,in_out,function,unicode,,"result = [('type', 'other')] |
3271 | +if data.get('default_billing') and data.get('default_shipping'): |
3272 | + result = [('type', 'default')] |
3273 | +elif data.get('default_billing'): |
3274 | + result = [('type', 'invoice')] |
3275 | +elif data.get('default_shipping'): |
3276 | + result = [('type', 'delivery')]", |
3277 | +magento_1324_prt_2,magento1324,base.model_res_partner,group_id,,in_out,function,int,,"if ifield: |
3278 | + result=self.pool.get('res.partner.category').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
3279 | + if result: |
3280 | + result=[('group_id',result)]", |
3281 | +magento_1324_prt_3,magento1324,base.model_res_partner,store_id,,in_out,function,int,,"if ifield: |
3282 | + result=self.pool.get('magerp.storeviews').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
3283 | + if result: |
3284 | + store = self.pool.get('magerp.storeviews').browse(cr, uid, result) |
3285 | + lang = store.lang_id |
3286 | + result=[('store_id',result),('lang',lang and lang.code or False)] |
3287 | + if not data.get('website_id'): |
3288 | + result.append(('website_id', store.website_id.id))", |
3289 | +magento_1324_prt_4,magento1324,base.model_res_partner,website_id,,in_out,function,int,,"if ifield: |
3290 | + result=self.pool.get('external.shop.group').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
3291 | + if result: |
3292 | + result=[('website_id',result)]", |
3293 | +magento_1324_prt_5,magento1324,base.model_res_partner,created_in,,in_out,function,unicode,,"result=[('created_in',ifield)]", |
3294 | +magento_1324_prt_6,magento1324,base.model_res_partner,created_at,,in_out,function,unicode,,"result=[('created_at',ifield)]", |
3295 | +magento_1324_prt_7,magento1324,base.model_res_partner,updated_at,,in_out,function,unicode,,"result=[('updated_at',ifield)]", |
3296 | +magento_1324_prt_8,magento1324,base.model_res_partner,firstname,,in_out,function,unicode,,"result = [('name', ifield + ' ' + data['lastname'])]","add_id = self.browse(cr, uid, record['id']) |
3297 | +>>>>>>> MERGE-SOURCE |
3298 | fn = add_id.address[0].firstname |
3299 | ln = add_id.address[0].lastname |
3300 | result=[('firstname', fn), ('lastname', ln)]" |
3301 | +<<<<<<< TREE |
3302 | "magento_1324_prt_10","magento1324","base.model_res_partner","email",,"in_out","function","unicode",,"result=[('emailid',ifield)]", |
3303 | "magento_1324_prt_11","magento1324","base.model_res_partner","taxvat",,"in_out","function","unicode",,"if ifield: |
3304 | result=[('mag_vat',ifield)] |
3305 | +======= |
3306 | +magento_1324_prt_10,magento1324,base.model_res_partner,email,,in_out,function,unicode,,"result=[('emailid',ifield)]", |
3307 | +magento_1324_prt_11,magento1324,base.model_res_partner,taxvat,,in_out,function,unicode,,"if ifield: |
3308 | + result=[('mag_vat',ifield)] |
3309 | +>>>>>>> MERGE-SOURCE |
3310 | else: |
3311 | +<<<<<<< TREE |
3312 | result=[]", |
3313 | "magento_1324_prt_12","magento1324","base.model_res_partner","dob",,"in_out","function","unicode",,"if ifield: |
3314 | result =[('mag_birthday',ifield[:10])] |
3315 | +======= |
3316 | + result=[]", |
3317 | +magento_1324_prt_12,magento1324,base.model_res_partner,dob,,in_out,function,unicode,,"if ifield: |
3318 | + result =[('mag_birthday',ifield[:10])] |
3319 | +>>>>>>> MERGE-SOURCE |
3320 | else: |
3321 | - result=[]", |
3322 | + result=[]", |
3323 | |
3324 | === added directory 'magentoerpconnect/settings/1.4.0.0' |
3325 | === added file 'magentoerpconnect/settings/1.4.0.0/external.mapping.template.csv' |
3326 | --- magentoerpconnect/settings/1.4.0.0/external.mapping.template.csv 1970-01-01 00:00:00 +0000 |
3327 | +++ magentoerpconnect/settings/1.4.0.0/external.mapping.template.csv 2012-07-06 14:53:18 +0000 |
3328 | @@ -0,0 +1,14 @@ |
3329 | +"id","type_id:id","model_id:id","external_list_method","external_get_method","external_update_method","external_create_method","external_delete_method","external_key_name" |
3330 | +"magento_1400_website","magento1400","base_sale_multichannels.model_external_shop_group","ol_websites.list",,,,,"website_id" |
3331 | +"magento_1400_storeview","magento1400","model_magerp_storeviews","ol_storeviews.list",,,,,"store_id" |
3332 | +"magento_1400_store","magento1400","sale.model_sale_shop","ol_groups.list",,,,,"group_id" |
3333 | +"magento_1400_order","magento1400","sale.model_sale_order","sales_order.list","sales_order.info",,,,"increment_id" |
3334 | +"magento_1400_order_line","magento1400","sale.model_sale_order_line",,,,,,"item_id" |
3335 | +"magento_1400_pro_cat","magento1400","product.model_product_category","category.list","category.info","catalog_category.update","catalog_category.create",,"category_id" |
3336 | +"magento_1400_attr_grp","magento1400","model_magerp_product_attribute_groups","ol_catalog_product_attribute_group.list","ol_catalog_product_attribute_group.list",,,,"attribute_group_id" |
3337 | +"magento_1400_attr_set","magento1400","model_magerp_product_attribute_set","ol_catalog_product_attributeset.list",,,,,"attribute_set_id" |
3338 | +"magento_1400_attr","magento1400","model_magerp_product_attributes","ol_catalog_product_attribute.list",,,,,"attribute_id" |
3339 | +"magento_1400_prd","magento1400","product.model_product_product","catalog_product.list","catalog_product.info","ol_catalog_product.update","ol_catalog_product.create",,"product_id" |
3340 | +"magento_1400_cst_grp","magento1400","base.model_res_partner_category","ol_customer_groups.list",,,,,"customer_group_id" |
3341 | +"magento_1400_prt_adr","magento1400","base.model_res_partner_address","ol_customer_address.list","ol_customer_address.info",,,,"entity_id" |
3342 | +"magento_1400_prt","magento1400","base.model_res_partner","customer.list","customer.info","customer.update",,,"customer_id" |
3343 | |
3344 | === added file 'magentoerpconnect/settings/1.4.0.0/external.mappinglines.template.csv' |
3345 | --- magentoerpconnect/settings/1.4.0.0/external.mappinglines.template.csv 1970-01-01 00:00:00 +0000 |
3346 | +++ magentoerpconnect/settings/1.4.0.0/external.mappinglines.template.csv 2012-07-06 14:53:18 +0000 |
3347 | @@ -0,0 +1,321 @@ |
3348 | +id,type_id:id,model_id:id,external_field,field_id:id,type,evaluation_type,external_type,child_mapping_id:id,in_function,out_function |
3349 | +mag_1400_erp_s_name,magento1400,base_sale_multichannels.model_external_shop_group,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
3350 | +mag_1400_erp_s_code,magento1400,base_sale_multichannels.model_external_shop_group,code,,in_out,function,unicode,,"result=[('code',ifield)]", |
3351 | +mag_1400_erp_s_web,magento1400,base_sale_multichannels.model_external_shop_group,website_id,,in_out,function,int,,"result=[('website_id',ifield)]", |
3352 | +mag_1400_erp_s_isa,magento1400,base_sale_multichannels.model_external_shop_group,is_default,,in_out,function,unicode,,"result=[('is_default',bool(eval(ifield)))]", |
3353 | +mag_1400_erp_s_stord,magento1400,base_sale_multichannels.model_external_shop_group,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]", |
3354 | +mag_1400_erp_s_gpid,magento1400,base_sale_multichannels.model_external_shop_group,default_group_id,,in_out,function,int,,"result=[('default_shop_integer_id',ifield)]", |
3355 | +mag_1400_erp_sv_name,magento1400,model_magerp_storeviews,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
3356 | +mag_1400_erp_sv_code,magento1400,model_magerp_storeviews,code,,in_out,function,unicode,,"result=[('code',ifield)]", |
3357 | +mag_1400_erp_sv_sg,magento1400,model_magerp_storeviews,website_id,,in_out,function,int,,"result=[('website_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
3358 | +mag_1400_erp_sv_isa,magento1400,model_magerp_storeviews,is_active,,in_out,function,unicode,,"result=[('is_active',bool(eval(ifield)))]", |
3359 | +mag_1400_erp_sv_stord,magento1400,model_magerp_storeviews,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]", |
3360 | +mag_1400_erp_sv_gpid,magento1400,model_magerp_storeviews,group_id,,in_out,function,int,,"result=[('shop_id',self.pool.get('sale.shop').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
3361 | +mag_1400_erp_st_name,magento1400,sale.model_sale_shop,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
3362 | +mag_1400_erp_st_gpid,magento1400,sale.model_sale_shop,group_id,,in_out,function,int,,"result=[('group_id',ifield)]", |
3363 | +mag_1400_erp_st_grp,magento1400,sale.model_sale_shop,website_id,,in_out,function,int,,"result=[('shop_group_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
3364 | +mag_1400_erp_st_default_st,magento1400,sale.model_sale_shop,default_store_id,,in_out,function,int,,"result=[('default_storeview_integer_id',ifield)]", |
3365 | +mag_1400_erp_st_root_categ,magento1400,sale.model_sale_shop,root_category_id,,in_out,function,int,,"result=[('root_category_id',ifield)]", |
3366 | +mag_1400_erp_so_total_amount,magento1400,sale.model_sale_order,grand_total,,in_out,function,float,,"result=[('ext_total_amount',str(ifield))]", |
3367 | +mag_1400_erp_so_name,magento1400,sale.model_sale_order,increment_id,,in_out,function,unicode,,"result=[('magento_incrementid',str(ifield)), ('name','mag_' + str(ifield))]", |
3368 | +mag_1400_erp_so_carrier_id,magento1400,sale.model_sale_order,shipping_method,,in_out,function,unicode,,"if ifield: |
3369 | + carrier_ids = self.pool.get('delivery.carrier').search(cr, uid, [('magento_code', '=', ifield)]) |
3370 | + if carrier_ids: |
3371 | + result=[('carrier_id', carrier_ids[0])] |
3372 | + else: |
3373 | + fake_partner_id = self.pool.get('res.partner').search(cr, uid, [])[0] |
3374 | + model_data_obj = self.pool.get('ir.model.data') |
3375 | + model, product_id = model_data_obj.get_object_reference(cr, uid, 'base_sale_multichannels', 'product_product_shipping') |
3376 | + carrier_id = self.pool.get('delivery.carrier').create(cr, uid, {'partner_id' : fake_partner_id, 'product_id' : product_id, 'name' : ifield, 'magento_code' : ifield}) |
3377 | + result=[('carrier_id', carrier_id)]", |
3378 | +mag_1400_erp_so_pay,magento1400,sale.model_sale_order,payment,,in_out,function,unicode,," |
3379 | +payments_mapping = {'checkmo': 'manual', 'ccsave': 'prepaid', 'free':'prepaid','googlecheckout':'prepaid','paypayl_express':'prepaid', 'paybox_system': 'prepaid', 'paypal_standard': 'prepaid', 'cashondelivery': 'manual', 'servired_standard': 'prepaid', 'bbva': 'prepaid', 'cofidis': 'prepaid'} |
3380 | +ifield=eval(ifield) |
3381 | +result=[('order_policy', ifield['method'] in payments_mapping and payments_mapping[ifield['method']] or 'prepaid'), ('ext_payment_method', ifield['method'])]", |
3382 | +mag_1400_erp_so_item,magento1400,sale.model_sale_order,items,sale.field_sale_order_order_line,in,sub-mapping,dict,magento_1400_order_line,, |
3383 | +"mag_1400_erp_soline_name","magento1400","sale.model_sale_order_line","name",,"in_out","function","unicode",,"result=[('name', ifield)] |
3384 | +", |
3385 | +"mag_1400_erp_soline_note","magento1400","sale.model_sale_order_line","product_options",,"in","function","unicode",,"if ifield: |
3386 | + import re |
3387 | + options_label = [] |
3388 | + clean = re.sub('\w:\w:|\w:\w+;', '', ifield) |
3389 | + for each in clean.split('{'): |
3390 | + if each.startswith('""label""'): |
3391 | + split_info = each.split(';') |
3392 | + options_label.append('%s: %s [%s]' % (split_info[1], split_info[3], data['sku'])) |
3393 | + |
3394 | + result=[('notes', """".join(options_label).replace('""""', '\n').replace('""', ''))] |
3395 | +", |
3396 | +mag_1400_erp_soline_pid,magento1400,sale.model_sale_order_line,product_id,,in_out,function,unicode,,"context['alternative_key'] = data['sku'] |
3397 | +result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
3398 | +mag_1400_erp_soline_uomqty,magento1400,sale.model_sale_order_line,qty_ordered,,in_out,function,unicode,,"result=[('product_uom_qty',ifield)]", |
3399 | +mag_1400_erp_soline_uosqty,magento1400,sale.model_sale_order_line,qty_ordered,,in,function,unicode,,"result=[('product_uos_qty',ifield)]", |
3400 | +mag_1400_erp_soline_price,magento1400,sale.model_sale_order_line,price,,in,function,unicode,,"if context.get('price_is_tax_included', False): |
3401 | + result=[('price_unit', (float(data['row_total']) + float(data['tax_amount']))/float(data['qty_ordered']))] |
3402 | +else: |
3403 | + result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]", |
3404 | +mag_1400_erp_soline_disc,magento1400,sale.model_sale_order_line,discount_amount,,in,function,float,,"if ifield: |
3405 | + result=[('discount', float(data['price']) != 0 and float(data['qty_ordered']) != 0 and float(100*ifield)/(float(data['price'])*float(data['qty_ordered'])) or 0)]", |
3406 | +mag_1400_erp_procat_2,magento1400,product.model_product_category,level,,in,function,int,,"result=[('sequence',ifield),('level',ifield)]", |
3407 | +mag_1400_erp_procat_3,magento1400,product.model_product_category,parent_id,,in_out,function,int,,"record_id = self.pool.get('ir.model.data').search(cr, uid, [('model', '=', self._name), ('name', '=', self.prefixed_id(ifield))]) |
3408 | +parent_id = False |
3409 | +if record_id: |
3410 | + parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[]) |
3411 | + parent_id=parent_rec.get('res_id',False) |
3412 | +result=[('magento_parent_id',ifield),('parent_id',parent_id)]","magento_parent_id = False |
3413 | +if record.get('parent_id',False): |
3414 | + magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) |
3415 | + if not magento_parent_id: |
3416 | + self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[external_referential_id],{},context=context) |
3417 | + magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) |
3418 | +if magento_parent_id: |
3419 | + result = [('parent_id',magento_parent_id)]" |
3420 | +mag_1400_erp_procat_4,magento1400,product.model_product_category,is_active,,in_out,function,unicode,,"result=[('is_active',ifield and (eval(ifield)) or False)]","result=[('is_active',record['is_active'])]" |
3421 | +mag_1400_erp_procat_5,magento1400,product.model_product_category,description,,in_out,function,unicode,,"result=[('description',ifield)]","result=[('description',record['description'])]" |
3422 | +mag_1400_erp_procat_6,magento1400,product.model_product_category,meta_title,,in_out,function,unicode,,"result=[('meta_title',ifield)]","result=[('meta_title',record['meta_title'])]" |
3423 | +mag_1400_erp_procat_7,magento1400,product.model_product_category,meta_keywords,,in_out,function,unicode,,"result=[('meta_keywords',ifield)]","result=[('meta_keywords',record['meta_keywords'])]" |
3424 | +mag_1400_erp_procat_8,magento1400,product.model_product_category,meta_description,,in_out,function,unicode,,"result=[('meta_description',ifield)]","result=[('meta_description',record['meta_description'])]" |
3425 | +mag_1400_erp_procat_9,magento1400,product.model_product_category,url_key,,in_out,function,unicode,,"result=[('url_key',ifield)]","if context.get('export_url', False) : |
3426 | + result=[('url_key',record['url_key'])]" |
3427 | +mag_1400_erp_procat_10,magento1400,product.model_product_category,name,,in_out,function,unicode,,"result=[('name',ifield or 'UNDEFINED'),('magento_exportable',True)]","result=[('name',record['name'])]" |
3428 | +mag_1400_erp_procat_11,magento1400,product.model_product_category,is_anchor,,in_out,function,unicode,,"result=[('is_anchor',ifield and bool(eval(ifield)) or False)]","result=[('is_anchor',record['is_anchor'])]" |
3429 | +mag_1400_erp_procat_12,magento1400,product.model_product_category,available_sort_by,,in_out,function,list,,"attr_ids = [] |
3430 | +cat_attr_obj = self.pool.get('magerp.product_category_attribute_options') |
3431 | +if ifield: |
3432 | + for val in ifield: |
3433 | + attr_ids.append(cat_attr_obj.get_create_option_id(cr, uid, val,'sort_by', context=context)) |
3434 | + result=[('available_sort_by', [(6, 0, attr_ids)]), ('use_default_available_sort_by', False)] |
3435 | +else: |
3436 | + result=[('use_default_available_sort_by', True)]","if record['use_default_available_sort_by']: |
3437 | + res = u'' |
3438 | +else: |
3439 | + res = [] |
3440 | + for cat_attr_option in self.pool.get('magerp.product_category_attribute_options').browse(cr, uid, record['available_sort_by'], context=context): |
3441 | + res.append(cat_attr_option.value) |
3442 | + # comment out the following line if you can run the following SQL query on the Magento database: |
3443 | + # update eav_attribute set is_required = 0 where attribute_code = 'available_sort_by'; |
3444 | + res = u'' |
3445 | +result=[('available_sort_by', res)]" |
3446 | +mag_1400_erp_procat_13,magento1400,product.model_product_category,default_sort_by,,in_out,function,unicode,,"if ifield: |
3447 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'sort_by', context=context) |
3448 | +else: |
3449 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','sort_by', context=context) |
3450 | +result=[('default_sort_by',att_id)]","options_obj = self.pool.get('magerp.product_category_attribute_options') |
3451 | +cat_attr_option_id = record['default_sort_by'] |
3452 | +if cat_attr_option_id: |
3453 | + cat_attr_option_id = cat_attr_option_id[0] |
3454 | +else: |
3455 | + cat_attr_option_id = options_obj._get_default_option(cr, uid, 'sort_by', '', context=context) |
3456 | + |
3457 | +cat_attr_option = options_obj.browse(cr, uid, cat_attr_option_id, context=context) |
3458 | +result=[('default_sort_by', cat_attr_option.value)]" |
3459 | +mag_1400_erp_procat_14,magento1400,product.model_product_category,updated_at,,in,function,unicode,,"result=[('magerp_stamp',ifield)]", |
3460 | +mag_1400_erp_procat_15,magento1400,product.model_product_category,image,,in_out,function,unicode,,"image_binary = False |
3461 | +if ifield and not ifield=='None': |
3462 | + try: |
3463 | + image_binary = conn.call('ol_catalog_category_media.info', [int(data['category_id'])]) |
3464 | + except Exception, e: |
3465 | + print e |
3466 | + pass |
3467 | + if image_binary: |
3468 | + image_binary = base64.encodestring(base64.urlsafe_b64decode(image_binary[0]['image_data'])) |
3469 | +result=[('image_name',ifield),('image',image_binary)]","if record['image']: |
3470 | + img = base64.decodestring(record['image']) |
3471 | + img_bin_enc = base64.encodestring(img) |
3472 | + conn.call('ol_catalog_category_media.create', [record['image_name'], img_bin_enc]) |
3473 | + result = [('image',record['image_name'])] |
3474 | +else: |
3475 | + result=[]" |
3476 | +mag_1400_erp_procat_16,magento1400,product.model_product_category,include_in_menu,,in_out,function,unicode,,"result=[('include_in_menu', ifield and (eval(ifield)) or False)]","result=[('include_in_menu',record['include_in_menu'])]" |
3477 | +mag_1400_erp_procat_17,magento1400,product.model_product_category,page_layout,,in_out,function,unicode,,"if ifield: |
3478 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'page_layout', context=context) |
3479 | +else: |
3480 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','page_layout', context=context) |
3481 | +result=[('page_layout',att_id)]","page_layout = record['page_layout'] and record['page_layout'][1] or '' |
3482 | +result=[('page_layout', page_layout)]" |
3483 | +mag_1400_erp_attrgrp_2,magento1400,model_magerp_product_attribute_groups,attribute_set_id,,in_out,function,int,,"result=[('attribute_set_id', ifield)]","result=[('attribute_set_id', record['attribute_set_id'])]" |
3484 | +mag_1400_erp_attrgrp_3,magento1400,model_magerp_product_attribute_groups,attribute_group_name,,in_out,function,unicode,,"result=[('attribute_group_name', ifield)]","result=[('attribute_group_name', record['attribute_group_name'])]" |
3485 | +mag_1400_erp_attrgrp_4,magento1400,model_magerp_product_attribute_groups,sort_order,,in_out,function,int,,"result=[('sort_order', ifield)]","result=[('sort_order', record['sort_order'])]" |
3486 | +mag_1400_erp_attrgrp_5,magento1400,model_magerp_product_attribute_groups,default_id,,in_out,function,int,,"result=[('default_id', ifield)]","result=[('default_id', record['default_id'])]" |
3487 | +mag_1400_erp_attrset_1,magento1400,model_magerp_product_attribute_set,attribute_set_id,,in_out,function,int,,"result=[('magento_id', ifield)]","result=[('attribute_set_id', record['magento_id'])]" |
3488 | +mag_1400_erp_attrset_2,magento1400,model_magerp_product_attribute_set,sort_order,,in_out,function,int,,"result=[('sort_order', ifield)]","result=[('sort_order', record['sort_order'])]" |
3489 | +mag_1400_erp_attrset_3,magento1400,model_magerp_product_attribute_set,attribute_set_name,,in_out,function,unicode,,"result=[('attribute_set_name', ifield)]","result=[('attribute_set_name', record['attribute_set_name'])]" |
3490 | +mag_1400_erp_attr_1,magento1400,model_magerp_product_attributes,attribute_code,,in_out,function,unicode,,"result=[('attribute_code', ifield)]","result=[('code', record['attribute_code'])]" |
3491 | +mag_1400_erp_attr_2,magento1400,model_magerp_product_attributes,attribute_id,,in_out,function,int,,"result=[('magento_id', ifield)]", |
3492 | +mag_1400_erp_attr_3,magento1400,model_magerp_product_attributes,frontend_input,,in_out,function,unicode,,"result=[('frontend_input', ifield)]","result=[('frontend_input', record['frontend_input'])]" |
3493 | +mag_1400_erp_attr_4,magento1400,model_magerp_product_attributes,frontend_class,,in_out,function,unicode,,"result=[('frontend_class', ifield)]","result=[('frontend_class', record['frontend_class'])]" |
3494 | +mag_1400_erp_attr_5,magento1400,model_magerp_product_attributes,backend_model,,in_out,function,unicode,,"result=[('backend_model', ifield)]","result=[('backend_model', record['backend_model'])]" |
3495 | +mag_1400_erp_attr_6,magento1400,model_magerp_product_attributes,backend_type,,in_out,function,unicode,,"result=[('backend_type', ifield)]","result=[('backend_type', record['backend_type'])]" |
3496 | +mag_1400_erp_attr_7,magento1400,model_magerp_product_attributes,frontend_label,,in_out,function,unicode,,"result=[('frontend_label', ifield)]","result=[('frontend_label', record['frontend_label'])]" |
3497 | +mag_1400_erp_attr_8,magento1400,model_magerp_product_attributes,is_visible_in_advanced_search,,in_out,function,unicode,,"result=[('is_visible_in_advanced_search', bool(eval(ifield)))]","result=[('is_visible_in_advanced_search', record['is_visible_in_advanced_search'])]" |
3498 | +mag_1400_erp_attr_9,magento1400,model_magerp_product_attributes,is_global,,in_out,function,unicode,,"result=[('is_global', bool(eval(ifield)))]","result=[('is_global', record['is_global'])]" |
3499 | +mag_1400_erp_attr_10,magento1400,model_magerp_product_attributes,is_filterable,,in_out,function,unicode,,"result=[('is_filterable', bool(eval(ifield)))]","result=[('is_filterable', record['is_filterable'])]" |
3500 | +mag_1400_erp_attr_11,magento1400,model_magerp_product_attributes,is_comparable,,in_out,function,unicode,,"result=[('is_comparable', bool(eval(ifield)))]","result=[('is_comparable', record['is_comparable'])]" |
3501 | +mag_1400_erp_attr_12,magento1400,model_magerp_product_attributes,is_visible,,in_out,function,unicode,,"result=[('is_visible', bool(eval(ifield)))]","result=[('is_visible', record['is_visible'])]" |
3502 | +mag_1400_erp_attr_13,magento1400,model_magerp_product_attributes,is_searchable,,in_out,function,unicode,,"result=[('is_searchable', bool(eval(ifield)))]","result=[('is_searchable', record['is_searchable'])]" |
3503 | +mag_1400_erp_attr_14,magento1400,model_magerp_product_attributes,is_user_defined,,in_out,function,unicode,,"result=[('is_user_defined', bool(eval(ifield)))]","result=[('is_user_defined', record['is_user_defined'])]" |
3504 | +mag_1400_erp_attr_15,magento1400,model_magerp_product_attributes,is_configurable,,in_out,function,unicode,,"result=[('is_configurable', bool(eval(ifield)))]","result=[('is_configurable', record['is_configurable'])]" |
3505 | +mag_1400_erp_attr_16,magento1400,model_magerp_product_attributes,is_visible_on_front,,in_out,function,unicode,,"result=[('is_visible_on_front', bool(eval(ifield)))]","result=[('is_visible_on_front', record['is_visible_on_front'])]" |
3506 | +mag_1400_erp_attr_17,magento1400,model_magerp_product_attributes,is_used_for_price_rules,,in_out,function,unicode,,"result=[('is_used_for_price_rules', bool(eval(ifield)))]","result=[('is_used_for_price_rules', record['is_used_for_price_rules'])]" |
3507 | +mag_1400_erp_attr_18,magento1400,model_magerp_product_attributes,is_unique,,in_out,function,unicode,,"result=[('is_unique', bool(eval(ifield)))]","result=[('is_unique', record['is_unique'])]" |
3508 | +mag_1400_erp_attr_19,magento1400,model_magerp_product_attributes,is_required,,in_out,function,unicode,,"result=[('is_required', bool(eval(ifield)))]","result=[('is_required', record['is_required'])]" |
3509 | +mag_1400_erp_attr_20,magento1400,model_magerp_product_attributes,position,,in_out,function,int,,"result=[('position', ifield)]","result=[('position', record['position'])]" |
3510 | +mag_1400_erp_attr_21,magento1400,model_magerp_product_attributes,attribute_set_info,,in_out,function,unicode,,"result=[('attribute_set_info', ifield)]","result=[('attribute_set_info', record['attribute_set_info'])]" |
3511 | +mag_1400_erp_attr_22,magento1400,model_magerp_product_attributes,default_value,,in_out,function,unicode,,"result=[('default_value', ifield)]","result=[('default_value', record['default_value'])]" |
3512 | +mag_1400_erp_attr_23,magento1400,model_magerp_product_attributes,note,,in_out,function,unicode,,"result=[('note', ifield)]","result=[('note', record['note'])]" |
3513 | +mag_1400_erp_attr_24,magento1400,model_magerp_product_attributes,entity_type_id,,in_out,function,int,,"result=[('entity_type_id', ifield)]","result=[('entity_type_id', record['entity_type_id'])]" |
3514 | +mag_1400_erp_attr_25,magento1400,model_magerp_product_attributes,apply_to,,in_out,function,unicode,,"result=[('apply_to', str(ifield))]","result=[('apply_to', eval(record['%s']))]" |
3515 | +mag_1400_erp_prd_1,magento1400,product.model_product_product,url_key,,in_out,function,unicode,,"result=[('x_magerp_url_key',ifield)]","if context.get('export_url', False) : |
3516 | + result=[('url_key',record['x_magerp_url_key'])]" |
3517 | +mag_1400_erp_prd_2,magento1400,product.model_product_product,name,,in_out,function,unicode,,"result = [('name',ifield)]","result = [('name',record['name'])]" |
3518 | +mag_1400_erp_prd_3,magento1400,product.model_product_product,description,,in_out,function,unicode,,"result = [('description',ifield)]", |
3519 | +mag_1400_erp_prd_4,magento1400,product.model_product_product,short_description,,in_out,function,unicode,,"result = [('description_sale',ifield)]", |
3520 | +mag_1400_erp_prd_5,magento1400,product.model_product_product,sku,,in_out,function,unicode,,"result = [('magento_sku',ifield), ('default_code',ifield)]", |
3521 | +mag_1400_erp_prd_6,magento1400,product.model_product_product,weight,,in_out,function,float,,"result = [('weight',ifield)]","result = [('weight',record['weight'] or 0)]" |
3522 | +mag_1400_erp_prd_7,magento1400,product.model_product_product,category_ids,,in_out,function,list,,"categ_ids =[] |
3523 | +if ifield and len(ifield) > 0: |
3524 | + for category_ids in ifield: |
3525 | + categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, category_ids, external_referential_id, context=context)) |
3526 | + categ_id = categ_ids.pop() |
3527 | +else: |
3528 | + categ_id = self.pool.get('external.referential').browse(cr, uid, external_referential_id).default_pro_cat.id |
3529 | +result = [('categ_id', categ_id), ('categ_ids',[(6, 0, categ_ids)])]"," |
3530 | +cat_obj = self.pool.get('product.category') |
3531 | +product = self.browse(cr, uid, record['id']) |
3532 | +categ_ids = [categ.id for categ in ([product.categ_id] + product.categ_ids) if categ.magento_exportable] |
3533 | +mag_categ_ids = [] |
3534 | +for categ_id in categ_ids: |
3535 | + mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id) |
3536 | + if not mag_categ_id: |
3537 | + cat_obj.ext_export(cr, uid, [categ_id], [external_referential_id], context=context) |
3538 | + mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id) |
3539 | + mag_categ_ids.append(mag_categ_id) |
3540 | +result=[('category_ids', mag_categ_ids)]" |
3541 | +mag_1400_erp_prd_8,magento1400,product.model_product_product,price,,in_out,function,float,,"result=[('list_price',ifield)]",result=[]#map later |
3542 | +mag_1400_erp_prd_9,magento1400,product.model_product_product,cost,,in_out,function,float,,"result=[('standard_price',ifield)]","result = [('cost',record['standard_price'] or 0)]" |
3543 | +mag_1400_erp_prd_10,magento1400,product.model_product_product,set,,in_out,function,unicode,,"result=[('set',self.pool.get('magerp.product_attribute_set').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
3544 | +mag_1400_erp_prd_11,magento1400,product.model_product_product,special_price,,in_out,function,float,,"result = [('x_magerp_special_price',ifield)]", |
3545 | +mag_1400_erp_prd_12,magento1400,product.model_product_product,tier_price,,in_out,function,unicode,,result=[]#no mapping by default,result=[]#no mapping by default |
3546 | +mag_1400_erp_prd_13,magento1400,product.model_product_product,minimal_price,,in_out,function,float,,"result = [('x_magerp_minimal_price',ifield)]"," |
3547 | +if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0: |
3548 | + result = [('minimal_price',record['x_magerp_minimal_price'])] |
3549 | +else: |
3550 | + result = [('minimal_price',False)]" |
3551 | +mag_1400_erp_prd_14,magento1400,product.model_product_product,type_id,,in_out,function,unicode,,"if ifield: |
3552 | + product_type_ids = self.pool.get('magerp.product_product_type').search(cr,uid,[('product_type','=',ifield)]) |
3553 | + if product_type_ids: |
3554 | + result = [('product_type',ifield)]","if 'product_type' in record and record['product_type']: |
3555 | + result = [('type_id',record['product_type'])] |
3556 | +else: |
3557 | + result = [('type_id','simple')]" |
3558 | +mag_1400_erp_prd_15,magento1400,product.model_product_product,websites,,in_out,function,list,,"websites_ids = [] |
3559 | +for ext_id in ifield: |
3560 | + websites_ids.append(self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ext_id, external_referential_id, context=context)) |
3561 | + |
3562 | +##### OPTION START, with this if the field websites of the product is empty the product is exported on every website |
3563 | +all_oe_websites_ids = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)]) |
3564 | +if set(websites_ids) == set(all_oe_websites_ids): |
3565 | + websites_ids =[] |
3566 | +##### OPTION END |
3567 | + |
3568 | +result=[('websites_ids', [(6,0, websites_ids)])]","##### OPTION START, with this if the field websites of the product is empty the product is exported on every website |
3569 | +if not record['websites_ids']: |
3570 | + record['websites_ids'] = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)]) |
3571 | +##### OPTION END |
3572 | + |
3573 | +ext_websites_ids = [] |
3574 | +for oe_id in record['websites_ids']: |
3575 | + ext_websites_ids.append(self.pool.get('external.shop.group').oeid_to_extid(cr, uid, oe_id, external_referential_id)) |
3576 | + |
3577 | +result=[('websites', ext_websites_ids)]" |
3578 | +mag_1400_erp_prd_16,magento1400,product.model_product_product,has_options,,in,function,unicode,,"result =[('x_magerp_has_options',ifield)]", |
3579 | +magento_1400_cst_grp_1,magento1400,base.model_res_partner_category,customer_group_code,,in,function,unicode,,"result=[('name',ifield)]", |
3580 | +magento_1400_cst_grp_3,magento1400,base.model_res_partner_category,tax_class_id,,in,function,int,,"result=[('tax_class_id',ifield)]", |
3581 | +magento_1400_prt_adr_2,magento1400,base.model_res_partner_address,city,,in_out,function,unicode,,"result=[('city',ifield)]", |
3582 | +magento_1400_prt_adr_3,magento1400,base.model_res_partner_address,fax,,in_out,function,unicode,,"result=[('fax',ifield)]", |
3583 | +magento_1400_prt_adr_4,magento1400,base.model_res_partner_address,firstname,,in_out,function,unicode,,"name = ' '.join([ f for f in (data['firstname'], data['lastname']) if f]) |
3584 | +if data.get('company'): |
3585 | + name = ""%s ; %s"" % (data['company'], name) |
3586 | +result = [('name', name), ('firstname', ifield), ('lastname', data['lastname'])]", |
3587 | +magento_1400_prt_adr_6,magento1400,base.model_res_partner_address,is_active,,in_out,function,unicode,,"result=[('active',bool(eval(ifield)))]", |
3588 | +magento_1400_prt_adr_7,magento1400,base.model_res_partner_address,country_id,,in_out,function,unicode,,"result = self.pool.get('res.country').search(cr,uid,[('code','=',ifield)]) |
3589 | +if result and len(result)==1: |
3590 | + result=[('country_id',result[0])] |
3591 | +else: |
3592 | + result=[] |
3593 | +", |
3594 | +magento_1400_prt_adr_8,magento1400,base.model_res_partner_address,street,,in_out,function,unicode,,"if ifield: |
3595 | + if len(ifield.split('\n')) ==2 : |
3596 | + result = [('street', ifield.split('\n')[0]) , ('street2', ifield.split('\n')[1])] |
3597 | + else : |
3598 | + result = [('street',ifield.replace('\\n',','))] |
3599 | +else: |
3600 | + result = []", |
3601 | +magento_1400_prt_adr_9,magento1400,base.model_res_partner_address,postcode,,in_out,function,unicode,,"result=[('zip',ifield)]", |
3602 | +magento_1400_prt_adr_10,magento1400,base.model_res_partner_address,telephone,,in_out,function,unicode,,"result=[('phone',ifield)]", |
3603 | +magento_1400_prt_adr_11,magento1400,base.model_res_partner_address,region,,in_out,function,unicode,,"if ifield: |
3604 | + result = self.pool.get('res.country.state').search(cr,uid,[('name','=ilike',ifield)]) |
3605 | + if result and len(result)==1: |
3606 | + result = [('state_id',result[0])] |
3607 | + else: |
3608 | + result=[] |
3609 | +else: |
3610 | + result=[]", |
3611 | +magento_1400_prt_adr_13,magento1400,base.model_res_partner_address,customer_id,,in_out,function,int,,"result=self.pool.get('res.partner').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
3612 | +if result: |
3613 | + result=[('partner_id',result)] |
3614 | +else: |
3615 | + result=[('partner_id',False)]", |
3616 | +magento_1400_prt_adr_14,magento1400,base.model_res_partner_address,address_type,,in_out,function,unicode,,"if ifield=='billing': |
3617 | + result=[('type','invoice')] |
3618 | +elif ifield=='shipping': |
3619 | + result=[('type','delivery')] |
3620 | +else: |
3621 | + result=[]", |
3622 | +magento_1400_prt_adr_15,magento1400,base.model_res_partner_address,email,,in_out,function,unicode,,"result = [('email', False)] |
3623 | +if ifield: |
3624 | + result = [('email', ifield)] |
3625 | +else: |
3626 | + partner_obj = self.pool.get('res.partner') |
3627 | + partner_id = partner_obj.extid_to_existing_oeid(cr, uid, data['customer_id'] ,external_referential_id) |
3628 | + if partner_id: |
3629 | + result = [('email', partner_obj.browse(cr, uid, partner_id).emailid)]", |
3630 | +magento_1400_prt_adr_17,magento1400,base.model_res_partner_address,default_billing,,in_out,function,unicode,,"result = [('type', 'other')] |
3631 | +if data.get('default_billing') and data.get('default_shipping'): |
3632 | + result = [('type', 'default')] |
3633 | +elif data.get('default_billing'): |
3634 | + result = [('type', 'invoice')] |
3635 | +elif data.get('default_shipping'): |
3636 | + result = [('type', 'delivery')]", |
3637 | +magento_1400_prt_2,magento1400,base.model_res_partner,group_id,,in_out,function,int,,"if ifield: |
3638 | + result=self.pool.get('res.partner.category').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
3639 | + if result: |
3640 | + result=[('group_id',result)]", |
3641 | +magento_1400_prt_3,magento1400,base.model_res_partner,store_id,,in_out,function,int,,"if ifield: |
3642 | + result=self.pool.get('magerp.storeviews').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
3643 | + if result: |
3644 | + store = self.pool.get('magerp.storeviews').browse(cr, uid, result) |
3645 | + lang = store.lang_id |
3646 | + result=[('store_id',result),('lang',lang and lang.code or False)] |
3647 | + if not data.get('website_id'): |
3648 | + result.append(('website_id', store.website_id.id))", |
3649 | +magento_1400_prt_4,magento1400,base.model_res_partner,website_id,,in_out,function,int,,"if ifield: |
3650 | + result=self.pool.get('external.shop.group').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
3651 | + if result: |
3652 | + result=[('website_id',result)]", |
3653 | +magento_1400_prt_5,magento1400,base.model_res_partner,created_in,,in_out,function,unicode,,"result=[('created_in',ifield)]", |
3654 | +magento_1400_prt_6,magento1400,base.model_res_partner,created_at,,in_out,function,unicode,,"result=[('created_at',ifield)]", |
3655 | +magento_1400_prt_7,magento1400,base.model_res_partner,updated_at,,in_out,function,unicode,,"result=[('updated_at',ifield)]", |
3656 | +magento_1400_prt_8,magento1400,base.model_res_partner,firstname,,in_out,function,unicode,,"result = [('name', ifield + ' ' + data['lastname'])]","add_id = self.browse(cr, uid, record['id']) |
3657 | +fn = add_id.address[0].firstname |
3658 | +ln = add_id.address[0].lastname |
3659 | +result=[('firstname', fn), ('lastname', ln)]" |
3660 | +magento_1400_prt_10,magento1400,base.model_res_partner,email,,in_out,function,unicode,,"result=[('emailid',ifield)]", |
3661 | +magento_1400_prt_11,magento1400,base.model_res_partner,taxvat,,in_out,function,unicode,,"if ifield: |
3662 | + result=[('mag_vat',ifield)] |
3663 | +else: |
3664 | + result=[]", |
3665 | +magento_1400_prt_12,magento1400,base.model_res_partner,dob,,in_out,function,unicode,,"if ifield: |
3666 | + result =[('mag_birthday',ifield[:10])] |
3667 | +else: |
3668 | + result=[]", |
3669 | |
3670 | === added file 'magentoerpconnect/settings/1.4.0.0/external.referential.type.csv' |
3671 | --- magentoerpconnect/settings/1.4.0.0/external.referential.type.csv 1970-01-01 00:00:00 +0000 |
3672 | +++ magentoerpconnect/settings/1.4.0.0/external.referential.type.csv 2012-07-06 14:53:18 +0000 |
3673 | @@ -0,0 +1,2 @@ |
3674 | +"id","name" |
3675 | +"magento1400","Magento Version 1.4.0.0+" |
3676 | |
3677 | === added directory 'magentoerpconnect/settings/1.4.2.0' |
3678 | === added file 'magentoerpconnect/settings/1.4.2.0/external.mapping.template.csv' |
3679 | --- magentoerpconnect/settings/1.4.2.0/external.mapping.template.csv 1970-01-01 00:00:00 +0000 |
3680 | +++ magentoerpconnect/settings/1.4.2.0/external.mapping.template.csv 2012-07-06 14:53:18 +0000 |
3681 | @@ -0,0 +1,14 @@ |
3682 | +"id","type_id:id","model_id:id","external_list_method","external_get_method","external_update_method","external_create_method","external_delete_method","external_key_name" |
3683 | +"magento_1420_website","magento1420","base_sale_multichannels.model_external_shop_group","ol_websites.list",,,,,"website_id" |
3684 | +"magento_1420_storeview","magento1420","model_magerp_storeviews","ol_storeviews.list",,,,,"store_id" |
3685 | +"magento_1420_store","magento1420","sale.model_sale_shop","ol_groups.list",,,,,"group_id" |
3686 | +"magento_1420_order","magento1420","sale.model_sale_order","sales_order.list","sales_order.info",,,,"increment_id" |
3687 | +"magento_1420_order_line","magento1420","sale.model_sale_order_line",,,,,,"item_id" |
3688 | +"magento_1420_pro_cat","magento1420","product.model_product_category","category.list","category.info","catalog_category.update","catalog_category.create",,"category_id" |
3689 | +"magento_1420_attr_grp","magento1420","model_magerp_product_attribute_groups","ol_catalog_product_attribute_group.list","ol_catalog_product_attribute_group.list",,,,"attribute_group_id" |
3690 | +"magento_1420_attr_set","magento1420","model_magerp_product_attribute_set","ol_catalog_product_attributeset.list",,,,,"attribute_set_id" |
3691 | +"magento_1420_attr","magento1420","model_magerp_product_attributes","ol_catalog_product_attribute.list",,,,,"attribute_id" |
3692 | +"magento_1420_prd","magento1420","product.model_product_product","catalog_product.list","catalog_product.info","ol_catalog_product.update","ol_catalog_product.create",,"product_id" |
3693 | +"magento_1420_cst_grp","magento1420","base.model_res_partner_category","ol_customer_groups.list",,,,,"customer_group_id" |
3694 | +"magento_1420_prt_adr","magento1420","base.model_res_partner_address","ol_customer_address.list","ol_customer_address.info",,,,"entity_id" |
3695 | +"magento_1420_prt","magento1420","base.model_res_partner","customer.list","customer.info","customer.update",,,"customer_id" |
3696 | |
3697 | === added file 'magentoerpconnect/settings/1.4.2.0/external.mappinglines.template.csv' |
3698 | --- magentoerpconnect/settings/1.4.2.0/external.mappinglines.template.csv 1970-01-01 00:00:00 +0000 |
3699 | +++ magentoerpconnect/settings/1.4.2.0/external.mappinglines.template.csv 2012-07-06 14:53:18 +0000 |
3700 | @@ -0,0 +1,318 @@ |
3701 | +id,type_id:id,model_id:id,external_field,field_id:id,type,evaluation_type,external_type,child_mapping_id:id,in_function,out_function |
3702 | +mag_1420_erp_s_name,magento1420,base_sale_multichannels.model_external_shop_group,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
3703 | +mag_1420_erp_s_code,magento1420,base_sale_multichannels.model_external_shop_group,code,,in_out,function,unicode,,"result=[('code',ifield)]", |
3704 | +mag_1420_erp_s_web,magento1420,base_sale_multichannels.model_external_shop_group,website_id,,in_out,function,int,,"result=[('website_id',ifield)]", |
3705 | +mag_1420_erp_s_isa,magento1420,base_sale_multichannels.model_external_shop_group,is_default,,in_out,function,unicode,,"result=[('is_default',bool(eval(ifield)))]", |
3706 | +mag_1420_erp_s_stord,magento1420,base_sale_multichannels.model_external_shop_group,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]", |
3707 | +mag_1420_erp_s_gpid,magento1420,base_sale_multichannels.model_external_shop_group,default_group_id,,in_out,function,int,,"result=[('default_shop_integer_id',ifield)]", |
3708 | +mag_1420_erp_sv_name,magento1420,model_magerp_storeviews,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
3709 | +mag_1420_erp_sv_code,magento1420,model_magerp_storeviews,code,,in_out,function,unicode,,"result=[('code',ifield)]", |
3710 | +mag_1420_erp_sv_sg,magento1420,model_magerp_storeviews,website_id,,in_out,function,int,,"result=[('website_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
3711 | +mag_1420_erp_sv_isa,magento1420,model_magerp_storeviews,is_active,,in_out,function,unicode,,"result=[('is_active',bool(eval(ifield)))]", |
3712 | +mag_1420_erp_sv_stord,magento1420,model_magerp_storeviews,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]", |
3713 | +mag_1420_erp_sv_gpid,magento1420,model_magerp_storeviews,group_id,,in_out,function,int,,"result=[('shop_id',self.pool.get('sale.shop').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
3714 | +mag_1420_erp_st_name,magento1420,sale.model_sale_shop,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
3715 | +mag_1420_erp_st_gpid,magento1420,sale.model_sale_shop,group_id,,in_out,function,int,,"result=[('group_id',ifield)]", |
3716 | +mag_1420_erp_st_grp,magento1420,sale.model_sale_shop,website_id,,in_out,function,int,,"result=[('shop_group_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
3717 | +mag_1420_erp_st_default_st,magento1420,sale.model_sale_shop,default_store_id,,in_out,function,int,,"result=[('default_storeview_integer_id',ifield)]", |
3718 | +mag_1420_erp_st_root_categ,magento1420,sale.model_sale_shop,root_category_id,,in_out,function,int,,"result=[('root_category_id',ifield)]", |
3719 | +mag_1420_erp_so_total_amount,magento1420,sale.model_sale_order,grand_total,,in_out,function,float,,"result=[('ext_total_amount',str(ifield))]", |
3720 | +mag_1420_erp_so_name,magento1420,sale.model_sale_order,increment_id,,in_out,function,unicode,,"result=[('magento_incrementid',str(ifield)), ('name','mag_' + str(ifield))]", |
3721 | +mag_1420_erp_so_carrier_id,magento1420,sale.model_sale_order,shipping_method,,in_out,function,unicode,,"if ifield: |
3722 | + carrier_ids = self.pool.get('delivery.carrier').search(cr, uid, [('magento_code', '=', ifield)]) |
3723 | + if carrier_ids: |
3724 | + result=[('carrier_id', carrier_ids[0])] |
3725 | + else: |
3726 | + fake_partner_id = self.pool.get('res.partner').search(cr, uid, [])[0] |
3727 | + model_data_obj = self.pool.get('ir.model.data') |
3728 | + model, product_id = model_data_obj.get_object_reference(cr, uid, 'base_sale_multichannels', 'product_product_shipping') |
3729 | + carrier_id = self.pool.get('delivery.carrier').create(cr, uid, {'partner_id' : fake_partner_id, 'product_id' : product_id, 'name' : ifield, 'magento_code' : ifield}) |
3730 | + result=[('carrier_id', carrier_id)]", |
3731 | +mag_1420_erp_so_pay,magento1420,sale.model_sale_order,payment,,in_out,function,unicode,," |
3732 | +payments_mapping = {'checkmo': 'manual', 'ccsave': 'prepaid', 'free':'prepaid','googlecheckout':'prepaid','paypayl_express':'prepaid', 'paybox_system': 'prepaid', 'paypal_standard': 'prepaid', 'cashondelivery': 'manual', 'servired_standard': 'prepaid', 'bbva': 'prepaid', 'cofidis': 'prepaid'} |
3733 | +ifield=eval(ifield) |
3734 | +result=[('order_policy', ifield['method'] in payments_mapping and payments_mapping[ifield['method']] or 'prepaid'), ('ext_payment_method', ifield['method'])]", |
3735 | +mag_1420_erp_so_item,magento1420,sale.model_sale_order,items,sale.field_sale_order_order_line,in,sub-mapping,dict,magento_1420_order_line,, |
3736 | +"mag_1420_erp_soline_name","magento1420","sale.model_sale_order_line","name",,"in_out","function","unicode",,"result=[('name', ifield)] |
3737 | +", |
3738 | +"mag_1420_erp_soline_note","magento1420","sale.model_sale_order_line","product_options",,"in","function","unicode",,"if ifield: |
3739 | + import re |
3740 | + options_label = [] |
3741 | + clean = re.sub('\w:\w:|\w:\w+;', '', ifield) |
3742 | + for each in clean.split('{'): |
3743 | + if each.startswith('""label""'): |
3744 | + split_info = each.split(';') |
3745 | + options_label.append('%s: %s [%s]' % (split_info[1], split_info[3], data['sku'])) |
3746 | + |
3747 | + result=[('notes', """".join(options_label).replace('""""', '\n').replace('""', ''))] |
3748 | +", |
3749 | +mag_1420_erp_soline_pid,magento1420,sale.model_sale_order_line,product_id,,in_out,function,unicode,,"context['alternative_key'] = data['sku'] |
3750 | +result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
3751 | +mag_1420_erp_soline_uomqty,magento1420,sale.model_sale_order_line,qty_ordered,,in_out,function,unicode,,"result=[('product_uom_qty',ifield)]", |
3752 | +mag_1420_erp_soline_uosqty,magento1420,sale.model_sale_order_line,qty_ordered,,in,function,unicode,,"result=[('product_uos_qty',ifield)]", |
3753 | +mag_1420_erp_soline_price,magento1420,sale.model_sale_order_line,price,,in,function,unicode,,"if context.get('price_is_tax_included', False): |
3754 | + result=[('price_unit', (float(data['row_total']) + float(data['tax_amount']))/float(data['qty_ordered']))] |
3755 | +else: |
3756 | + result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]", |
3757 | +mag_1420_erp_soline_disc,magento1420,sale.model_sale_order_line,discount_amount,,in,function,float,,"if ifield: |
3758 | + result=[('discount', float(data['price']) != 0 and float(data['qty_ordered']) != 0 and float(100*ifield)/(float(data['price'])*float(data['qty_ordered'])) or 0)]", |
3759 | +mag_1420_erp_procat_2,magento1420,product.model_product_category,level,,in,function,int,,"result=[('sequence',ifield),('level',ifield)]", |
3760 | +mag_1420_erp_procat_3,magento1420,product.model_product_category,parent_id,,in_out,function,int,,"record_id = self.pool.get('ir.model.data').search(cr, uid, [('model', '=', self._name), ('name', '=', self.prefixed_id(ifield))]) |
3761 | +parent_id = False |
3762 | +if record_id: |
3763 | + parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[]) |
3764 | + parent_id=parent_rec.get('res_id',False) |
3765 | +result=[('magento_parent_id',ifield),('parent_id',parent_id)]","magento_parent_id = False |
3766 | +if record.get('parent_id',False): |
3767 | + magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) |
3768 | + if not magento_parent_id: |
3769 | + self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[external_referential_id],{},context=context) |
3770 | + magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) |
3771 | +if magento_parent_id: |
3772 | + result = [('parent_id',magento_parent_id)]" |
3773 | +mag_1420_erp_procat_4,magento1420,product.model_product_category,is_active,,in_out,function,unicode,,"result=[('is_active',ifield and (eval(ifield)) or False)]","result=[('is_active',record['is_active'])]" |
3774 | +mag_1420_erp_procat_5,magento1420,product.model_product_category,description,,in_out,function,unicode,,"result=[('description',ifield)]","result=[('description',record['description'])]" |
3775 | +mag_1420_erp_procat_6,magento1420,product.model_product_category,meta_title,,in_out,function,unicode,,"result=[('meta_title',ifield)]","result=[('meta_title',record['meta_title'])]" |
3776 | +mag_1420_erp_procat_7,magento1420,product.model_product_category,meta_keywords,,in_out,function,unicode,,"result=[('meta_keywords',ifield)]","result=[('meta_keywords',record['meta_keywords'])]" |
3777 | +mag_1420_erp_procat_8,magento1420,product.model_product_category,meta_description,,in_out,function,unicode,,"result=[('meta_description',ifield)]","result=[('meta_description',record['meta_description'])]" |
3778 | +mag_1420_erp_procat_9,magento1420,product.model_product_category,url_key,,in_out,function,unicode,,"result=[('url_key',ifield)]","if context.get('export_url', False) : |
3779 | + result=[('url_key',record['url_key'])]" |
3780 | +mag_1420_erp_procat_10,magento1420,product.model_product_category,name,,in_out,function,unicode,,"result=[('name',ifield or 'UNDEFINED'),('magento_exportable',True)]","result=[('name',record['name'])]" |
3781 | +mag_1420_erp_procat_11,magento1420,product.model_product_category,is_anchor,,in_out,function,unicode,,"result=[('is_anchor',ifield and bool(eval(ifield)) or False)]","result=[('is_anchor',record['is_anchor'])]" |
3782 | +mag_1420_erp_procat_12,magento1420,product.model_product_category,available_sort_by,,in_out,function,list,,"attr_ids = [] |
3783 | +cat_attr_obj = self.pool.get('magerp.product_category_attribute_options') |
3784 | +if ifield: |
3785 | + for val in ifield: |
3786 | + attr_ids.append(cat_attr_obj.get_create_option_id(cr, uid, val,'sort_by', context=context)) |
3787 | + result=[('available_sort_by', [(6, 0, attr_ids)]), ('use_default_available_sort_by', False)] |
3788 | +else: |
3789 | + result=[('use_default_available_sort_by', True)]","if record['use_default_available_sort_by']: |
3790 | + res = u'' |
3791 | +else: |
3792 | + res = [] |
3793 | + for cat_attr_option in self.pool.get('magerp.product_category_attribute_options').browse(cr, uid, record['available_sort_by'], context=context): |
3794 | + res.append(cat_attr_option.value) |
3795 | +result=[('available_sort_by', res)]" |
3796 | +mag_1420_erp_procat_13,magento1420,product.model_product_category,default_sort_by,,in_out,function,unicode,,"if ifield: |
3797 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'sort_by', context=context) |
3798 | +else: |
3799 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','sort_by', context=context) |
3800 | +result=[('default_sort_by',att_id)]","options_obj = self.pool.get('magerp.product_category_attribute_options') |
3801 | +cat_attr_option_id = record['default_sort_by'] |
3802 | +if cat_attr_option_id: |
3803 | + cat_attr_option_id = cat_attr_option_id[0] |
3804 | +else: |
3805 | + cat_attr_option_id = options_obj._get_default_option(cr, uid, 'sort_by', '', context=context) |
3806 | + |
3807 | +cat_attr_option = options_obj.browse(cr, uid, cat_attr_option_id, context=context) |
3808 | +result=[('default_sort_by', cat_attr_option.value)]" |
3809 | +mag_1420_erp_procat_14,magento1420,product.model_product_category,updated_at,,in,function,unicode,,"result=[('magerp_stamp',ifield)]", |
3810 | +mag_1420_erp_procat_15,magento1420,product.model_product_category,image,,in_out,function,unicode,,"image_binary = False |
3811 | +if ifield and not ifield=='None': |
3812 | + try: |
3813 | + image_binary = conn.call('ol_catalog_category_media.info', [int(data['category_id'])]) |
3814 | + except Exception, e: |
3815 | + print e |
3816 | + pass |
3817 | + if image_binary: |
3818 | + image_binary = base64.encodestring(base64.urlsafe_b64decode(image_binary[0]['image_data'])) |
3819 | +result=[('image_name',ifield),('image',image_binary)]","if record['image']: |
3820 | + img = base64.decodestring(record['image']) |
3821 | + img_bin_enc = base64.encodestring(img) |
3822 | + conn.call('ol_catalog_category_media.create', [record['image_name'], img_bin_enc]) |
3823 | + result = [('image',record['image_name'])] |
3824 | +else: |
3825 | + result=[]" |
3826 | +mag_1420_erp_procat_16,magento1420,product.model_product_category,include_in_menu,,in_out,function,unicode,,"result=[('include_in_menu', ifield and (eval(ifield)) or False)]","result=[('include_in_menu',record['include_in_menu'])]" |
3827 | +mag_1420_erp_procat_17,magento1420,product.model_product_category,page_layout,,in_out,function,unicode,,"if ifield: |
3828 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'page_layout', context=context) |
3829 | +else: |
3830 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','page_layout', context=context) |
3831 | +result=[('page_layout',att_id)]","page_layout = record['page_layout'] and record['page_layout'][1] or '' |
3832 | +result=[('page_layout', page_layout)]" |
3833 | +mag_1420_erp_attrgrp_2,magento1420,model_magerp_product_attribute_groups,attribute_set_id,,in_out,function,int,,"result=[('attribute_set_id', ifield)]","result=[('attribute_set_id', record['attribute_set_id'])]" |
3834 | +mag_1420_erp_attrgrp_3,magento1420,model_magerp_product_attribute_groups,attribute_group_name,,in_out,function,unicode,,"result=[('attribute_group_name', ifield)]","result=[('attribute_group_name', record['attribute_group_name'])]" |
3835 | +mag_1420_erp_attrgrp_4,magento1420,model_magerp_product_attribute_groups,sort_order,,in_out,function,int,,"result=[('sort_order', ifield)]","result=[('sort_order', record['sort_order'])]" |
3836 | +mag_1420_erp_attrgrp_5,magento1420,model_magerp_product_attribute_groups,default_id,,in_out,function,int,,"result=[('default_id', ifield)]","result=[('default_id', record['default_id'])]" |
3837 | +mag_1420_erp_attrset_1,magento1420,model_magerp_product_attribute_set,attribute_set_id,,in_out,function,int,,"result=[('magento_id', ifield)]","result=[('attribute_set_id', record['magento_id'])]" |
3838 | +mag_1420_erp_attrset_2,magento1420,model_magerp_product_attribute_set,sort_order,,in_out,function,int,,"result=[('sort_order', ifield)]","result=[('sort_order', record['sort_order'])]" |
3839 | +mag_1420_erp_attrset_3,magento1420,model_magerp_product_attribute_set,attribute_set_name,,in_out,function,unicode,,"result=[('attribute_set_name', ifield)]","result=[('attribute_set_name', record['attribute_set_name'])]" |
3840 | +mag_1420_erp_attr_1,magento1420,model_magerp_product_attributes,attribute_code,,in_out,function,unicode,,"result=[('attribute_code', ifield)]","result=[('code', record['attribute_code'])]" |
3841 | +mag_1420_erp_attr_2,magento1420,model_magerp_product_attributes,attribute_id,,in_out,function,int,,"result=[('magento_id', ifield)]", |
3842 | +mag_1420_erp_attr_3,magento1420,model_magerp_product_attributes,frontend_input,,in_out,function,unicode,,"result=[('frontend_input', ifield)]","result=[('frontend_input', record['frontend_input'])]" |
3843 | +mag_1420_erp_attr_4,magento1420,model_magerp_product_attributes,frontend_class,,in_out,function,unicode,,"result=[('frontend_class', ifield)]","result=[('frontend_class', record['frontend_class'])]" |
3844 | +mag_1420_erp_attr_5,magento1420,model_magerp_product_attributes,backend_model,,in_out,function,unicode,,"result=[('backend_model', ifield)]","result=[('backend_model', record['backend_model'])]" |
3845 | +mag_1420_erp_attr_6,magento1420,model_magerp_product_attributes,backend_type,,in_out,function,unicode,,"result=[('backend_type', ifield)]","result=[('backend_type', record['backend_type'])]" |
3846 | +mag_1420_erp_attr_7,magento1420,model_magerp_product_attributes,frontend_label,,in_out,function,unicode,,"result=[('frontend_label', ifield)]","result=[('frontend_label', record['frontend_label'])]" |
3847 | +mag_1420_erp_attr_8,magento1420,model_magerp_product_attributes,is_visible_in_advanced_search,,in_out,function,unicode,,"result=[('is_visible_in_advanced_search', bool(eval(ifield)))]","result=[('is_visible_in_advanced_search', record['is_visible_in_advanced_search'])]" |
3848 | +mag_1420_erp_attr_9,magento1420,model_magerp_product_attributes,is_global,,in_out,function,unicode,,"result=[('is_global', bool(eval(ifield)))]","result=[('is_global', record['is_global'])]" |
3849 | +mag_1420_erp_attr_10,magento1420,model_magerp_product_attributes,is_filterable,,in_out,function,unicode,,"result=[('is_filterable', bool(eval(ifield)))]","result=[('is_filterable', record['is_filterable'])]" |
3850 | +mag_1420_erp_attr_11,magento1420,model_magerp_product_attributes,is_comparable,,in_out,function,unicode,,"result=[('is_comparable', bool(eval(ifield)))]","result=[('is_comparable', record['is_comparable'])]" |
3851 | +mag_1420_erp_attr_12,magento1420,model_magerp_product_attributes,is_visible,,in_out,function,unicode,,"result=[('is_visible', bool(eval(ifield)))]","result=[('is_visible', record['is_visible'])]" |
3852 | +mag_1420_erp_attr_13,magento1420,model_magerp_product_attributes,is_searchable,,in_out,function,unicode,,"result=[('is_searchable', bool(eval(ifield)))]","result=[('is_searchable', record['is_searchable'])]" |
3853 | +mag_1420_erp_attr_14,magento1420,model_magerp_product_attributes,is_user_defined,,in_out,function,unicode,,"result=[('is_user_defined', bool(eval(ifield)))]","result=[('is_user_defined', record['is_user_defined'])]" |
3854 | +mag_1420_erp_attr_15,magento1420,model_magerp_product_attributes,is_configurable,,in_out,function,unicode,,"result=[('is_configurable', bool(eval(ifield)))]","result=[('is_configurable', record['is_configurable'])]" |
3855 | +mag_1420_erp_attr_16,magento1420,model_magerp_product_attributes,is_visible_on_front,,in_out,function,unicode,,"result=[('is_visible_on_front', bool(eval(ifield)))]","result=[('is_visible_on_front', record['is_visible_on_front'])]" |
3856 | +mag_1420_erp_attr_17,magento1420,model_magerp_product_attributes,is_used_for_price_rules,,in_out,function,unicode,,"result=[('is_used_for_price_rules', bool(eval(ifield)))]","result=[('is_used_for_price_rules', record['is_used_for_price_rules'])]" |
3857 | +mag_1420_erp_attr_18,magento1420,model_magerp_product_attributes,is_unique,,in_out,function,unicode,,"result=[('is_unique', bool(eval(ifield)))]","result=[('is_unique', record['is_unique'])]" |
3858 | +mag_1420_erp_attr_19,magento1420,model_magerp_product_attributes,is_required,,in_out,function,unicode,,"result=[('is_required', bool(eval(ifield)))]","result=[('is_required', record['is_required'])]" |
3859 | +mag_1420_erp_attr_20,magento1420,model_magerp_product_attributes,position,,in_out,function,int,,"result=[('position', ifield)]","result=[('position', record['position'])]" |
3860 | +mag_1420_erp_attr_21,magento1420,model_magerp_product_attributes,attribute_set_info,,in_out,function,unicode,,"result=[('attribute_set_info', ifield)]","result=[('attribute_set_info', record['attribute_set_info'])]" |
3861 | +mag_1420_erp_attr_22,magento1420,model_magerp_product_attributes,default_value,,in_out,function,unicode,,"result=[('default_value', ifield)]","result=[('default_value', record['default_value'])]" |
3862 | +mag_1420_erp_attr_23,magento1420,model_magerp_product_attributes,note,,in_out,function,unicode,,"result=[('note', ifield)]","result=[('note', record['note'])]" |
3863 | +mag_1420_erp_attr_24,magento1420,model_magerp_product_attributes,entity_type_id,,in_out,function,int,,"result=[('entity_type_id', ifield)]","result=[('entity_type_id', record['entity_type_id'])]" |
3864 | +mag_1420_erp_attr_25,magento1420,model_magerp_product_attributes,apply_to,,in_out,function,unicode,,"result=[('apply_to', str(ifield))]","result=[('apply_to', eval(record['%s']))]" |
3865 | +mag_1420_erp_prd_1,magento1420,product.model_product_product,url_key,,in_out,function,unicode,,"result=[('x_magerp_url_key',ifield)]","if context.get('export_url', False) : |
3866 | + result=[('url_key',record['x_magerp_url_key'])]" |
3867 | +mag_1420_erp_prd_2,magento1420,product.model_product_product,name,,in_out,function,unicode,,"result = [('name',ifield)]","result = [('name',record['name'])]" |
3868 | +mag_1420_erp_prd_3,magento1420,product.model_product_product,description,,in_out,function,unicode,,"result = [('description',ifield)]", |
3869 | +mag_1420_erp_prd_4,magento1420,product.model_product_product,short_description,,in_out,function,unicode,,"result = [('description_sale',ifield)]", |
3870 | +mag_1420_erp_prd_5,magento1420,product.model_product_product,sku,,in_out,function,unicode,,"result = [('magento_sku',ifield), ('default_code',ifield)]", |
3871 | +mag_1420_erp_prd_6,magento1420,product.model_product_product,weight,,in_out,function,float,,"result = [('weight',ifield)]","result = [('weight',record['weight'] or 0)]" |
3872 | +mag_1420_erp_prd_7,magento1420,product.model_product_product,category_ids,,in_out,function,list,,"categ_ids =[] |
3873 | +if ifield and len(ifield) > 0: |
3874 | + for category_ids in ifield: |
3875 | + categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, category_ids, external_referential_id, context=context)) |
3876 | + categ_id = categ_ids.pop() |
3877 | +else: |
3878 | + categ_id = self.pool.get('external.referential').browse(cr, uid, external_referential_id).default_pro_cat.id |
3879 | +result = [('categ_id', categ_id), ('categ_ids',[(6, 0, categ_ids)])]"," |
3880 | +cat_obj = self.pool.get('product.category') |
3881 | +product = self.browse(cr, uid, record['id']) |
3882 | +categ_ids = [categ.id for categ in ([product.categ_id] + product.categ_ids) if categ.magento_exportable] |
3883 | +mag_categ_ids = [] |
3884 | +for categ_id in categ_ids: |
3885 | + mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id) |
3886 | + if not mag_categ_id: |
3887 | + cat_obj.ext_export(cr, uid, [categ_id], [external_referential_id], context=context) |
3888 | + mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id) |
3889 | + mag_categ_ids.append(mag_categ_id) |
3890 | +result=[('category_ids', mag_categ_ids)]" |
3891 | +mag_1420_erp_prd_8,magento1420,product.model_product_product,price,,in_out,function,float,,"result=[('list_price',ifield)]",result=[]#map later |
3892 | +mag_1420_erp_prd_9,magento1420,product.model_product_product,cost,,in_out,function,float,,"result=[('standard_price',ifield)]","result = [('cost',record['standard_price'] or 0)]" |
3893 | +mag_1420_erp_prd_10,magento1420,product.model_product_product,set,,in_out,function,unicode,,"result=[('set',self.pool.get('magerp.product_attribute_set').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
3894 | +mag_1420_erp_prd_11,magento1420,product.model_product_product,special_price,,in_out,function,float,,"result = [('x_magerp_special_price',ifield)]", |
3895 | +mag_1420_erp_prd_12,magento1420,product.model_product_product,tier_price,,in_out,function,unicode,,result=[]#no mapping by default,result=[]#no mapping by default |
3896 | +mag_1420_erp_prd_13,magento1420,product.model_product_product,minimal_price,,in_out,function,float,,"result = [('x_magerp_minimal_price',ifield)]"," |
3897 | +if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0: |
3898 | + result = [('minimal_price',record['x_magerp_minimal_price'])] |
3899 | +else: |
3900 | + result = [('minimal_price',False)]" |
3901 | +mag_1420_erp_prd_14,magento1420,product.model_product_product,type_id,,in_out,function,unicode,,"if ifield: |
3902 | + product_type_ids = self.pool.get('magerp.product_product_type').search(cr,uid,[('product_type','=',ifield)]) |
3903 | + if product_type_ids: |
3904 | + result = [('product_type',ifield)]","if 'product_type' in record and record['product_type']: |
3905 | + result = [('type_id',record['product_type'])] |
3906 | +else: |
3907 | + result = [('type_id','simple')]" |
3908 | +mag_1420_erp_prd_15,magento1420,product.model_product_product,websites,,in_out,function,list,,"websites_ids = [] |
3909 | +for ext_id in ifield: |
3910 | + websites_ids.append(self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ext_id, external_referential_id, context=context)) |
3911 | + |
3912 | +##### OPTION START, with this if the field websites of the product is empty the product is exported on every website |
3913 | +all_oe_websites_ids = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)]) |
3914 | +if set(websites_ids) == set(all_oe_websites_ids): |
3915 | + websites_ids =[] |
3916 | +##### OPTION END |
3917 | + |
3918 | +result=[('websites_ids', [(6,0, websites_ids)])]","##### OPTION START, with this if the field websites of the product is empty the product is exported on every website |
3919 | +if not record['websites_ids']: |
3920 | + record['websites_ids'] = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)]) |
3921 | +##### OPTION END |
3922 | + |
3923 | +ext_websites_ids = [] |
3924 | +for oe_id in record['websites_ids']: |
3925 | + ext_websites_ids.append(self.pool.get('external.shop.group').oeid_to_extid(cr, uid, oe_id, external_referential_id)) |
3926 | + |
3927 | +result=[('websites', ext_websites_ids)]" |
3928 | +mag_1420_erp_prd_16,magento1420,product.model_product_product,has_options,,in,function,unicode,,"result =[('x_magerp_has_options',ifield)]", |
3929 | +magento_1420_cst_grp_1,magento1420,base.model_res_partner_category,customer_group_code,,in,function,unicode,,"result=[('name',ifield)]", |
3930 | +magento_1420_cst_grp_3,magento1420,base.model_res_partner_category,tax_class_id,,in,function,int,,"result=[('tax_class_id',ifield)]", |
3931 | +magento_1420_prt_adr_2,magento1420,base.model_res_partner_address,city,,in_out,function,unicode,,"result=[('city',ifield)]", |
3932 | +magento_1420_prt_adr_3,magento1420,base.model_res_partner_address,fax,,in_out,function,unicode,,"result=[('fax',ifield)]", |
3933 | +magento_1420_prt_adr_4,magento1420,base.model_res_partner_address,firstname,,in_out,function,unicode,,"name = ' '.join([ f for f in (data['firstname'], data['lastname']) if f]) |
3934 | +if data.get('company'): |
3935 | + name = ""%s ; %s"" % (data['company'], name) |
3936 | +result = [('name', name), ('firstname', ifield), ('lastname', data['lastname'])]", |
3937 | +magento_1420_prt_adr_6,magento1420,base.model_res_partner_address,is_active,,in_out,function,unicode,,"result=[('active',bool(eval(ifield)))]", |
3938 | +magento_1420_prt_adr_7,magento1420,base.model_res_partner_address,country_id,,in_out,function,unicode,,"result = self.pool.get('res.country').search(cr,uid,[('code','=',ifield)]) |
3939 | +if result and len(result)==1: |
3940 | + result=[('country_id',result[0])] |
3941 | +else: |
3942 | + result=[] |
3943 | +", |
3944 | +magento_1420_prt_adr_8,magento1420,base.model_res_partner_address,street,,in_out,function,unicode,,"if ifield: |
3945 | + if len(ifield.split('\n')) ==2 : |
3946 | + result = [('street', ifield.split('\n')[0]) , ('street2', ifield.split('\n')[1])] |
3947 | + else : |
3948 | + result = [('street',ifield.replace('\\n',','))] |
3949 | +else: |
3950 | + result = []", |
3951 | +magento_1420_prt_adr_9,magento1420,base.model_res_partner_address,postcode,,in_out,function,unicode,,"result=[('zip',ifield)]", |
3952 | +magento_1420_prt_adr_10,magento1420,base.model_res_partner_address,telephone,,in_out,function,unicode,,"result=[('phone',ifield)]", |
3953 | +magento_1420_prt_adr_11,magento1420,base.model_res_partner_address,region,,in_out,function,unicode,,"if ifield: |
3954 | + result = self.pool.get('res.country.state').search(cr,uid,[('name','=ilike',ifield)]) |
3955 | + if result and len(result)==1: |
3956 | + result = [('state_id',result[0])] |
3957 | + else: |
3958 | + result=[] |
3959 | +else: |
3960 | + result=[]", |
3961 | +magento_1420_prt_adr_13,magento1420,base.model_res_partner_address,customer_id,,in_out,function,int,,"result=self.pool.get('res.partner').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
3962 | +if result: |
3963 | + result=[('partner_id',result)] |
3964 | +else: |
3965 | + result=[('partner_id',False)]", |
3966 | +magento_1420_prt_adr_14,magento1420,base.model_res_partner_address,address_type,,in_out,function,unicode,,"if ifield=='billing': |
3967 | + result=[('type','invoice')] |
3968 | +elif ifield=='shipping': |
3969 | + result=[('type','delivery')] |
3970 | +else: |
3971 | + result=[]", |
3972 | +magento_1420_prt_adr_15,magento1420,base.model_res_partner_address,email,,in_out,function,unicode,,"result = [('email', False)] |
3973 | +if ifield: |
3974 | + result = [('email', ifield)] |
3975 | +else: |
3976 | + partner_obj = self.pool.get('res.partner') |
3977 | + partner_id = partner_obj.extid_to_existing_oeid(cr, uid, data['customer_id'] ,external_referential_id) |
3978 | + if partner_id: |
3979 | + result = [('email', partner_obj.browse(cr, uid, partner_id).emailid)]", |
3980 | +magento_1420_prt_adr_17,magento1420,base.model_res_partner_address,default_billing,,in_out,function,unicode,,"result = [('type', 'other')] |
3981 | +if data.get('default_billing') and data.get('default_shipping'): |
3982 | + result = [('type', 'default')] |
3983 | +elif data.get('default_billing'): |
3984 | + result = [('type', 'invoice')] |
3985 | +elif data.get('default_shipping'): |
3986 | + result = [('type', 'delivery')]", |
3987 | +magento_1420_prt_2,magento1420,base.model_res_partner,group_id,,in_out,function,int,,"if ifield: |
3988 | + result=self.pool.get('res.partner.category').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
3989 | + if result: |
3990 | + result=[('group_id',result)]", |
3991 | +magento_1420_prt_3,magento1420,base.model_res_partner,store_id,,in_out,function,int,,"if ifield: |
3992 | + result=self.pool.get('magerp.storeviews').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
3993 | + if result: |
3994 | + store = self.pool.get('magerp.storeviews').browse(cr, uid, result) |
3995 | + lang = store.lang_id |
3996 | + result=[('store_id',result),('lang',lang and lang.code or False)] |
3997 | + if not data.get('website_id'): |
3998 | + result.append(('website_id', store.website_id.id))", |
3999 | +magento_1420_prt_4,magento1420,base.model_res_partner,website_id,,in_out,function,int,,"if ifield: |
4000 | + result=self.pool.get('external.shop.group').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
4001 | + if result: |
4002 | + result=[('website_id',result)]", |
4003 | +magento_1420_prt_5,magento1420,base.model_res_partner,created_in,,in_out,function,unicode,,"result=[('created_in',ifield)]", |
4004 | +magento_1420_prt_6,magento1420,base.model_res_partner,created_at,,in_out,function,unicode,,"result=[('created_at',ifield)]", |
4005 | +magento_1420_prt_7,magento1420,base.model_res_partner,updated_at,,in_out,function,unicode,,"result=[('updated_at',ifield)]", |
4006 | +magento_1420_prt_8,magento1420,base.model_res_partner,firstname,,in_out,function,unicode,,"result = [('name', ifield + ' ' + data['lastname'])]","add_id = self.browse(cr, uid, record['id']) |
4007 | +fn = add_id.address[0].firstname |
4008 | +ln = add_id.address[0].lastname |
4009 | +result=[('firstname', fn), ('lastname', ln)]" |
4010 | +magento_1420_prt_10,magento1420,base.model_res_partner,email,,in_out,function,unicode,,"result=[('emailid',ifield)]", |
4011 | +magento_1420_prt_11,magento1420,base.model_res_partner,taxvat,,in_out,function,unicode,,"if ifield: |
4012 | + result=[('mag_vat',ifield)] |
4013 | +else: |
4014 | + result=[]", |
4015 | +magento_1420_prt_12,magento1420,base.model_res_partner,dob,,in_out,function,unicode,,"if ifield: |
4016 | + result =[('mag_birthday',ifield[:10])] |
4017 | +else: |
4018 | + result=[]", |
4019 | |
4020 | === added file 'magentoerpconnect/settings/1.4.2.0/external.referential.type.csv' |
4021 | --- magentoerpconnect/settings/1.4.2.0/external.referential.type.csv 1970-01-01 00:00:00 +0000 |
4022 | +++ magentoerpconnect/settings/1.4.2.0/external.referential.type.csv 2012-07-06 14:53:18 +0000 |
4023 | @@ -0,0 +1,2 @@ |
4024 | +"id","name" |
4025 | +"magento1420","Magento Version 1.4.2.0+" |
4026 | |
4027 | === modified file 'magentoerpconnect/settings/1.5.0.0/external.mapping.template.csv' |
4028 | --- magentoerpconnect/settings/1.5.0.0/external.mapping.template.csv 2012-05-19 11:35:11 +0000 |
4029 | +++ magentoerpconnect/settings/1.5.0.0/external.mapping.template.csv 2012-07-06 14:53:18 +0000 |
4030 | @@ -1,3 +1,4 @@ |
4031 | +<<<<<<< TREE |
4032 | id,extra_name,version_id:id,model_id:id,external_list_method,external_get_method,external_update_method,external_create_method,external_delete_method,external_search_method,external_done_method,key_for_external_id,external_resource_name |
4033 | mag1500_external_shop_group,,magentoerpconnect.magento1500,base_sale_multichannels.model_external_shop_group,ol_websites.list,,,,,,,website_id, |
4034 | mag1500_magerp_storeviews,,magentoerpconnect.magento1500,magentoerpconnect.model_magerp_storeviews,ol_storeviews.list,,,,,,,store_id, |
4035 | @@ -14,3 +15,19 @@ |
4036 | mag1500_sale_order,,magentoerpconnect.magento1500,base_sale_multichannels.model_sale_order,sales_order.list,sales_order.info,,,,sales_order.search,sales_order.done,increment_id, |
4037 | mag1500_account_invoice,,magentoerpconnect.magento1500,account.model_account_invoice,,,,,,,,, |
4038 | mag1500_product_link,,magentoerpconnect.magento1500,magentoerpconnect.model_product_link,,,,,,,,, |
4039 | +======= |
4040 | +"id","type_id:id","model_id:id","external_list_method","external_get_method","external_update_method","external_create_method","external_delete_method","external_key_name" |
4041 | +"magento_1500_website","magento1500","base_sale_multichannels.model_external_shop_group","ol_websites.list",,,,,"website_id" |
4042 | +"magento_1500_storeview","magento1500","model_magerp_storeviews","ol_storeviews.list",,,,,"store_id" |
4043 | +"magento_1500_store","magento1500","sale.model_sale_shop","ol_groups.list",,,,,"group_id" |
4044 | +"magento_1500_order","magento1500","sale.model_sale_order","sales_order.list","sales_order.info",,,,"increment_id" |
4045 | +"magento_1500_order_line","magento1500","sale.model_sale_order_line",,,,,,"item_id" |
4046 | +"magento_1500_pro_cat","magento1500","product.model_product_category","category.list","category.info","catalog_category.update","catalog_category.create",,"category_id" |
4047 | +"magento_1500_attr_grp","magento1500","model_magerp_product_attribute_groups","ol_catalog_product_attribute_group.list","ol_catalog_product_attribute_group.list",,,,"attribute_group_id" |
4048 | +"magento_1500_attr_set","magento1500","model_magerp_product_attribute_set","ol_catalog_product_attributeset.list",,,,,"attribute_set_id" |
4049 | +"magento_1500_attr","magento1500","model_magerp_product_attributes","ol_catalog_product_attribute.list",,,,,"attribute_id" |
4050 | +"magento_1500_prd","magento1500","product.model_product_product","catalog_product.list","catalog_product.info","ol_catalog_product.update","ol_catalog_product.create",,"product_id" |
4051 | +"magento_1500_cst_grp","magento1500","base.model_res_partner_category","ol_customer_groups.list",,,,,"customer_group_id" |
4052 | +"magento_1500_prt_adr","magento1500","base.model_res_partner_address","ol_customer_address.list","ol_customer_address.info",,,,"entity_id" |
4053 | +"magento_1500_prt","magento1500","base.model_res_partner","customer.list","customer.info","customer.update",,,"customer_id" |
4054 | +>>>>>>> MERGE-SOURCE |
4055 | |
4056 | === added file 'magentoerpconnect/settings/1.5.0.0/external.mappinglines.template.csv.OTHER' |
4057 | --- magentoerpconnect/settings/1.5.0.0/external.mappinglines.template.csv.OTHER 1970-01-01 00:00:00 +0000 |
4058 | +++ magentoerpconnect/settings/1.5.0.0/external.mappinglines.template.csv.OTHER 2012-07-06 14:53:18 +0000 |
4059 | @@ -0,0 +1,330 @@ |
4060 | +id,type_id:id,model_id:id,external_field,field_id:id,type,evaluation_type,external_type,child_mapping_id:id,in_function,out_function |
4061 | +mag_1500_erp_s_name,magento1500,base_sale_multichannels.model_external_shop_group,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
4062 | +mag_1500_erp_s_code,magento1500,base_sale_multichannels.model_external_shop_group,code,,in_out,function,unicode,,"result=[('code',ifield)]", |
4063 | +mag_1500_erp_s_web,magento1500,base_sale_multichannels.model_external_shop_group,website_id,,in_out,function,int,,"result=[('website_id',ifield)]", |
4064 | +mag_1500_erp_s_isa,magento1500,base_sale_multichannels.model_external_shop_group,is_default,,in_out,function,unicode,,"result=[('is_default',bool(eval(ifield)))]", |
4065 | +mag_1500_erp_s_stord,magento1500,base_sale_multichannels.model_external_shop_group,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]", |
4066 | +mag_1500_erp_s_gpid,magento1500,base_sale_multichannels.model_external_shop_group,default_group_id,,in_out,function,int,,"result=[('default_shop_integer_id',ifield)]", |
4067 | +mag_1500_erp_sv_name,magento1500,model_magerp_storeviews,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
4068 | +mag_1500_erp_sv_code,magento1500,model_magerp_storeviews,code,,in_out,function,unicode,,"result=[('code',ifield)]", |
4069 | +mag_1500_erp_sv_sg,magento1500,model_magerp_storeviews,website_id,,in_out,function,int,,"result=[('website_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
4070 | +mag_1500_erp_sv_isa,magento1500,model_magerp_storeviews,is_active,,in_out,function,unicode,,"result=[('is_active',bool(eval(ifield)))]", |
4071 | +mag_1500_erp_sv_stord,magento1500,model_magerp_storeviews,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]", |
4072 | +mag_1500_erp_sv_gpid,magento1500,model_magerp_storeviews,group_id,,in_out,function,int,,"result=[('shop_id',self.pool.get('sale.shop').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
4073 | +mag_1500_erp_st_name,magento1500,sale.model_sale_shop,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]" |
4074 | +mag_1500_erp_st_gpid,magento1500,sale.model_sale_shop,group_id,,in_out,function,int,,"result=[('group_id',ifield)]", |
4075 | +mag_1500_erp_st_grp,magento1500,sale.model_sale_shop,website_id,,in_out,function,int,,"result=[('shop_group_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
4076 | +mag_1500_erp_st_default_st,magento1500,sale.model_sale_shop,default_store_id,,in_out,function,int,,"result=[('default_storeview_integer_id',ifield)]", |
4077 | +mag_1500_erp_st_root_categ,magento1500,sale.model_sale_shop,root_category_id,,in_out,function,int,,"result=[('root_category_id',ifield)]", |
4078 | +mag_1500_erp_so_name,magento1500,sale.model_sale_order,increment_id,,in_out,function,unicode,,"result=[('magento_incrementid',str(ifield)), ('name','mag_' + str(ifield))]", |
4079 | +mag_1500_erp_so_total_amount,magento1500,sale.model_sale_order,grand_total,,in_out,function,float,,"result=[('ext_total_amount',str(ifield))]", |
4080 | +mag_1500_erp_so_carrier_id,magento1500,sale.model_sale_order,shipping_method,,in_out,function,unicode,,"if ifield: |
4081 | + carrier_ids = self.pool.get('delivery.carrier').search(cr, uid, [('magento_code', '=', ifield)]) |
4082 | + if carrier_ids: |
4083 | + result=[('carrier_id', carrier_ids[0])] |
4084 | + else: |
4085 | + fake_partner_id = self.pool.get('res.partner').search(cr, uid, [])[0] |
4086 | + model_data_obj = self.pool.get('ir.model.data') |
4087 | + model, product_id = model_data_obj.get_object_reference(cr, uid, 'base_sale_multichannels', 'product_product_shipping') |
4088 | + carrier_id = self.pool.get('delivery.carrier').create(cr, uid, {'partner_id' : fake_partner_id, 'product_id' : product_id, 'name' : ifield, 'magento_code' : ifield}) |
4089 | + result=[('carrier_id', carrier_id)]", |
4090 | +mag_1500_erp_so_pay,magento1500,sale.model_sale_order,payment,,in_out,function,unicode,," |
4091 | +payments_mapping = {'checkmo': 'manual', 'ccsave': 'prepaid', 'free':'prepaid','googlecheckout':'prepaid','paypayl_express':'prepaid', 'paybox_system': 'prepaid', 'paypal_standard': 'prepaid', 'cashondelivery': 'manual', 'servired_standard': 'prepaid', 'bbva': 'prepaid', 'cofidis': 'prepaid'} |
4092 | +ifield=eval(ifield) |
4093 | +result=[('order_policy', ifield['method'] in payments_mapping and payments_mapping[ifield['method']] or 'prepaid'), ('ext_payment_method', ifield['method'])]", |
4094 | + |
4095 | +mag_1500_erp_so_item,magento1500,sale.model_sale_order,items,sale.field_sale_order_order_line,in,sub-mapping,dict,magento_1500_order_line,, |
4096 | +"mag_1500_erp_soline_name","magento1500","sale.model_sale_order_line","name",,"in_out","function","unicode",,"result=[('name', ifield)] |
4097 | +", |
4098 | +"Mag_1500_erp_soline_note","magento1500","sale.model_sale_order_line","product_options",,"in","function","unicode",,"if ifield: |
4099 | + import re |
4100 | + options_label = [] |
4101 | + clean = re.sub('\w:\w:|\w:\w+;', '', ifield) |
4102 | + for each in clean.split('{'): |
4103 | + if each.startswith('""label""'): |
4104 | + split_info = each.split(';') |
4105 | + options_label.append('%s: %s [%s]' % (split_info[1], split_info[3], data['sku'])) |
4106 | + |
4107 | + result=[('notes', """".join(options_label).replace('""""', '\n').replace('""', ''))] |
4108 | +", |
4109 | +mag_1500_erp_soline_pid,magento1500,sale.model_sale_order_line,product_id,,in_out,function,unicode,,"context['alternative_key'] = data['sku'] |
4110 | +result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
4111 | +mag_1500_erp_soline_uomqty,magento1500,sale.model_sale_order_line,qty_ordered,,in_out,function,unicode,,"result=[('product_uom_qty',ifield)]", |
4112 | +mag_1500_erp_soline_uosqty,magento1500,sale.model_sale_order_line,qty_ordered,,in,function,unicode,,"result=[('product_uos_qty',ifield)]", |
4113 | +mag_1500_erp_soline_price,magento1500,sale.model_sale_order_line,price,,in,function,unicode,,"if context.get('price_is_tax_included', False): |
4114 | + result=[('price_unit', (float(data['row_total']) + float(data['tax_amount']))/float(data['qty_ordered']))] |
4115 | +else: |
4116 | + result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]", |
4117 | +mag_1500_erp_soline_disc,magento1500,sale.model_sale_order_line,discount_amount,,in,function,float,,"if ifield: |
4118 | + result=[('discount', float(data['price']) != 0 and float(data['qty_ordered']) != 0 and float(100*ifield)/(float(data['price'])*float(data['qty_ordered'])) or 0)]", |
4119 | +mag_1500_erp_procat_2,magento1500,product.model_product_category,level,,in,function,int,,"result=[('sequence',ifield),('level',ifield)]", |
4120 | +mag_1500_erp_procat_3,magento1500,product.model_product_category,parent_id,,in_out,function,int,,"record_id = self.pool.get('ir.model.data').search(cr, uid, [('model', '=', self._name), ('name', '=', self.prefixed_id(ifield))]) |
4121 | +parent_id = False |
4122 | +if record_id: |
4123 | + parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[]) |
4124 | + parent_id=parent_rec.get('res_id',False) |
4125 | +result=[('magento_parent_id',ifield),('parent_id',parent_id)]","magento_parent_id = False |
4126 | +if record.get('parent_id',False): |
4127 | + magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) |
4128 | + if not magento_parent_id: |
4129 | + self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[external_referential_id],{},context=context) |
4130 | + magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) |
4131 | +if magento_parent_id: |
4132 | + result = [('parent_id',magento_parent_id)]" |
4133 | +mag_1500_erp_procat_4,magento1500,product.model_product_category,is_active,,in_out,function,unicode,,"result=[('is_active',ifield and (eval(ifield)) or False)]","result=[('is_active',record['is_active'])]" |
4134 | +mag_1500_erp_procat_5,magento1500,product.model_product_category,description,,in_out,function,unicode,,"result=[('description',ifield)]","result=[('description',record['description'])]" |
4135 | +mag_1500_erp_procat_6,magento1500,product.model_product_category,meta_title,,in_out,function,unicode,,"result=[('meta_title',ifield)]","result=[('meta_title',record['meta_title'])]" |
4136 | +mag_1500_erp_procat_7,magento1500,product.model_product_category,meta_keywords,,in_out,function,unicode,,"result=[('meta_keywords',ifield)]","result=[('meta_keywords',record['meta_keywords'])]" |
4137 | +mag_1500_erp_procat_8,magento1500,product.model_product_category,meta_description,,in_out,function,unicode,,"result=[('meta_description',ifield)]","result=[('meta_description',record['meta_description'])]" |
4138 | +mag_1500_erp_procat_9,magento1500,product.model_product_category,url_key,,in_out,function,unicode,,"result=[('url_key',ifield)]","if context.get('export_url', False) : |
4139 | + result=[('url_key',record['url_key'])]" |
4140 | +mag_1500_erp_procat_10,magento1500,product.model_product_category,name,,in_out,function,unicode,,"result=[('name',ifield or 'UNDEFINED'),('magento_exportable',True)]","result=[('name',record['name'])]" |
4141 | +mag_1500_erp_procat_11,magento1500,product.model_product_category,is_anchor,,in_out,function,unicode,,"result=[('is_anchor',ifield and bool(eval(ifield)) or False)]","result=[('is_anchor',record['is_anchor'])]" |
4142 | +mag_1500_erp_procat_12,magento1500,product.model_product_category,available_sort_by,,in_out,function,unicode,,"attr_ids = [] |
4143 | +cat_attr_obj = self.pool.get('magerp.product_category_attribute_options') |
4144 | +if ifield: |
4145 | + for val in ifield: |
4146 | + attr_ids.append(cat_attr_obj.get_create_option_id(cr, uid, val,'sort_by', context=context)) |
4147 | + result=[('available_sort_by', [(6, 0, attr_ids)]), ('use_default_available_sort_by', False)] |
4148 | +else: |
4149 | + result=[('use_default_available_sort_by', True)]","if record['use_default_available_sort_by']: |
4150 | + res = u'' |
4151 | +else: |
4152 | + res = [] |
4153 | + for cat_attr_option in self.pool.get('magerp.product_category_attribute_options').browse(cr, uid, record['available_sort_by'], context=context): |
4154 | + res.append(cat_attr_option.value) |
4155 | +result=[('available_sort_by', res)]" |
4156 | +mag_1500_erp_procat_13,magento1500,product.model_product_category,default_sort_by,,in_out,function,unicode,,"if ifield: |
4157 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'sort_by', context=context) |
4158 | +else: |
4159 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','sort_by', context=context) |
4160 | +result=[('default_sort_by',att_id)]","options_obj = self.pool.get('magerp.product_category_attribute_options') |
4161 | +cat_attr_option_id = record['default_sort_by'] |
4162 | +if cat_attr_option_id: |
4163 | + cat_attr_option_id = cat_attr_option_id[0] |
4164 | +else: |
4165 | + cat_attr_option_id = options_obj._get_default_option(cr, uid, 'sort_by', '', context=context)[0] |
4166 | + |
4167 | +cat_attr_option = options_obj.browse(cr, uid, cat_attr_option_id, context=context) |
4168 | +result=[('default_sort_by', cat_attr_option.value)]" |
4169 | +mag_1500_erp_procat_14,magento1500,product.model_product_category,updated_at,,in,function,unicode,,"result=[('magerp_stamp',ifield)]", |
4170 | +mag_1500_erp_procat_15,magento1500,product.model_product_category,image,,in_out,function,unicode,,"image_binary = False |
4171 | +if ifield and not ifield=='None': |
4172 | + try: |
4173 | + image_binary = conn.call('ol_catalog_category_media.info', [int(data['category_id'])]) |
4174 | + except Exception, e: |
4175 | + print e |
4176 | + pass |
4177 | + if image_binary: |
4178 | + image_binary = base64.encodestring(base64.urlsafe_b64decode(image_binary[0]['image_data'])) |
4179 | +result=[('image_name',ifield),('image',image_binary)]","if record['image']: |
4180 | + img = base64.decodestring(record['image']) |
4181 | + img_bin_enc = base64.encodestring(img) |
4182 | + conn.call('ol_catalog_category_media.create', [record['image_name'], img_bin_enc]) |
4183 | + result = [('image',record['image_name'])] |
4184 | +else: |
4185 | + result=[]" |
4186 | +mag_1500_erp_procat_16,magento1500,product.model_product_category,include_in_menu,,in_out,function,unicode,,"result=[('include_in_menu', ifield and (eval(ifield)) or False)]","result=[('include_in_menu',record['include_in_menu'])]" |
4187 | +mag_1500_erp_procat_17,magento1500,product.model_product_category,page_layout,,in_out,function,unicode,,"if ifield: |
4188 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'page_layout', context=context) |
4189 | +else: |
4190 | + att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','page_layout', context=context) |
4191 | +result=[('page_layout',att_id)]","page_layout = record['page_layout'] and record['page_layout'][1] or '' |
4192 | +result=[('page_layout', page_layout)]" |
4193 | +mag_1500_erp_attrgrp_2,magento1500,model_magerp_product_attribute_groups,attribute_set_id,,in_out,function,int,,"result=[('attribute_set_id', ifield)]","result=[('attribute_set_id', record['attribute_set_id'])]" |
4194 | +mag_1500_erp_attrgrp_3,magento1500,model_magerp_product_attribute_groups,attribute_group_name,,in_out,function,unicode,,"result=[('attribute_group_name', ifield)]","result=[('attribute_group_name', record['attribute_group_name'])]" |
4195 | +mag_1500_erp_attrgrp_4,magento1500,model_magerp_product_attribute_groups,sort_order,,in_out,function,int,,"result=[('sort_order', ifield)]","result=[('sort_order', record['sort_order'])]" |
4196 | +mag_1500_erp_attrgrp_5,magento1500,model_magerp_product_attribute_groups,default_id,,in_out,function,int,,"result=[('default_id', ifield)]","result=[('default_id', record['default_id'])]" |
4197 | +mag_1500_erp_attrset_1,magento1500,model_magerp_product_attribute_set,attribute_set_id,,in_out,function,int,,"result=[('magento_id', ifield)]","result=[('attribute_set_id', record['magento_id'])]" |
4198 | +mag_1500_erp_attrset_2,magento1500,model_magerp_product_attribute_set,sort_order,,in_out,function,int,,"result=[('sort_order', ifield)]","result=[('sort_order', record['sort_order'])]" |
4199 | +mag_1500_erp_attrset_3,magento1500,model_magerp_product_attribute_set,attribute_set_name,,in_out,function,unicode,,"result=[('attribute_set_name', ifield)]","result=[('attribute_set_name', record['attribute_set_name'])]" |
4200 | +mag_1500_erp_attr_1,magento1500,model_magerp_product_attributes,attribute_code,,in_out,function,unicode,,"result=[('attribute_code', ifield)]","result=[('code', record['attribute_code'])]" |
4201 | +mag_1500_erp_attr_2,magento1500,model_magerp_product_attributes,attribute_id,,in_out,function,int,,"result=[('magento_id', ifield)]", |
4202 | +mag_1500_erp_attr_3,magento1500,model_magerp_product_attributes,frontend_input,,in_out,function,unicode,,"result=[('frontend_input', ifield)]","result=[('frontend_input', record['frontend_input'])]" |
4203 | +mag_1500_erp_attr_4,magento1500,model_magerp_product_attributes,frontend_class,,in_out,function,unicode,,"result=[('frontend_class', ifield)]","result=[('frontend_class', record['frontend_class'])]" |
4204 | +mag_1500_erp_attr_5,magento1500,model_magerp_product_attributes,backend_model,,in_out,function,unicode,,"result=[('backend_model', ifield)]","result=[('backend_model', record['backend_model'])]" |
4205 | +mag_1500_erp_attr_6,magento1500,model_magerp_product_attributes,backend_type,,in_out,function,unicode,,"result=[('backend_type', ifield)]","result=[('backend_type', record['backend_type'])]" |
4206 | +mag_1500_erp_attr_7,magento1500,model_magerp_product_attributes,frontend_label,,in_out,function,unicode,,"result=[('frontend_label', ifield)]","result=[('frontend_label', record['frontend_label'])]" |
4207 | +mag_1500_erp_attr_8,magento1500,model_magerp_product_attributes,is_visible_in_advanced_search,,in_out,function,unicode,,"result=[('is_visible_in_advanced_search', bool(eval(ifield)))]","result=[('is_visible_in_advanced_search', record['is_visible_in_advanced_search'])]" |
4208 | +mag_1500_erp_attr_9,magento1500,model_magerp_product_attributes,is_global,,in_out,function,unicode,,"result=[('is_global', bool(eval(ifield)))]","result=[('is_global', record['is_global'])]" |
4209 | +mag_1500_erp_attr_10,magento1500,model_magerp_product_attributes,is_filterable,,in_out,function,unicode,,"result=[('is_filterable', bool(eval(ifield)))]","result=[('is_filterable', record['is_filterable'])]" |
4210 | +mag_1500_erp_attr_11,magento1500,model_magerp_product_attributes,is_comparable,,in_out,function,unicode,,"result=[('is_comparable', bool(eval(ifield)))]","result=[('is_comparable', record['is_comparable'])]" |
4211 | +mag_1500_erp_attr_12,magento1500,model_magerp_product_attributes,is_visible,,in_out,function,unicode,,"result=[('is_visible', bool(eval(ifield)))]","result=[('is_visible', record['is_visible'])]" |
4212 | +mag_1500_erp_attr_13,magento1500,model_magerp_product_attributes,is_searchable,,in_out,function,unicode,,"result=[('is_searchable', bool(eval(ifield)))]","result=[('is_searchable', record['is_searchable'])]" |
4213 | +mag_1500_erp_attr_14,magento1500,model_magerp_product_attributes,is_user_defined,,in_out,function,unicode,,"result=[('is_user_defined', bool(eval(ifield)))]","result=[('is_user_defined', record['is_user_defined'])]" |
4214 | +mag_1500_erp_attr_15,magento1500,model_magerp_product_attributes,is_configurable,,in_out,function,unicode,,"result=[('is_configurable', bool(eval(ifield)))]","result=[('is_configurable', record['is_configurable'])]" |
4215 | +mag_1500_erp_attr_16,magento1500,model_magerp_product_attributes,is_visible_on_front,,in_out,function,unicode,,"result=[('is_visible_on_front', bool(eval(ifield)))]","result=[('is_visible_on_front', record['is_visible_on_front'])]" |
4216 | +mag_1500_erp_attr_17,magento1500,model_magerp_product_attributes,is_used_for_price_rules,,in_out,function,unicode,,"result=[('is_used_for_price_rules', bool(eval(ifield)))]","result=[('is_used_for_price_rules', record['is_used_for_price_rules'])]" |
4217 | +mag_1500_erp_attr_18,magento1500,model_magerp_product_attributes,is_unique,,in_out,function,unicode,,"result=[('is_unique', bool(eval(ifield)))]","result=[('is_unique', record['is_unique'])]" |
4218 | +mag_1500_erp_attr_19,magento1500,model_magerp_product_attributes,is_required,,in_out,function,unicode,,"result=[('is_required', bool(eval(ifield)))]","result=[('is_required', record['is_required'])]" |
4219 | +mag_1500_erp_attr_20,magento1500,model_magerp_product_attributes,position,,in_out,function,int,,"result=[('position', ifield)]","result=[('position', record['position'])]" |
4220 | +mag_1500_erp_attr_21,magento1500,model_magerp_product_attributes,attribute_set_info,,in_out,function,unicode,,"result=[('attribute_set_info', ifield)]","result=[('attribute_set_info', record['attribute_set_info'])]" |
4221 | +mag_1500_erp_attr_22,magento1500,model_magerp_product_attributes,default_value,,in_out,function,unicode,,"result=[('default_value', ifield)]","result=[('default_value', record['default_value'])]" |
4222 | +mag_1500_erp_attr_23,magento1500,model_magerp_product_attributes,note,,in_out,function,unicode,,"result=[('note', ifield)]","result=[('note', record['note'])]" |
4223 | +mag_1500_erp_attr_24,magento1500,model_magerp_product_attributes,entity_type_id,,in_out,function,int,,"result=[('entity_type_id', ifield)]","result=[('entity_type_id', record['entity_type_id'])]" |
4224 | +mag_1500_erp_attr_25,magento1500,model_magerp_product_attributes,apply_to,,in_out,function,unicode,,"result=[('apply_to', str(ifield))]","result=[('apply_to', eval(record['%s']))]" |
4225 | +mag_1500_erp_prd_1,magento1500,product.model_product_product,url_key,,in_out,function,unicode,,"result=[('x_magerp_url_key',ifield)]","if context.get('export_url', False) : |
4226 | + result=[('url_key',record['x_magerp_url_key'])]" |
4227 | +mag_1500_erp_prd_2,magento1500,product.model_product_product,name,,in_out,function,unicode,,"result = [('name',ifield)]","result = [('name',record['name'])]" |
4228 | +mag_1500_erp_prd_3,magento1500,product.model_product_product,description,,in_out,function,unicode,,"result = [('description',ifield)]", |
4229 | +mag_1500_erp_prd_4,magento1500,product.model_product_product,short_description,,in_out,function,unicode,,"result = [('description_sale',ifield)]", |
4230 | +mag_1500_erp_prd_5,magento1500,product.model_product_product,sku,,in_out,function,unicode,,"result = [('magento_sku',ifield), ('default_code',ifield)]", |
4231 | +mag_1500_erp_prd_6,magento1500,product.model_product_product,weight,,in_out,function,float,,"result = [('weight',ifield)]","result = [('weight',record['weight'] or 0)]" |
4232 | +mag_1500_erp_prd_7,magento1500,product.model_product_product,categories,,in_out,function,list,,"categ_ids =[] |
4233 | +if ifield: |
4234 | + for category_id in ifield: |
4235 | + categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, category_id, external_referential_id, context=context)) |
4236 | + main_categ_id = categ_ids.pop() |
4237 | +else: |
4238 | + main_categ_id = self.pool.get('external.referential').browse(cr, uid, external_referential_id).default_pro_cat.id |
4239 | +result = [('categ_id', main_categ_id), ('categ_ids',[(6, 0, categ_ids)])]"," |
4240 | +cat_obj = self.pool.get('product.category') |
4241 | +product = self.browse(cr, uid, record['id']) |
4242 | +categ_ids = [categ.id for categ in ([product.categ_id] + product.categ_ids) if categ.magento_exportable] |
4243 | +mag_categ_ids = [] |
4244 | +for categ_id in categ_ids: |
4245 | + mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id) |
4246 | + if not mag_categ_id: |
4247 | + ctx = dict(context, force_export=True) |
4248 | + cat_obj.ext_export(cr, uid, [categ_id], [external_referential_id], context=ctx) |
4249 | + mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id) |
4250 | + mag_categ_ids.append(mag_categ_id) |
4251 | +result=[('category_ids', mag_categ_ids)]" |
4252 | +mag_1500_erp_prd_8,magento1500,product.model_product_product,price,,in_out,function,float,,"result=[('list_price',ifield)]",result=[]#map later |
4253 | +mag_1500_erp_prd_9,magento1500,product.model_product_product,cost,,in_out,function,float,,"result=[('standard_price',ifield)]","result = [('cost',record['standard_price'] or 0)]" |
4254 | +mag_1500_erp_prd_10,magento1500,product.model_product_product,set,,in_out,function,unicode,,"result=[('set',self.pool.get('magerp.product_attribute_set').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]", |
4255 | +mag_1500_erp_prd_11,magento1500,product.model_product_product,special_price,,in_out,function,float,,"result = [('x_magerp_special_price',ifield)]", |
4256 | +mag_1500_erp_prd_12,magento1500,product.model_product_product,tier_price,,in_out,function,unicode,,result=[]#no mapping by default,result=[]#no mapping by default |
4257 | +mag_1500_erp_prd_13,magento1500,product.model_product_product,minimal_price,,in_out,function,float,,"result = [('x_magerp_minimal_price',ifield)]"," |
4258 | +if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0: |
4259 | + result = [('minimal_price',record['x_magerp_minimal_price'])] |
4260 | +else: |
4261 | + result = [('minimal_price',False)]" |
4262 | +mag_1500_erp_prd_14,magento1500,product.model_product_product,type_id,,in_out,function,unicode,,"if ifield: |
4263 | + product_type_ids = self.pool.get('magerp.product_product_type').search(cr,uid,[('product_type','=',ifield)]) |
4264 | + if product_type_ids: |
4265 | + result = [('product_type',ifield)]","if 'product_type' in record and record['product_type']: |
4266 | + result = [('type_id',record['product_type'])] |
4267 | +else: |
4268 | + result = [('type_id','simple')]" |
4269 | +mag_1500_erp_prd_15,magento1500,product.model_product_product,websites,,in_out,function,list,,"websites_ids = [] |
4270 | +for ext_id in ifield: |
4271 | + websites_ids.append(self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ext_id, external_referential_id, context=context)) |
4272 | + |
4273 | +##### OPTION START, with this if the field websites of the product is empty the product is exported on every website |
4274 | +all_oe_websites_ids = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)]) |
4275 | +if set(websites_ids) == set(all_oe_websites_ids): |
4276 | + websites_ids =[] |
4277 | +##### OPTION END |
4278 | + |
4279 | +result=[('websites_ids', [(6,0, websites_ids)])]","##### OPTION START, with this if the field websites of the product is empty the product is exported on every website |
4280 | +if not record['websites_ids']: |
4281 | + record['websites_ids'] = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)]) |
4282 | +##### OPTION END |
4283 | + |
4284 | +ext_websites_ids = [] |
4285 | +for oe_id in record['websites_ids']: |
4286 | + ext_websites_ids.append(self.pool.get('external.shop.group').oeid_to_extid(cr, uid, oe_id, external_referential_id)) |
4287 | + |
4288 | +result=[('websites', ext_websites_ids)]" |
4289 | +mag_1500_erp_prd_16,magento1500,product.model_product_product,has_options,,in,function,unicode,,"result =[('x_magerp_has_options',ifield)]", |
4290 | +magento_1500_cst_grp_1,magento1500,base.model_res_partner_category,customer_group_code,,in,function,unicode,,"result=[('name',ifield)]", |
4291 | +magento_1500_cst_grp_3,magento1500,base.model_res_partner_category,tax_class_id,,in,function,int,,"result=[('tax_class_id',ifield)]", |
4292 | +magento_1500_prt_adr_2,magento1500,base.model_res_partner_address,city,,in_out,function,unicode,,"result=[('city',ifield)]", |
4293 | +magento_1500_prt_adr_3,magento1500,base.model_res_partner_address,fax,,in_out,function,unicode,,"result=[('fax',ifield)]", |
4294 | +magento_1500_prt_adr_4,magento1500,base.model_res_partner_address,firstname,,in_out,function,unicode,,"name = ' '.join([ f for f in (data['firstname'], data['lastname']) if f]) |
4295 | +if data.get('company'): |
4296 | + name = ""%s ; %s"" % (data['company'], name) |
4297 | +result = [('name', name), ('firstname', ifield), ('lastname', data['lastname'])]", |
4298 | +magento_1500_prt_adr_6,magento1500,base.model_res_partner_address,is_active,,in_out,function,unicode,,"result=[('active',bool(eval(ifield)))]", |
4299 | +magento_1500_prt_adr_7,magento1500,base.model_res_partner_address,country_id,,in_out,function,unicode,,"result = self.pool.get('res.country').search(cr,uid,[('code','=',ifield)]) |
4300 | +if result and len(result)==1: |
4301 | + result=[('country_id',result[0])] |
4302 | +else: |
4303 | + result=[] |
4304 | +", |
4305 | +magento_1500_prt_adr_8,magento1500,base.model_res_partner_address,street,,in_out,function,unicode,,"if ifield: |
4306 | + if len(ifield.split('\n')) ==2 : |
4307 | + result = [('street', ifield.split('\n')[0]) , ('street2', ifield.split('\n')[1])] |
4308 | + else : |
4309 | + result = [('street',ifield.replace('\\n',','))] |
4310 | +else: |
4311 | + result = []", |
4312 | +magento_1500_prt_adr_9,magento1500,base.model_res_partner_address,postcode,,in_out,function,unicode,,"result=[('zip',ifield)]", |
4313 | +magento_1500_prt_adr_10,magento1500,base.model_res_partner_address,telephone,,in_out,function,unicode,,"result=[('phone',ifield)]", |
4314 | +magento_1500_prt_adr_11,magento1500,base.model_res_partner_address,region,,in_out,function,unicode,,"if ifield: |
4315 | + result = self.pool.get('res.country.state').search(cr,uid,[('name','=ilike',ifield)]) |
4316 | + if result and len(result)==1: |
4317 | + result = [('state_id',result[0])] |
4318 | + else: |
4319 | + result=[] |
4320 | +else: |
4321 | + result=[]", |
4322 | +magento_1500_prt_adr_13,magento1500,base.model_res_partner_address,customer_id,,in_out,function,int,," |
4323 | +if ifield: |
4324 | + result=self.pool.get('res.partner').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
4325 | + if result: |
4326 | + result=[('partner_id', result)] |
4327 | + else: |
4328 | + result=[('partner_id', False)]", |
4329 | +magento_1500_prt_adr_14,magento1500,base.model_res_partner_address,address_type,,in_out,function,unicode,,"if ifield=='billing': |
4330 | + result=[('type','invoice')] |
4331 | +elif ifield=='shipping': |
4332 | + result=[('type','delivery')] |
4333 | +else: |
4334 | + result=[]", |
4335 | +magento_1500_prt_adr_15,magento1500,base.model_res_partner_address,email,,in_out,function,unicode,,"result = [('email', False)] |
4336 | +if ifield: |
4337 | + result = [('email', ifield)] |
4338 | +else: |
4339 | + if data.get('customer_id'): |
4340 | + partner_obj = self.pool.get('res.partner') |
4341 | + partner_id = partner_obj.extid_to_existing_oeid(cr, uid, data['customer_id'] ,external_referential_id) |
4342 | + if partner_id: |
4343 | + result = [('email', partner_obj.browse(cr, uid, partner_id).emailid)] ", |
4344 | +magento_1500_prt_adr_16,magento1500,base.model_res_partner_address,prefix,,in_out,function,unicode,,"if ifield: |
4345 | + title_ids = self.pool.get('res.partner.title').search(cr, uid, [('domain', '=', 'contact'), ('shortcut', '=', ifield)]) |
4346 | + if title_ids: |
4347 | + title_id = title_ids[0] |
4348 | + else: |
4349 | + title_id = self.pool.get('res.partner.title').create(cr, uid, {'domain': 'contact', 'shortcut': ifield, 'name' : ifield}) |
4350 | + result=[('title', title_id)]", |
4351 | +magento_1500_prt_adr_17,magento1500,base.model_res_partner_address,default_billing,,in_out,function,unicode,,"result = [('type', 'other')] |
4352 | +if data.get('default_billing') and data.get('default_shipping'): |
4353 | + result = [('type', 'default')] |
4354 | +elif data.get('default_billing'): |
4355 | + result = [('type', 'invoice')] |
4356 | +elif data.get('default_shipping'): |
4357 | + result = [('type', 'delivery')]", |
4358 | +magento_1500_prt_2,magento1500,base.model_res_partner,group_id,,in_out,function,int,,"if ifield: |
4359 | + result=self.pool.get('res.partner.category').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
4360 | + if result: |
4361 | + result=[('group_id',result)]", |
4362 | +magento_1500_prt_3,magento1500,base.model_res_partner,store_id,,in_out,function,int,,"if ifield: |
4363 | + result=self.pool.get('magerp.storeviews').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
4364 | + if result: |
4365 | + store = self.pool.get('magerp.storeviews').browse(cr, uid, result) |
4366 | + lang = store.lang_id |
4367 | + result=[('store_id',result),('lang',lang and lang.code or False)] |
4368 | + if not data.get('website_id'): |
4369 | + result.append(('website_id', store.website_id.id))", |
4370 | +magento_1500_prt_4,magento1500,base.model_res_partner,website_id,,in_out,function,int,,"if ifield: |
4371 | + result=self.pool.get('external.shop.group').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context) |
4372 | + if result: |
4373 | + result=[('website_id',result)]", |
4374 | +magento_1500_prt_5,magento1500,base.model_res_partner,created_in,,in_out,function,unicode,,"result=[('created_in',ifield)]", |
4375 | +magento_1500_prt_6,magento1500,base.model_res_partner,created_at,,in_out,function,unicode,,"result=[('created_at',ifield)]", |
4376 | +magento_1500_prt_7,magento1500,base.model_res_partner,updated_at,,in_out,function,unicode,,"result=[('updated_at',ifield)]", |
4377 | +magento_1500_prt_8,magento1500,base.model_res_partner,firstname,,in_out,function,unicode,,"result = [('name', ifield + ' ' + data['lastname'])]","add_id = self.browse(cr, uid, record['id']) |
4378 | +fn = add_id.address[0].firstname |
4379 | +ln = add_id.address[0].lastname |
4380 | +result=[('firstname', fn), ('lastname', ln)]" |
4381 | +magento_1500_prt_10,magento1500,base.model_res_partner,email,,in_out,function,unicode,,"result=[('emailid',ifield)]", |
4382 | +magento_1500_prt_11,magento1500,base.model_res_partner,taxvat,,in_out,function,unicode,,"if ifield: |
4383 | + result=[('mag_vat',ifield)] |
4384 | +else: |
4385 | + result=[]", |
4386 | +magento_1500_prt_12,magento1500,base.model_res_partner,dob,,in_out,function,unicode,,"if ifield: |
4387 | + result =[('mag_birthday',ifield[:10])] |
4388 | +else: |
4389 | + result=[]", |
4390 | |
4391 | === added directory 'magentoerpconnect/settings/update' |
4392 | === added file 'magentoerpconnect/settings/update/fix_product_categories.sql' |
4393 | --- magentoerpconnect/settings/update/fix_product_categories.sql 1970-01-01 00:00:00 +0000 |
4394 | +++ magentoerpconnect/settings/update/fix_product_categories.sql 2012-07-06 14:53:18 +0000 |
4395 | @@ -0,0 +1,7 @@ |
4396 | +UPDATE product_category |
4397 | +SET default_sort_by=(SELECT id FROM magerp_product_category_attribute_options WHERE value='' and attribute_name='sort_by') |
4398 | +WHERE default_sort_by in (SELECT id FROM magerp_product_category_attribute_options WHERE value='None' and attribute_name='sort_by'); |
4399 | + |
4400 | +UPDATE product_category |
4401 | +SET page_layout=(SELECT id FROM magerp_product_category_attribute_options WHERE value='' and attribute_name='page_layout') |
4402 | +WHERE page_layout in (SELECT id FROM magerp_product_category_attribute_options WHERE value='None' and attribute_name='page_layout'); |
4403 | |
4404 | === added file 'magentoerpconnect/settings/update/magerp.product_category_attribute_options.xml' |
4405 | --- magentoerpconnect/settings/update/magerp.product_category_attribute_options.xml 1970-01-01 00:00:00 +0000 |
4406 | +++ magentoerpconnect/settings/update/magerp.product_category_attribute_options.xml 2012-07-06 14:53:18 +0000 |
4407 | @@ -0,0 +1,16 @@ |
4408 | +<?xml version="1.0" encoding="utf-8"?> |
4409 | +<openerp> |
4410 | + <data> |
4411 | + <record model='magerp.product_category_attribute_options' id='mag_product_category_attribute_1_1400'> |
4412 | + <field name="attribute_name">page_layout</field> |
4413 | + <field name="label">No layout updates</field> |
4414 | + <field name="value" eval='""' /> |
4415 | + </record> |
4416 | + |
4417 | + <record model='magerp.product_category_attribute_options' id='mag_product_category_attribute_7_1400'> |
4418 | + <field name="attribute_name">sort_by</field> |
4419 | + <field name="label">Use Config Settings</field> |
4420 | + <field name="value" eval='""' /> |
4421 | + </record> |
4422 | + </data> |
4423 | +</openerp> |
4424 | |
4425 | === modified file 'magentoerpconnect/stock.py' |
4426 | --- magentoerpconnect/stock.py 2012-05-25 15:37:26 +0000 |
4427 | +++ magentoerpconnect/stock.py 2012-07-06 14:53:18 +0000 |
4428 | @@ -20,6 +20,10 @@ |
4429 | ######################################################################### |
4430 | |
4431 | import xmlrpclib |
4432 | +<<<<<<< TREE |
4433 | +======= |
4434 | +import logging |
4435 | +>>>>>>> MERGE-SOURCE |
4436 | |
4437 | from osv import fields,osv |
4438 | from tools.translate import _ |
4439 | @@ -69,8 +73,13 @@ |
4440 | else: |
4441 | item_qty.update({product_2_item[line['product_id']]: line['product_qty']}) |
4442 | |
4443 | +<<<<<<< TREE |
4444 | ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, item_qty, _("Shipping Created"), mail_notification, True]) |
4445 | return ext_shipping_id |
4446 | +======= |
4447 | + ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, item_qty, _("Shipping Created"), mail_notification, True]) |
4448 | + return ext_shipping_id |
4449 | +>>>>>>> MERGE-SOURCE |
4450 | |
4451 | def create_ext_shipping(self, cr, uid, id, picking_type, external_referential_id, context=None): |
4452 | """ |
4453 | @@ -103,6 +112,8 @@ |
4454 | # in order to exclude it from the future exports |
4455 | if e.faultCode == 102: |
4456 | raise ExternalShippingCreateError(e) |
4457 | + else: |
4458 | + raise |
4459 | |
4460 | if ext_shipping_id and carrier_id: |
4461 | self.add_ext_tracking_reference(cr, uid, id, carrier_id, ext_shipping_id, context) |
4462 | @@ -110,6 +121,10 @@ |
4463 | |
4464 | def add_ext_tracking_reference(self, cr, uid, id, carrier_id, ext_shipping_id, context=None): |
4465 | if context is None: context = {} |
4466 | +<<<<<<< TREE |
4467 | +======= |
4468 | + logger = logging.getLogger('ext synchro') |
4469 | +>>>>>>> MERGE-SOURCE |
4470 | conn = context.get('conn_obj', False) |
4471 | carrier = self.pool.get('delivery.carrier').read(cr, uid, carrier_id, ['magento_carrier_code', 'magento_tracking_title'], context) |
4472 | |
4473 | @@ -120,7 +135,11 @@ |
4474 | |
4475 | res = conn.call('sales_order_shipment.addTrack', [ext_shipping_id, carrier['magento_carrier_code'], carrier['magento_tracking_title'] or '', carrier_tracking_ref or '']) |
4476 | if res: |
4477 | +<<<<<<< TREE |
4478 | _logger.info("Successfully adding a tracking reference to the shipping with OpenERP id %s and ext id %s in external sale system", id, ext_shipping_id) |
4479 | +======= |
4480 | + logger.info("Successfully adding a tracking reference to the shipping with OpenERP id %s and ext id %s in external sale system", id, ext_shipping_id) |
4481 | +>>>>>>> MERGE-SOURCE |
4482 | return True |
4483 | |
4484 | stock_picking() |
4485 | |
4486 | === modified file 'magentoerpconnect_payment/sale.py' |
4487 | --- magentoerpconnect_payment/sale.py 2012-03-27 09:40:33 +0000 |
4488 | +++ magentoerpconnect_payment/sale.py 2012-07-06 14:53:18 +0000 |
4489 | @@ -101,6 +101,89 @@ |
4490 | self._magento_create_invoice(cr, uid, order, context=context) |
4491 | return True |
4492 | |
4493 | + def _call_magento_invoice(self, cr, uid, order, order_external_data=None, context=None): |
4494 | + """Return the Magento data for all invoices |
4495 | + of an order |
4496 | + |
4497 | + :param browse_record order: browsable record of sale order |
4498 | + :param dict order_external_data: magento data of the order, optional, |
4499 | + a call to magento will be done to get the data if None |
4500 | + :return: list of magento invoices as dict |
4501 | + """ |
4502 | + if context is None: |
4503 | + context = {} |
4504 | + |
4505 | + referential = order.shop_id.referential_id |
4506 | + connection = context.get('conn_obj') or \ |
4507 | + referential.external_connection() |
4508 | + |
4509 | + # Filter on order_increment_id does not work |
4510 | + # on magento. |
4511 | + # So we need first to get the order id |
4512 | + # and filter the invoice on this order id |
4513 | + if not order_external_data: |
4514 | + order_ext_id = self.oeid_to_extid( |
4515 | + cr, uid, order.id, referential.id, context=context) |
4516 | + order_external_data = connection.call( |
4517 | + 'sales_order.info', [order_ext_id]) |
4518 | + |
4519 | + mag_order_id = order_external_data['order_id'] |
4520 | + return connection.call( |
4521 | + 'sales_order_invoice.list', [{'order_id': {'eq': mag_order_id}}]) |
4522 | + |
4523 | + def _get_missing_magento_invoice_number(self, cr, uid, order, external_data, context=None): |
4524 | + """Get the first invoice number for a magento order |
4525 | + and assign it to magento_ref fields |
4526 | + so we can later push it on the invoice |
4527 | + |
4528 | + :param browse_record order: browsable record of sale order |
4529 | + :param dict external_data: magento data of the order |
4530 | + :return: invoice number of magento |
4531 | + """ |
4532 | + invoice_number = False |
4533 | + mag_invoices = self._call_magento_invoice( |
4534 | + cr, uid, order, order_external_data=external_data, context=context) |
4535 | + if mag_invoices: |
4536 | + invoice_number = mag_invoices[0].get('increment_id') |
4537 | + |
4538 | + if invoice_number: |
4539 | + self.write( |
4540 | + cr, uid, order.id, |
4541 | + {'magento_ref': invoice_number}, |
4542 | + context=context) |
4543 | + # propagate on invoice if some exists |
4544 | + # don't care of multiplue invoice because we |
4545 | + # don't know which invoice would have |
4546 | + # which magento number, 1 invoice on magento |
4547 | + # and 1 invoice on openerp expected, otherwise |
4548 | + # it has to be manually filled |
4549 | + if order.invoice_ids: |
4550 | + inv_ids = [inv.id for inv in order.invoice_ids] |
4551 | + self.pool.get('account.invoice').write( |
4552 | + cr, uid, inv_ids, |
4553 | + {'magento_ref': invoice_number}, |
4554 | + context=context) |
4555 | + return invoice_number |
4556 | + |
4557 | + def create_payments(self, cr, uid, order_id, data_record, context=None): |
4558 | + """Inherited to get the magento invoice number. |
4559 | + With Magento, we are sure that when we have a payment, |
4560 | + we have an invoice, so we get its number to have it |
4561 | + on the openerp invoice |
4562 | + """ |
4563 | + paid = super(sale_order, self).create_payments( |
4564 | + cr, uid, order_id, data_record, context=context) |
4565 | + |
4566 | + if 'Magento' in context.get('external_referential_type', ''): |
4567 | + order = self.browse(cr, uid, order_id, context=context) |
4568 | + |
4569 | + if paid and not order.magento_ref: |
4570 | + # get the invoice number |
4571 | + self._get_missing_magento_invoice_number( |
4572 | + cr, uid, order, data_record, context=context) |
4573 | + |
4574 | + return paid |
4575 | + |
4576 | def _prepare_invoice(self, cr, uid, order, lines, context=None): |
4577 | """Prepare the dict of values to create the new invoice for a |
4578 | sale order. This method may be overridden to implement custom |
4579 | @@ -123,4 +206,16 @@ |
4580 | vals['magento_ref'] = order.magento_ref |
4581 | return vals |
4582 | |
4583 | + def _apply_payment_settings(self, cr, uid, order, paid, context=None): |
4584 | + """We should deactivate need_to_update to avoid to query magento |
4585 | + on each import of orders and not to mislead the users if they use |
4586 | + a filter on need_to_update. |
4587 | + """ |
4588 | + res = super(sale_order, self)._apply_payment_settings(cr, uid, order, |
4589 | + paid, context=context) |
4590 | + payment_settings = order.base_payment_type_id |
4591 | + if payment_settings and payment_settings.allow_magento_manual_invoice: |
4592 | + self.write(cr, uid, order.id, {'need_to_update': False}, context=context) |
4593 | + return res |
4594 | + |
4595 | sale_order() |
4596 | |
4597 | === modified file 'magentoerpconnect_product_variant/product.py' |
4598 | --- magentoerpconnect_product_variant/product.py 2012-04-26 21:59:20 +0000 |
4599 | +++ magentoerpconnect_product_variant/product.py 2012-07-06 14:53:18 +0000 |
4600 | @@ -86,6 +86,95 @@ |
4601 | else: |
4602 | vals['product_type'] = 'simple' |
4603 | return super(product_product, self).create(cr, uid, vals, context) |
4604 | +<<<<<<< TREE |
4605 | +======= |
4606 | + |
4607 | + def action_before_exporting(self, cr, uid, id, product_type, external_referential_ids, defaults, context): |
4608 | + #When the export of a configurable product is forced we should check if all variant are already exported |
4609 | + if context.get('force_export', False) and product_type == 'configurable': |
4610 | + conn = context.get('conn_obj', False) |
4611 | + shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id']) |
4612 | + variant_ids = self.read(cr, uid, id, ['variant_ids'], context)['variant_ids'] |
4613 | + variant_ids.remove(id) |
4614 | + for variant in self.browse(cr, uid, variant_ids, context=context): |
4615 | + if variant.magento_exportable: |
4616 | + if not self.oeid_to_extid(cr, uid, variant.id, shop.referential_id.id): |
4617 | + conn.logger.info("Force the export of the product %s as it was not exported before", id) |
4618 | + self.ext_export(cr, uid, [variant.id], external_referential_ids, defaults, context) |
4619 | + return True |
4620 | + |
4621 | + def add_data_to_create_configurable_product(self, cr, uid, oe_id, data, context=None): |
4622 | + shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id']) |
4623 | + # check if not already created |
4624 | + products_data = {} # values of the attributes used on the element products |
4625 | + attributes_data = {} # params of the attributes to use on the configurable product |
4626 | + |
4627 | + variant_ids = self.read(cr, uid, oe_id, ['variant_ids'], context=context)['variant_ids'] |
4628 | + variant_ids.remove(oe_id) |
4629 | + if variant_ids: |
4630 | + associated_skus = [] |
4631 | + # create a dict with all values used on the configurable products |
4632 | + for product in self.browse(cr, uid, variant_ids): |
4633 | + if product.magento_exportable: |
4634 | + associated_skus += [product.magento_sku] |
4635 | + attr_list = set() |
4636 | + # get values for each attribute of the product |
4637 | + mag_prod_id = str(self.oeid_to_extid(cr, uid, product.id, shop.referential_id.id)) |
4638 | + products_data[mag_prod_id] = {} |
4639 | + index=0 |
4640 | + for value in product.dimension_value_ids: |
4641 | + # get the option selected on the product |
4642 | + option = value.option_id.magento_attribut_option |
4643 | + attr = option.attribute_id |
4644 | + attr_list = attr_list.union(set([attr])) |
4645 | + prod_data = { |
4646 | + 'attribute_id': attr.magento_id, # id of the attribute |
4647 | + 'label': option.label, # label of the option |
4648 | + 'value_index': int(option.value), # id of the option |
4649 | + 'is_percent': 0, # modification of the price |
4650 | + 'pricing_value': '', # modification of the price |
4651 | + } |
4652 | + #products_data[mag_prod_id][str(attribute_set.configurable_attributes.index(attr))] = prod_data |
4653 | + products_data[mag_prod_id][str(index)] = prod_data |
4654 | + index += 1 |
4655 | + |
4656 | + # create a dict with attributes used on the configurable product |
4657 | + index=-1 |
4658 | + for attr in attr_list: |
4659 | + index += 1 |
4660 | + attr_data = { |
4661 | + #'id': False, |
4662 | + 'label': '', |
4663 | + #'position': False, |
4664 | + 'values': [], |
4665 | + 'attribute_id': attr.magento_id, # id of the attribute on magento |
4666 | + 'attribute_code': attr.attribute_code, # code of the attribute on magento |
4667 | + 'frontend_label': attr.frontend_label, # label of the attribute on magento |
4668 | + 'html_id': "config_super_product__attribute_%s" % index, # must be config_super_product__attribute_ with an increment |
4669 | + } |
4670 | + attr_values = [] |
4671 | + for prod_id in products_data: |
4672 | + [attr_values.append(products_data[prod_id][key]) for key in products_data[prod_id] if products_data[prod_id][key]['attribute_id'] == attr.magento_id] |
4673 | + attr_data.update({'values': attr_values}) |
4674 | + attributes_data.update({str(index): attr_data}) |
4675 | + data.update({'configurable_products_data': products_data, 'configurable_attributes_data': attributes_data, 'associated_skus':associated_skus}) |
4676 | + return data |
4677 | + |
4678 | + |
4679 | + def ext_create(self, cr, uid, data, conn, method, oe_id, context): |
4680 | + if data.get('type_id', False) == 'configurable': |
4681 | + data = self.add_data_to_create_configurable_product(cr, uid, oe_id, data, context) |
4682 | + return super(product_product, self).ext_create(cr, uid, data, conn, method, oe_id, context) |
4683 | + |
4684 | + def extdata_from_oevals(self, cr, uid, external_referential_id, data_record, mapping_lines, defaults, context=None): |
4685 | + #TODO maybe this mapping can be in the mapping template but the problem is that this mapping have to be apply at the end |
4686 | + #because they will overwrite other mapping result. Maybe adding a sequence on the mapping will be the solution |
4687 | + res = super(product_product, self).extdata_from_oevals(cr, uid, external_referential_id, data_record, mapping_lines, defaults, context) |
4688 | + if data_record.get('is_multi_variants', False): |
4689 | + for dim_value in self.pool.get('product.variant.dimension.value').browse(cr, uid, data_record['dimension_value_ids'], context=context): |
4690 | + res[dim_value.dimension_id.magento_attribut.attribute_code] = dim_value.option_id.magento_attribut_option.value |
4691 | + return res |
4692 | +>>>>>>> MERGE-SOURCE |
4693 | |
4694 | def _filter_fields_to_return(self, cr, uid, field_names, context): |
4695 | #In the cas that the magento view is open from the button 'open magento fields', we can give a very customize view because only on for one product |