Merge lp:~magentoerpconnect-core-editors/magentoerpconnect/trunk-fix-876312 into lp:~magentoerpconnect-core-editors/magentoerpconnect/oerp7.0-refactor

Proposed by Alexandre Fayolle - camptocamp
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
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.

Description of the change

Work around magento bug wrt product categories. Closes https://bugs.launchpad.net/magentoerpconnect/+bug/876312

To post a comment you must log in.

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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'magento_sku_is_code/product.py'
--- magento_sku_is_code/product.py 2012-03-15 09:47:04 +0000
+++ magento_sku_is_code/product.py 2012-07-06 14:53:18 +0000
@@ -19,16 +19,26 @@
19#19#
20##############################################################################20##############################################################################
2121
22import copy
23
22from osv import osv, fields24from osv import osv, fields
2325
2426
25class Product(osv.osv):27class Product(osv.osv):
26 """Inherit product to use the default code as the Magento SKU. Copy the default code into the magento_sku field."""28 """Inherit product to use the default code as the Magento SKU.
29 Copy the default code into the magento_sku field, but doesn't
30 change it if the product has already been exported to an
31 external referential."""
32
27 _inherit = 'product.product'33 _inherit = 'product.product'
2834
29 _columns = {'magento_sku':fields.char('Magento SKU', size=64, readonly=True),}35 _columns = {
36 'magento_sku': fields.char('Magento SKU', size=64, readonly=True),
37 }
3038
31 _sql_constraints = [('code_uniq', 'unique(default_code)', 'The code must be unique')]39 _sql_constraints = [
40 ('code_uniq', 'unique(default_code)', 'The code must be unique')
41 ]
3242
33 def _get_sku(self, cr, uid, vals, product=None, context=None):43 def _get_sku(self, cr, uid, vals, product=None, context=None):
34 """44 """
@@ -36,7 +46,7 @@
36 @param vals: vals to be created / modified46 @param vals: vals to be created / modified
37 @param product: optional browse instance of the product (when writing)47 @param product: optional browse instance of the product (when writing)
38 """48 """
39 return vals['default_code']49 return vals['default_code'].strip()
4050
41 def create(self, cr, uid, vals, context=None):51 def create(self, cr, uid, vals, context=None):
42 if vals.get('default_code'):52 if vals.get('default_code'):
@@ -49,18 +59,27 @@
49 ids_to_write = ids[:]59 ids_to_write = ids[:]
50 if vals.get('default_code'):60 if vals.get('default_code'):
51 for product in self.browse(cr, uid, ids, context=context):61 for product in self.browse(cr, uid, ids, context=context):
52 # write separately on each product if they are not already exported62 # write separately on each product if they
63 # are not already exported. because the sku value
64 # will change for each product. Concretely, when a value
65 # for default_code is given, we should have only one product
66 # in the write
53 if not product.magento_exported:67 if not product.magento_exported:
54 new_vals = vals.copy()68 atomic_vals = copy.deepcopy(vals)
55 new_vals['magento_sku'] = self._get_sku(cr, uid, new_vals, product=product, context=context)69 atomic_vals['magento_sku'] = self._get_sku(
56 super(Product, self).write(cr, uid, [product.id], new_vals, context=context)70 cr, uid, atomic_vals, product=product, context=context)
71
72 super(Product, self).write(
73 cr, uid, [product.id], atomic_vals, context=context)
57 ids_to_write.remove(product.id)74 ids_to_write.remove(product.id)
5875
59 return super(Product, self).write(cr, uid, ids_to_write, vals, context=context)76 return super(Product, self).write(
77 cr, uid, ids_to_write, vals, context=context)
6078
61 def copy(self, cr, uid, id, default=None, context=None):79 def copy(self, cr, uid, id, default=None, context=None):
62 if not default is None: default = {}80 if not default is None: default = {}
63 default['default_code'] = False81 default['default_code'] = False
64 return super(Product, self).copy(cr, uid, id, default=default, context=context)82 return super(Product, self).copy(
83 cr, uid, id, default=default, context=context)
6584
66Product()85Product()
6786
=== modified file 'magentoerpconnect/__openerp__.py'
--- magentoerpconnect/__openerp__.py 2012-05-16 08:01:05 +0000
+++ magentoerpconnect/__openerp__.py 2012-07-06 14:53:18 +0000
@@ -18,7 +18,7 @@
18#########################################################################18#########################################################################
19{19{
20 "name" : "Magento e-commerce",20 "name" : "Magento e-commerce",
21 "version" : "1.0",21 "version" : "1.0.1",
22 "depends" : ["base",22 "depends" : ["base",
23 "product",23 "product",
24 "product_m2mcategories",24 "product_m2mcategories",
@@ -44,9 +44,22 @@
44 "demo_xml" : [],44 "demo_xml" : [],
45 "update_xml" : [45 "update_xml" : [
46 'security/ir.model.access.csv',46 'security/ir.model.access.csv',
47<<<<<<< TREE
47 'settings/magerp.product_category_attribute_options.csv',48 'settings/magerp.product_category_attribute_options.csv',
48 'settings/external.referential.type.csv',49 'settings/external.referential.type.csv',
49 'settings/1.5.0.0/external.referential.version.csv',50 'settings/1.5.0.0/external.referential.version.csv',
51=======
52 'settings/1.3.2.4/external.referential.type.csv',
53 'settings/1.3.2.4/external.mapping.template.csv',
54 'settings/1.3.2.4/external.mappinglines.template.csv',
55 'settings/1.4.0.0/external.referential.type.csv',
56 'settings/1.4.0.0/external.mapping.template.csv',
57 'settings/1.4.0.0/external.mappinglines.template.csv',
58 'settings/1.4.2.0/external.referential.type.csv',
59 'settings/1.4.2.0/external.mapping.template.csv',
60 'settings/1.4.2.0/external.mappinglines.template.csv',
61 'settings/1.5.0.0/external.referential.type.csv',
62>>>>>>> MERGE-SOURCE
50 'settings/1.5.0.0/external.mapping.template.csv',63 'settings/1.5.0.0/external.mapping.template.csv',
51 'settings/1.5.0.0/external.shop.group/external.mappinglines.template.csv',64 'settings/1.5.0.0/external.shop.group/external.mappinglines.template.csv',
52 'settings/1.5.0.0/magerp.storeviews/external.mappinglines.template.csv',65 'settings/1.5.0.0/magerp.storeviews/external.mappinglines.template.csv',
@@ -64,7 +77,9 @@
64 'settings/1.5.0.0/account.invoice/external.mappinglines.template.csv',77 'settings/1.5.0.0/account.invoice/external.mappinglines.template.csv',
65 'settings/1.5.0.0/product.link/external.mappinglines.template.csv',78 'settings/1.5.0.0/product.link/external.mappinglines.template.csv',
66 'settings/magerp_product_product_type.xml',79 'settings/magerp_product_product_type.xml',
80 'settings/update/magerp.product_category_attribute_options.xml',
67 'magerp_data.xml',81 'magerp_data.xml',
82 'board_view.xml',
68 'magerp_core_view.xml',83 'magerp_core_view.xml',
69 'product_view.xml',84 'product_view.xml',
70 'partner_view.xml',85 'partner_view.xml',
7186
=== added file 'magentoerpconnect/board_view.xml'
--- magentoerpconnect/board_view.xml 1970-01-01 00:00:00 +0000
+++ magentoerpconnect/board_view.xml 2012-07-06 14:53:18 +0000
@@ -0,0 +1,30 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5 <record id="board_magentoerpconnect_form" model="ir.ui.view">
6 <field name="name">board.magentoerpconnect.form</field>
7 <field name="model">board.board</field>
8 <field name="type">form</field>
9 <field name="arch" type="xml">
10 <form string="Magentoerpconnect Dashboard">
11 <board style="2-1">
12 <column>
13 <action name="%(base_external_referentials.ir_actions_act_window_external_report_line)d" string="Last Synchronizations Errors" />
14 </column>
15 <column/>
16 </board>
17 </form>
18 </field>
19 </record>
20
21 <record id="open_board_magentoerpconnect" model="ir.actions.act_window">
22 <field name="name">Magentoerpconnect Dashboard</field>
23 <field name="res_model">board.board</field>
24 <field name="view_type">form</field>
25 <field name="view_mode">form</field>
26 <field name="view_id" ref="board_magentoerpconnect_form"/>
27 </record>
28
29 </data>
30</openerp>
031
=== modified file 'magentoerpconnect/invoice.py'
=== modified file 'magentoerpconnect/magerp_core.py'
--- magentoerpconnect/magerp_core.py 2012-05-25 15:37:26 +0000
+++ magentoerpconnect/magerp_core.py 2012-07-06 14:53:18 +0000
@@ -25,6 +25,10 @@
25from osv import osv, fields25from osv import osv, fields
26import magerp_osv26import magerp_osv
27import pooler27import pooler
28<<<<<<< TREE
29=======
30import logging
31>>>>>>> MERGE-SOURCE
28import base64, urllib32import base64, urllib
29from magerp_osv import Connection33from magerp_osv import Connection
30import tools34import tools
@@ -101,6 +105,10 @@
101 def sync_attribs(self, cr, uid, ids, context=None):105 def sync_attribs(self, cr, uid, ids, context=None):
102 attr_obj = self.pool.get('magerp.product_attributes')106 attr_obj = self.pool.get('magerp.product_attributes')
103 attr_set_obj = self.pool.get('magerp.product_attribute_set')107 attr_set_obj = self.pool.get('magerp.product_attribute_set')
108<<<<<<< TREE
109=======
110 logger = logging.getLogger('ext synchro')
111>>>>>>> MERGE-SOURCE
104 for referential in self.browse(cr, uid, ids, context=context):112 for referential in self.browse(cr, uid, ids, context=context):
105 external_session = ExternalSession(referential, referential)113 external_session = ExternalSession(referential, referential)
106 attr_conn = external_session.connection114 attr_conn = external_session.connection
@@ -130,7 +138,11 @@
130 context=context,138 context=context,
131 )139 )
132 import_cr.commit()140 import_cr.commit()
141<<<<<<< TREE
133 _logger.info("All attributs for the attributs set id %s was succesfully imported", attr_set_id)142 _logger.info("All attributs for the attributs set id %s was succesfully imported", attr_set_id)
143=======
144 logger.info("All attributs for the attributs set id %s was succesfully imported", attr_set_id)
145>>>>>>> MERGE-SOURCE
134 #Relate attribute sets & attributes146 #Relate attribute sets & attributes
135 mage_inp = {}147 mage_inp = {}
136 #Pass in {attribute_set_id:{attributes},attribute_set_id2:{attributes}}148 #Pass in {attribute_set_id:{attributes},attribute_set_id2:{attributes}}
@@ -289,6 +301,8 @@
289 filter = [filters]301 filter = [filters]
290 return attr_conn.call('ol_customer.search', filter)302 return attr_conn.call('ol_customer.search', filter)
291303
304 partner_obj = self.pool.get('res.partner')
305
292 for referential in self.browse(cr, uid, ids, context):306 for referential in self.browse(cr, uid, ids, context):
293 attr_conn = referential.external_connection(DEBUG)307 attr_conn = referential.external_connection(DEBUG)
294 last_imported_id = 0308 last_imported_id = 0
@@ -296,22 +310,24 @@
296 last_imported_id = referential.last_imported_partner_id310 last_imported_id = referential.last_imported_partner_id
297311
298 ext_customer_ids = next_partners(attr_conn, last_imported_id + 1, self.SYNC_PARTNER_STEP)312 ext_customer_ids = next_partners(attr_conn, last_imported_id + 1, self.SYNC_PARTNER_STEP)
313
314 context['use_external_log'] = True
299 import_cr = pooler.get_db(cr.dbname).cursor()315 import_cr = pooler.get_db(cr.dbname).cursor()
300 try:316 try:
301 while ext_customer_ids:317 while ext_customer_ids:
302 for ext_customer_id in ext_customer_ids:318 for ext_customer_id in ext_customer_ids:
303 customer_info = attr_conn.call('customer.info', [ext_customer_id])319 customer_info = attr_conn.call(
304 customer_address_info = attr_conn.call('customer_address.list', [ext_customer_id])320 'customer.info', [ext_customer_id])
305321
306 address_info = False322 partner_obj.ext_import(
307 if customer_address_info:323 import_cr, uid, [customer_info],
308 address_info = customer_address_info[0]324 referential.id, context=context)
309 address_info['customer_id'] = ext_customer_id325 partner_id = partner_obj.extid_to_oeid(
310 address_info['email'] = customer_info['email']326 import_cr, uid, ext_customer_id,
311327 referential.id, context=context)
312 self.pool.get('res.partner').ext_import(import_cr, uid, [customer_info], referential.id, context=context)328 partner_obj.import_magento_address_book(
313 if address_info:329 import_cr, uid, partner_id,
314 self.pool.get('res.partner.address').ext_import(import_cr, uid, [address_info], referential.id, context=context)330 referential.id, context=context)
315331
316 last_imported_id = int(ext_customer_id)332 last_imported_id = int(ext_customer_id)
317 self.write(import_cr, uid, referential.id, {'last_imported_partner_id': last_imported_id}, context=context)333 self.write(import_cr, uid, referential.id, {'last_imported_partner_id': last_imported_id}, context=context)
318334
=== modified file 'magentoerpconnect/magerp_menu.xml'
--- magentoerpconnect/magerp_menu.xml 2012-03-15 09:47:04 +0000
+++ magentoerpconnect/magerp_menu.xml 2012-07-06 14:53:18 +0000
@@ -1,7 +1,7 @@
1<?xml version="1.0" encoding="utf-8"?>1<?xml version="1.0" encoding="utf-8"?>
2<openerp>2<openerp>
3 <data>3 <data>
4 <menuitem id="menu_magerp" name="MagentoERPconnect" icon="terp-sale"4 <menuitem id="menu_magerp" name="MagentoERPconnect" icon="terp-sale" action="open_board_magentoerpconnect"
5 web_icon="images/magento.png" 5 web_icon="images/magento.png"
6 web_icon_hover="images/magento-hover.png"/>6 web_icon_hover="images/magento-hover.png"/>
77
@@ -25,41 +25,17 @@
2525
26 <menuitem id="menu_magerp_reporting" name="Reporting" parent="menu_magerp" />26 <menuitem id="menu_magerp_reporting" name="Reporting" parent="menu_magerp" />
2727
28 <record id="action_magerp_external_report" model="ir.actions.act_window">
29 <field name="name">External Reports</field>
30 <field name="type">ir.actions.act_window</field>
31 <field name="res_model">external.report</field>
32 <field name="view_type">form</field>
33 <field name="domain">[('external_referential_id.type_id.name', 'like', 'Magento')]</field> <!-- erk -->
34 <field name="view_id" ref="base_external_referentials.external_report_tree_view"/>
35 <field name="search_view_id" ref="base_external_referentials.external_report_search_form_view"/>
36 </record>
37 <menuitem id="menu_magerp_reporting_report" name="Synchronisation Report"
38 parent="menu_magerp_reporting" action="action_magerp_external_report" sequence="20"/>
39
40 <record id="action_magerp_external_report_history" model="ir.actions.act_window">
41 <field name="name">External Report History</field>
42 <field name="type">ir.actions.act_window</field>
43 <field name="res_model">external.report.history</field>
44 <field name="view_type">form</field>
45 <field name="domain">[('external_report_id.external_referential_id.type_id.name', 'like', 'Magento')]</field> <!-- erk -->
46 <field name="view_id" ref="base_external_referentials.external_report_history_tree_view"/>
47 <field name="search_view_id" ref="base_external_referentials.external_report_history_search_view"/>
48 </record>
49
50 <menuitem id="menu_magerp_reporting_report_history" name="Synchronisation History"
51 parent="menu_magerp_reporting" action="action_magerp_external_report_history" sequence="25" />
5228
53 <record id="action_magerp_external_report_line" model="ir.actions.act_window">29 <record id="action_magerp_external_report_line" model="ir.actions.act_window">
54 <field name="name">External Report Lines</field>30 <field name="name">External Report Lines</field>
55 <field name="type">ir.actions.act_window</field>31 <field name="type">ir.actions.act_window</field>
56 <field name="res_model">external.report.line</field>32 <field name="res_model">external.report.line</field>
57 <field name="view_type">form</field>33 <field name="view_type">form</field>
58 <field name="domain">[('external_report_id.external_referential_id.type_id.name', 'like', 'Magento')]</field> <!-- erk -->34 <field name="domain">[('referential_id.type_id.name', 'like', 'Magento')]</field> <!-- erk -->
59 <field name="view_id" ref="base_external_referentials.external_report_line_tree_view"/>35 <field name="view_id" ref="base_external_referentials.external_report_line_tree_view"/>
60 <field name="search_view_id" ref="base_external_referentials.external_report_line_search_view"/>36 <field name="search_view_id" ref="base_external_referentials.external_report_line_search_view"/>
61 </record>37 </record>
62 <menuitem id="menu_magerp_reporting_report_line" name="Last Synchronisation Details"38 <menuitem id="menu_magerp_reporting_report_line" name="Synchronisation Errors"
63 parent="menu_magerp_reporting" action="action_magerp_external_report_line" sequence="30"/>39 parent="menu_magerp_reporting" action="action_magerp_external_report_line" sequence="30"/>
64 </data>40 </data>
65</openerp>41</openerp>
6642
=== modified file 'magentoerpconnect/magerp_osv.py'
--- magentoerpconnect/magerp_osv.py 2012-05-24 20:52:38 +0000
+++ magentoerpconnect/magerp_osv.py 2012-07-06 14:53:18 +0000
@@ -23,9 +23,16 @@
23import time23import time
24import datetime24import datetime
25import xmlrpclib25import xmlrpclib
26<<<<<<< TREE
27=======
28import logging
29>>>>>>> MERGE-SOURCE
26import urllib230import urllib2
27import base6431import base64
32import pooler
28from tools.translate import _33from tools.translate import _
34from openerp.addons.base_external_referentials.external_osv import MappingError
35from psycopg2 import IntegrityError
2936
3037
31#NEW FEATURE38#NEW FEATURE
@@ -175,7 +182,7 @@
175 def __init__(self, location, username, password, debug=False, logger=False):182 def __init__(self, location, username, password, debug=False, logger=False):
176 #Append / if not there183 #Append / if not there
177 if not location[-1] == '/':184 if not location[-1] == '/':
178 location += '/' 185 location += '/'
179 self.corelocation = location186 self.corelocation = location
180 #Please do not remove the str indeed xmlrpc lib require a string for the location187 #Please do not remove the str indeed xmlrpc lib require a string for the location
181 #if an unicode is send it will raise you an error188 #if an unicode is send it will raise you an error
@@ -184,26 +191,46 @@
184 self.password = password191 self.password = password
185 self.debug = debug192 self.debug = debug
186 self.result = {}193 self.result = {}
194<<<<<<< TREE
187 self.logger = logger or _logger195 self.logger = logger or _logger
188196
189 197
198=======
199 self.logger = logging.getLogger('Connection(%s)' % self.location)
200
201
202>>>>>>> MERGE-SOURCE
190 def connect(self):203 def connect(self):
191 if not self.location[-1] == '/':204 if not self.location[-1] == '/':
192 self.location += '/'205 self.location += '/'
193 if self.debug:206 if self.debug:
207<<<<<<< TREE
194 self.logger.info("Attempting connection with Settings:%s,%s,%s" % (self.location, self.username, self.password))208 self.logger.info("Attempting connection with Settings:%s,%s,%s" % (self.location, self.username, self.password))
209=======
210 self.logger.info(_("Attempting connection with Settings:%s,%s,%s"), self.location, self.username, self.password)
211>>>>>>> MERGE-SOURCE
195 self.ser = xmlrpclib.ServerProxy(self.location)212 self.ser = xmlrpclib.ServerProxy(self.location)
196 for sleep_time in [1, 3, 6]:213 for sleep_time in [1, 3, 6]:
197 try:214 try:
198 self.session = self.ser.login(self.username, self.password)215 self.session = self.ser.login(self.username, self.password)
199 if self.debug:216 if self.debug:
217<<<<<<< TREE
200 self.logger.info("Login Successful")218 self.logger.info("Login Successful")
219=======
220 self.logger.info(_("Login Successful"))
221>>>>>>> MERGE-SOURCE
201 return True222 return True
202 except IOError, e:223 except IOError, e:
224<<<<<<< TREE
203 self.logger.error("Error in connecting:%s" % e)225 self.logger.error("Error in connecting:%s" % e)
204 self.logger.warning("Webservice Failure, sleeping %s second before next attempt" % sleep_time)226 self.logger.warning("Webservice Failure, sleeping %s second before next attempt" % sleep_time)
227=======
228 self.logger.error(_("Error in connecting:%s"), e, exc_info=True)
229 self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time)
230>>>>>>> MERGE-SOURCE
205 time.sleep(sleep_time)231 time.sleep(sleep_time)
206 except Exception,e:232 except Exception,e:
233<<<<<<< TREE
207 self.logger.error("Magento Connection" + netsvc.LOG_ERROR + "Error in connecting:%s" % e)234 self.logger.error("Magento Connection" + netsvc.LOG_ERROR + "Error in connecting:%s" % e)
208 self.logger.warning("Webservice Failure, sleeping %s second before next attempt" % sleep_time)235 self.logger.warning("Webservice Failure, sleeping %s second before next attempt" % sleep_time)
209 time.sleep(sleep_time) 236 time.sleep(sleep_time)
@@ -211,6 +238,34 @@
211238
212 239
213 def call(self, method, *arguments): 240 def call(self, method, *arguments):
241=======
242 self.logger.error(_("Error in connecting:%s"), e, exc_info=True)
243 self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time)
244 time.sleep(sleep_time)
245 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?'))
246
247 def _truncate_arguments(self, arguments, max_length=128):
248 """truncate long strings in arguments for logging purpose"""
249 logged_args = []
250 try:
251 for arg in arguments:
252 # reduce verbosity of log for large strings (e.g. base64 encoded images...)
253 if isinstance(arg, basestring) and len(arg) > max_length:
254 arg = arg[:max_length] + '...'
255 elif isinstance(arg, dict):
256 new_arg = {}
257 for key, value in arg.iteritems():
258 if isinstance(value, basestring) and len(value) > max_length:
259 value = value[:max_length] + '...'
260 new_arg[key] = value
261 arg = new_arg
262 logged_args.append(arg)
263 return logged_args
264 except TypeError: # arguments can be a bool
265 return arguments
266
267 def call(self, method, *arguments):
268>>>>>>> MERGE-SOURCE
214 if arguments:269 if arguments:
215 arguments = list(arguments)[0]270 arguments = list(arguments)[0]
216 else:271 else:
@@ -218,18 +273,37 @@
218 for sleep_time in [1, 3, 6]:273 for sleep_time in [1, 3, 6]:
219 try:274 try:
220 if self.debug:275 if self.debug:
276<<<<<<< TREE
221 self.logger.info(_("Calling Method:%s,Arguments:%s") % (method, arguments))277 self.logger.info(_("Calling Method:%s,Arguments:%s") % (method, arguments))
278=======
279 logged_args = self._truncate_arguments(arguments)
280 self.logger.info(_("Calling Method:%s,Arguments:%s"), method, logged_args)
281>>>>>>> MERGE-SOURCE
222 res = self.ser.call(self.session, method, arguments)282 res = self.ser.call(self.session, method, arguments)
223 if self.debug:283 if self.debug:
284 logged_res = self._truncate_arguments(res)
224 if method=='catalog_product.list':285 if method=='catalog_product.list':
225 # 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 activate286 # 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
287<<<<<<< TREE
226 self.logger.debug(_("Query Returned:%s") % (res))288 self.logger.debug(_("Query Returned:%s") % (res))
289=======
290 self.logger.debug(_("Query Returned:%s"), logged_res)
291>>>>>>> MERGE-SOURCE
227 else:292 else:
293<<<<<<< TREE
228 self.logger.info(_("Query Returned:%s") % (res))294 self.logger.info(_("Query Returned:%s") % (res))
295=======
296 self.logger.info(_("Query Returned:%s"), logged_res)
297>>>>>>> MERGE-SOURCE
229 return res298 return res
230 except IOError, e:299 except IOError, e:
300<<<<<<< TREE
231 self.logger.error(_("Method: %s\nArguments:%s\nError:%s") % (method, arguments, e))301 self.logger.error(_("Method: %s\nArguments:%s\nError:%s") % (method, arguments, e))
232 self.logger.warning(_("Webservice Failure, sleeping %s second before next attempt") % (sleep_time))302 self.logger.warning(_("Webservice Failure, sleeping %s second before next attempt") % (sleep_time))
303=======
304 self.logger.error(_("Method: %s\nArguments:%s\nError:%s"), method, arguments, e, exc_info=True)
305 self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time)
306>>>>>>> MERGE-SOURCE
233 time.sleep(sleep_time)307 time.sleep(sleep_time)
234 raise308 raise
235309
@@ -254,7 +328,7 @@
254 _DELETE_METHOD = False328 _DELETE_METHOD = False
255 _mapping = {}329 _mapping = {}
256 DEBUG = False330 DEBUG = False
257 331
258 #TODO deprecated, remove use332 #TODO deprecated, remove use
259 def mage_to_oe(self, cr, uid, mageid, instance, *arguments):333 def mage_to_oe(self, cr, uid, mageid, instance, *arguments):
260 """given a record id in the Magento referential, returns a tuple (id, name) with the id in the OpenERP referential; Magento instance wise"""334 """given a record id in the Magento referential, returns a tuple (id, name) with the id in the OpenERP referential; Magento instance wise"""
@@ -279,7 +353,7 @@
279 read = self.read(cr, uid, oeid, [self._rec_name])353 read = self.read(cr, uid, oeid, [self._rec_name])
280 return (read[0]['id'], read[0][self._rec_name])354 return (read[0]['id'], read[0][self._rec_name])
281 return False355 return False
282 356
283 #TODO deprecated, remove use357 #TODO deprecated, remove use
284 def sync_import(self, cr, uid, magento_records, instance, debug=False, defaults=None, *attrs):358 def sync_import(self, cr, uid, magento_records, instance, debug=False, defaults=None, *attrs):
285359
@@ -314,7 +388,7 @@
314 'temp_vars':{},388 'temp_vars':{},
315 'mage2oe_filters':mage2oe_filters389 'mage2oe_filters':mage2oe_filters
316 }390 }
317 391
318 #now properly mapp known Magento attributes to OpenERP entity columns:392 #now properly mapp known Magento attributes to OpenERP entity columns:
319 for each_valid_key in self._mapping:393 for each_valid_key in self._mapping:
320 if each_valid_key in magento_record.keys():394 if each_valid_key in magento_record.keys():
@@ -347,13 +421,12 @@
347 if self._mapping[each_valid_key][0]:#if not function mapping421 if self._mapping[each_valid_key][0]:#if not function mapping
348 vals[self._mapping[each_valid_key][0]] = magento_record[each_valid_key] or False422 vals[self._mapping[each_valid_key][0]] = magento_record[each_valid_key] or False
349 vals['referential_id'] = instance423 vals['referential_id'] = instance
350 tools.debug(vals)
351 if self._MAGE_FIELD:424 if self._MAGE_FIELD:
352 if self._MAGE_FIELD in vals.keys() and vals[self._MAGE_FIELD]:425 if self._MAGE_FIELD in vals.keys() and vals[self._MAGE_FIELD]:
353 self.record_save(cr, uid, rec_id, vals, defaults)426 self.record_save(cr, uid, rec_id, vals, defaults)
354 else:427 else:
355 self.record_save(cr, uid, rec_id, vals, defaults)428 self.record_save(cr, uid, rec_id, vals, defaults)
356 429
357 def record_save(self, cr, uid, rec_id, vals, defaults):430 def record_save(self, cr, uid, rec_id, vals, defaults):
358 if defaults:431 if defaults:
359 for key in defaults.keys():432 for key in defaults.keys():
@@ -364,7 +437,7 @@
364 else:437 else:
365 #Record is not there, create it438 #Record is not there, create it
366 self.create(cr, uid, vals,)439 self.create(cr, uid, vals,)
367 440
368 def cast_string(self, subject):441 def cast_string(self, subject):
369 """This function will convert string objects to the data type required. Example "0"/"1" to boolean conversion"""442 """This function will convert string objects to the data type required. Example "0"/"1" to boolean conversion"""
370 for key in subject.keys():443 for key in subject.keys():
@@ -374,7 +447,7 @@
374 else:447 else:
375 subject[key] = True448 subject[key] = True
376 return subject449 return subject
377 450
378 def mage_import_base(self,cr,uid,conn, external_referential_id, defaults=None, context=None):451 def mage_import_base(self,cr,uid,conn, external_referential_id, defaults=None, context=None):
379 if context is None:452 if context is None:
380 context = {}453 context = {}
@@ -396,7 +469,7 @@
396 list_method = self.pool.get('external.mapping').read(cr,uid,mapping_id[0],['external_list_method']).get('external_list_method',False)469 list_method = self.pool.get('external.mapping').read(cr,uid,mapping_id[0],['external_list_method']).get('external_list_method',False)
397 if list_method:470 if list_method:
398 data = conn.call(list_method, context['ids_or_filter'])471 data = conn.call(list_method, context['ids_or_filter'])
399 472
400 #it may happen that list method doesn't provide enough information, forcing us to use get_method on each record (case for sale orders)473 #it may happen that list method doesn't provide enough information, forcing us to use get_method on each record (case for sale orders)
401 if context.get('one_by_one', False):474 if context.get('one_by_one', False):
402 self.mage_import_one_by_one(cr, uid, conn, external_referential_id, mapping_id[0], data, defaults, context)475 self.mage_import_one_by_one(cr, uid, conn, external_referential_id, mapping_id[0], data, defaults, context)
@@ -405,24 +478,60 @@
405478
406 return result479 return result
407480
481 def _mage_import_one(self, cr, uid, conn, record, referential_id, mapping_id, defaults=None, context=None):
482 ext_id = record[self.pool.get('external.mapping').read(cr, uid, mapping_id, ['external_key_name'])['external_key_name']]
483 get_method = self.pool.get('external.mapping').read(cr, uid, mapping_id, ['external_get_method']).get('external_get_method',False)
484 rec_data = [conn.call(get_method, [ext_id])]
485 rec_result = self.ext_import(cr, uid, rec_data, referential_id, defaults, context)
486 return rec_result['create_ids'], rec_result['write_ids']
487
408 def mage_import_one_by_one(self, cr, uid, conn, external_referential_id, mapping_id, data, defaults=None, context=None):488 def mage_import_one_by_one(self, cr, uid, conn, external_referential_id, mapping_id, data, defaults=None, context=None):
409 if context is None:489 if context is None:
410 context = {}490 context = {}
491 report_line_obj = self.pool.get('external.report.line')
411 result = {'create_ids': [], 'write_ids': []}492 result = {'create_ids': [], 'write_ids': []}
412 if context.get('one_by_one', False):493 import_ctx = dict(context)
413 del(context['one_by_one'])494 import_ctx.pop('one_by_one', False)
495 # avoid to use external logs in submethods as they are handle at this level
496 import_ctx.pop('use_external_log', False)
497 import_ctx['import_no_new_cr'] = True
414 for record in data:498 for record in data:
415 id = record[self.pool.get('external.mapping').read(cr, uid, mapping_id, ['external_key_name'])['external_key_name']]499 record_cr = pooler.get_db(cr.dbname).cursor()
416 get_method = self.pool.get('external.mapping').read(cr, uid, mapping_id, ['external_get_method']).get('external_get_method',False)500 try:
417 rec_data = [conn.call(get_method, [id])]501 ext_id = record[self.pool.get('external.mapping').read(
418 rec_result = self.ext_import(cr, uid, rec_data, external_referential_id, defaults, context)502 record_cr, uid, mapping_id, ['external_key_name'])['external_key_name']]
419 result['create_ids'].append(rec_result['create_ids'])503 cids, wids = self._mage_import_one(
420 result['write_ids'].append(rec_result['write_ids'])504 record_cr, uid, conn, record, external_referential_id, mapping_id, defaults=defaults, context=import_ctx)
421 # and let the import continue, because it will be imported on the next import505 except (MappingError, osv.except_osv, xmlrpclib.Fault, IntegrityError):
506 record_cr.rollback()
507 report_line_obj.log_failed(
508 cr, uid,
509 self._name,
510 'import',
511 external_referential_id,
512 external_id=ext_id,
513 defaults=defaults,
514 context=context)
515 else:
516 record_cr.commit()
517 report_line_obj.log_success(
518 cr, uid,
519 self._name,
520 'import',
521 external_referential_id,
522 external_id=ext_id,
523 context=context)
524 result['create_ids'].append(cids)
525 result['write_ids'].append(wids)
526 finally:
527 record_cr.close()
422 return result528 return result
423529
424 def get_external_data(self, cr, uid, conn, external_referential_id, defaults=None, context=None):530 def get_external_data(self, cr, uid, conn, external_referential_id, defaults=None, context=None):
425 """Constructs data using WS or other synch protocols and then call ext_import on it"""531 """Constructs data using WS or other synch protocols and then call ext_import on it"""
532 if context is None:
533 context = {}
534 context = dict(context)
426 return self.mage_import_base(cr, uid, conn, external_referential_id, defaults, context)#TODO refactor mage_import_base calls to this interface535 return self.mage_import_base(cr, uid, conn, external_referential_id, defaults, context)#TODO refactor mage_import_base calls to this interface
427536
428 #TODO deprecated, remove use537 #TODO deprecated, remove use
@@ -438,7 +547,7 @@
438 self.sync_import(cr, uid, magento_records, instance, debug, defaults)547 self.sync_import(cr, uid, magento_records, instance, debug, defaults)
439 else:548 else:
440 raise osv.except_osv(_('Undefined List method !'), _("list method is undefined for this object!"))549 raise osv.except_osv(_('Undefined List method !'), _("list method is undefined for this object!"))
441 550
442 #TODO deprecated, remove use551 #TODO deprecated, remove use
443 def get_all_mage_ids(self, cr, uid, ids, instance=False):552 def get_all_mage_ids(self, cr, uid, ids, instance=False):
444 search_param = []553 search_param = []
@@ -451,4 +560,4 @@
451 for each in reads:560 for each in reads:
452 mageids.append(each[self._MAGE_FIELD])561 mageids.append(each[self._MAGE_FIELD])
453 return mageids562 return mageids
454 563
455564
=== modified file 'magentoerpconnect/partner.py'
--- magentoerpconnect/partner.py 2012-05-19 13:37:23 +0000
+++ magentoerpconnect/partner.py 2012-07-06 14:53:18 +0000
@@ -22,6 +22,9 @@
22#along with this program. If not, see <http://www.gnu.org/licenses/>. #22#along with this program. If not, see <http://www.gnu.org/licenses/>. #
23#########################################################################23#########################################################################
2424
25import string
26import copy
27
25from osv import osv, fields28from osv import osv, fields
26from tools.translate import _29from tools.translate import _
27import magerp_osv30import magerp_osv
@@ -52,6 +55,7 @@
52 return res55 return res
5356
54 _columns = {57 _columns = {
58<<<<<<< TREE
55 'name': fields.function(_get_partner_name, obj="res.partner.address", type = 'char', size = 256,59 'name': fields.function(_get_partner_name, obj="res.partner.address", type = 'char', size = 256,
56 store = {60 store = {
57 'res.partner.address' : (lambda self, cr, uid, ids, c={}: ids,61 'res.partner.address' : (lambda self, cr, uid, ids, c={}: ids,
@@ -60,8 +64,22 @@
60 'firstname':fields.char('First Name', size=100),64 'firstname':fields.char('First Name', size=100),
61 'lastname':fields.char('Last Name', size=100),65 'lastname':fields.char('Last Name', size=100),
62 'is_magento_order_address':fields.boolean('Magento Order Address?'), #TODO still needed?66 'is_magento_order_address':fields.boolean('Magento Order Address?'), #TODO still needed?
67=======
68 'firstname':fields.char('First Name', size=100),
69 'lastname':fields.char('Last Name', size=100),
70 'is_magento_order_address':
71 fields.boolean('Magento Order Address',
72 help="Created for a Magento sale order",
73 readonly=True),
74 'magento_address_book':
75 fields.boolean('Magento Address Book',
76 help="Part of the Magento Address Book",
77 readonly=True)
78>>>>>>> MERGE-SOURCE
63 }79 }
80
64 _defaults = {81 _defaults = {
82<<<<<<< TREE
65 'is_magento_order_address': lambda * a:False,83 'is_magento_order_address': lambda * a:False,
66 }84 }
6785
@@ -75,6 +93,19 @@
75 ext_create_ids[resource_id] = ext_id93 ext_create_ids[resource_id] = ext_id
76 return ext_create_ids94 return ext_create_ids
7795
96=======
97 'is_magento_order_address': lambda * a: False,
98 }
99
100 def mage_import_base(self,cr,uid,conn, external_referential_id, defaults=None, context=None):
101 # quick hack
102 # remove the id so the address will be imported using "list method"
103 # instead of "get method" because the entity_id field miss in the get method.
104 context.pop('id', False)
105 return super(res_partner_address, self).mage_import_base(
106 cr, uid, conn, external_referential_id, defaults=defaults, context=context)
107
108>>>>>>> MERGE-SOURCE
78res_partner_address()109res_partner_address()
79110
80class res_partner(magerp_osv.magerp_osv):111class res_partner(magerp_osv.magerp_osv):
@@ -107,11 +138,20 @@
107 '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."),138 '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."),
108 'mag_newsletter':fields.boolean('Newsletter'),139 'mag_newsletter':fields.boolean('Newsletter'),
109 'magento_exported': fields.function(_is_magento_exported, type="boolean", method=True, string="Exists on Magento"),140 'magento_exported': fields.function(_is_magento_exported, type="boolean", method=True, string="Exists on Magento"),
141<<<<<<< TREE
110 'magento_pwd': fields.char('Magento Password', size=256),142 'magento_pwd': fields.char('Magento Password', size=256),
143=======
144 'is_magento_guest': fields.boolean(
145 'Is a Magento guest',
146 help="This partner has been created for a Magento "
147 "guest sale order.",
148 readonly=True)
149>>>>>>> MERGE-SOURCE
111 }150 }
112151
113 _sql_constraints = [('emailid_uniq', 'unique(emailid, website_id)', 'A partner already exists with this email address on the selected website.')]152 _sql_constraints = [('emailid_uniq', 'unique(emailid, website_id)', 'A partner already exists with this email address on the selected website.')]
114153
154<<<<<<< TREE
115 @only_for_referential('magento')155 @only_for_referential('magento')
116 def get_ids_and_update_date(self, cr, uid, external_session, ids=None, last_exported_date=None, context=None):156 def get_ids_and_update_date(self, cr, uid, external_session, ids=None, last_exported_date=None, context=None):
117 store_ids = [store.id for store in external_session.sync_from_object.storeview_ids]157 store_ids = [store.id for store in external_session.sync_from_object.storeview_ids]
@@ -143,5 +183,217 @@
143 for resource_id in resource_ids:183 for resource_id in resource_ids:
144 result = address_obj._export_one_resource(cr, uid, external_session, resource_id, context=context)184 result = address_obj._export_one_resource(cr, uid, external_session, resource_id, context=context)
145 return res185 return res
186=======
187 def _import_magento_addresses(self, cr, uid, connection, ext_customer_id,
188 referential_id, context=None):
189 """
190 Import all the magento addresses of a magento customer's address book
191
192 :param connection: connection to Magento
193 :param int ext_customer_id: id on Magento of the customer
194 :param int referential_id: id of the Magento external referential
195 """
196 if context is None:
197 context = {}
198 address_obj = self.pool.get('res.partner.address')
199 import_ctx = context.copy()
200 import_ctx['ids_or_filter'] = [ext_customer_id]
201 defaults = {'magento_address_book': True}
202 return address_obj.get_external_data(
203 cr, uid, connection, referential_id,
204 defaults=defaults, context=import_ctx)
205
206 def _disable_missing_addresses(self, cr, uid, partner_id, curr_address_ids,
207 referential_id, context=None):
208 """
209 Disable the addresses of the partner which have been deleted on
210 Magento since last synchronization.
211
212 :param int partner_id: id of the partner for whom we
213 update the addresses
214 :param list curr_address_ids: list of openerp ids of the addresses
215 which currently exist in the magento address book
216 :param int referential_id: id of the Magento external referential
217 :return: True
218 """
219 # list of the all the addresses in openerp which have been imported
220 # from this referential
221 address_obj = self.pool.get('res.partner.address')
222 partner_address_ids = address_obj.search(
223 cr, uid, [('partner_id', '=', partner_id)], context=context)
224 all_ref_address_ids = \
225 [address_id for address_id in partner_address_ids
226 if address_obj.oeid_to_extid(
227 cr, uid, address_id, referential_id, context=context)]
228
229 # do a diff to know which addresses does not anymore exist
230 # on Magento
231 del_address_ids = set(all_ref_address_ids).difference(curr_address_ids)
232 address_obj.write(
233 cr, uid, del_address_ids, {'active': False}, context=context)
234 return True
235
236 def import_magento_address_book(self, cr, uid, ids, referential_id,
237 context=None):
238 """
239 Import all the addresses from the Magento referential's address book
240 Deactivate the addresses which have been deleted from Magento
241 since the last import.
242
243 :param int/list ids: ids or list of ids of partner to import the
244 address book
245 :param int referential_id: id of the Magento external referential
246 """
247 if context is None:
248 context = {}
249
250 if isinstance(ids, (int, long)):
251 ids = [ids]
252
253 ref_obj = self.pool.get('external.referential')
254 connection = context.get('conn_obj') or \
255 ref_obj.external_connection(
256 cr, uid, referential_id, context=context)
257
258 for partner_id in ids:
259 ext_customer_id = self.oeid_to_extid(
260 cr, uid, partner_id, referential_id, context=context)
261
262 result = self._import_magento_addresses(
263 cr, uid, connection, ext_customer_id, referential_id,
264 context=context)
265
266 # list of all addresses currently in the magento address book
267 curr_address_ids = result['create_ids'] + result['write_ids']
268 self._disable_missing_addresses(
269 cr, uid, partner_id, curr_address_ids, referential_id,
270 context=context)
271
272 return True
273
274 def add_magento_vat_number(self, cr, uid, partner_id, tax_vat, country_code=None, context=None):
275 """Adds vat number (country code+magento vat) if base_vat module is installed and Magento sends customer_taxvat
276 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
277 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
278 Also we should think about the way to update customer. Indeed by default there are never updated"""
279 partner_vals = {'mag_vat': tax_vat}
280 cr.execute('select * from ir_module_module where name=%s and state=%s', ('base_vat','installed'))
281 if cr.fetchone():
282 allchars = string.maketrans('', '')
283 delchars = ''.join([c for c in allchars if c not in string.letters + string.digits])
284 vat = tax_vat.translate(allchars, delchars).upper()
285 vat_country, vat_number = vat[:2].lower(), vat[2:]
286 vat_ok = False
287 if 'check_vat_' + vat_country in dir(self):
288 check = getattr(self, 'check_vat_' + vat_country)
289 vat_ok = check(vat_number)
290 else:
291 # Maybe magento vat number has not country code prefix. Take it from billing address.
292 if country_code:
293 fnct = 'check_vat_' + country_code.lower()
294 if fnct in dir(self):
295 check = getattr(self, fnct)
296 vat_ok = check(vat)
297 vat = country_code + vat
298 else:
299 vat_ok = False
300 if vat_ok:
301 partner_vals.update({'vat_subjected':True, 'vat':vat})
302 self.write(cr, uid, [partner_id], partner_vals)
303 return True
304
305 def write(self, cr, uid, ids, vals, context=None):
306 if isinstance(ids, (int, long)):
307 ids = [ids]
308 if vals.get('store_id') and not vals.get('store_ids'):
309 for partner_id in ids:
310 # Add the last store id visited if
311 # it is not in the list of store ids
312 # partner store_id = last store where he bought (so this order)
313 # partner store_ids = all stores where he bought
314 atomic_vals = copy.deepcopy(vals)
315 partner = self.browse(cr, uid, partner_id, context=context)
316 if partner.store_id:
317 last_store_id = partner.store_id.id
318 if last_store_id not in [st.id for st in partner.store_ids]:
319 atomic_vals['store_ids'] = [(4, last_store_id)]
320
321 super(res_partner, self).write(
322 cr, uid, partner_id, atomic_vals, context=context)
323 else:
324 return super(res_partner, self).write(
325 cr, uid, ids, vals, context=context)
326 return True
327
328 def create(self, cr, uid, vals, context=None):
329 if vals.get('store_id') and not vals.get('store_ids'):
330 vals['store_ids'] = [(4, vals['store_id'])]
331 return super(res_partner, self).create(cr, uid, vals, context=context)
332
333 def search_magento_partner(self, cr, uid, magento_email, website_id, is_bound=None, context=None):
334 """
335 Searches and returns the partners which are potentially the same
336 based on the mail and the magento website id
337
338 :param str magento_email: mail of the customer on magento
339 :param int website_id: id of the website (openerp id!)
340 :param bool is_bound: specify it the partner must already be bound
341 with a magento customer (True) or not (False)
342 When None value: all partners ids are returned
343 :return: id of the found partner or False if any partner's found
344 """
345 partner_ids = False
346 if website_id:
347 partner_ids = self.search(cr, uid,
348 [('emailid', '=', magento_email),
349 ('website_id', '=', website_id)],
350 context=context)
351
352 # when the partner has been created, the website is not necessarily
353 # filled, in such case we search the first occurrence
354 # with the same email not already bound with a magento customer
355 if not partner_ids:
356 partner_ids = self.search(cr, uid,
357 [('emailid', '=', magento_email),
358 ('website_id', '=', False)],
359 context=context)
360 # keep or exclude already bound partners according to argument is_bound
361 if is_bound is not None:
362 partner_ids = [partner.id for partner
363 in self.browse(cr, uid, partner_ids[:], context=context)
364 if bool(partner.magento_exported) is is_bound]
365
366 return partner_ids and partner_ids[0] or False
367
368 def _existing_oeid_for_extid_import(self, cr, uid, vals, external_id, external_referential_id, context=None):
369 """
370 When importing a new customer from Magento (no external_id found in ir.model.data), we search
371 for a partner with the same emailid and website than the imported one
372 (fields must be filled in advance).
373
374 The external customer will update the partner returned in the tuple.
375 The external id will be created on this partner with the external resource
376 if the value is False in the tuple.
377
378 :param dict vals: vals to create in OpenERP, already evaluated by oevals_from_extdata
379 :param int external_id: external id of the resource to create
380 :param int external_referential_id: external referential id from where we import the resource
381 :return: tuple of (ir.model.data id / False: external id to create, model resource id / False: resource to create)
382 """
383 existing_ir_model_data_id, existing_res_id = super(res_partner, self)\
384 ._existing_oeid_for_extid_import(cr, uid, vals, external_id, external_referential_id, context=context)
385
386 if existing_res_id:
387 return existing_ir_model_data_id, existing_res_id
388
389 partner_id = self.search_magento_partner(
390 cr, uid,
391 vals['emailid'],
392 vals.get('website_id', False),
393 is_bound=None,
394 context=context)
395
396 return False, partner_id
397>>>>>>> MERGE-SOURCE
146398
147res_partner()399res_partner()
148400
=== modified file 'magentoerpconnect/partner_view.xml'
--- magentoerpconnect/partner_view.xml 2012-05-19 13:37:23 +0000
+++ magentoerpconnect/partner_view.xml 2012-07-06 14:53:18 +0000
@@ -7,11 +7,15 @@
7 <field name="type">form</field>7 <field name="type">form</field>
8 <field name="inherit_id" ref="base.view_partner_form" />8 <field name="inherit_id" ref="base.view_partner_form" />
9 <field name="arch" type="xml">9 <field name="arch" type="xml">
10<<<<<<< TREE
10 <xpath expr="/form/notebook/page/field/form/group/field[@name='name']" position="replace" >11 <xpath expr="/form/notebook/page/field/form/group/field[@name='name']" position="replace" >
11 <field name="company" />12 <field name="company" />
12 <field name="firstname" />13 <field name="firstname" />
13 <field name="lastname" />14 <field name="lastname" />
14 </xpath>15 </xpath>
16=======
17 <data>
18>>>>>>> MERGE-SOURCE
15 <xpath expr="/form/notebook" position="inside">19 <xpath expr="/form/notebook" position="inside">
16 <page string="Magento Information">20 <page string="Magento Information">
17 <field name="magento_exported" invisible="True"/>21 <field name="magento_exported" invisible="True"/>
@@ -23,11 +27,19 @@
23 <field name="mag_birthday" />27 <field name="mag_birthday" />
24 <field name="mag_newsletter" select="2"/>28 <field name="mag_newsletter" select="2"/>
25 <field name="store_id" />29 <field name="store_id" />
30 <field name="is_magento_guest"/>
26 <newline/>31 <newline/>
27 <separator string="Store views" colspan="4" />32 <separator string="Store views" colspan="4" />
28 <field name="store_ids" colspan="4" nolabel="1" attrs="{'readonly': [('magento_exported', '=', True)]}"/>33 <field name="store_ids" colspan="4" nolabel="1" attrs="{'readonly': [('magento_exported', '=', True)]}"/>
29 </page>34 </page>
30 </xpath>35 </xpath>
36 <xpath expr="//tree[@string='Partner Contacts']/field[@name='email']" position="after">
37 <field name="magento_address_book"/>
38 </xpath>
39 <xpath expr="//form[@string='Partner Contacts']/group[3]/field[@name='email']" position="after">
40 <field name="magento_address_book"/>
41 </xpath>
42 </data>
31 </field>43 </field>
32 </record>44 </record>
3345
@@ -50,11 +62,37 @@
50 <field name="type">form</field>62 <field name="type">form</field>
51 <field name="inherit_id" ref="base.view_partner_address_form1" />63 <field name="inherit_id" ref="base.view_partner_address_form1" />
52 <field name="arch" type="xml">64 <field name="arch" type="xml">
65<<<<<<< TREE
53 <field name="name" position="replace">66 <field name="name" position="replace">
54 <field name="company" />67 <field name="company" />
55 <field name="firstname" />68 <field name="firstname" />
56 <field name="lastname" />69 <field name="lastname" />
57 </field>70 </field>
71=======
72 <data>
73 <field name="active" position="after">
74 <field name="magento_address_book"/>
75 </field>
76 <field name="name" position="after">
77 <field name="firstname" />
78 <field name="lastname" />
79 </field>
80 </data>
81 </field>
82 </record>
83
84 <record id="view_partner_address_tree_mag" model="ir.ui.view">
85 <field name="name">res.partner.address.tree.mag</field>
86 <field name="model">res.partner.address</field>
87 <field name="inherit_id" ref="base.view_partner_address_tree"/>
88 <field name="type">tree</field>
89 <field name="arch" type="xml">
90 <data>
91 <field name="type" position="after">
92 <field name="magento_address_book"/>
93 </field>
94 </data>
95>>>>>>> MERGE-SOURCE
58 </field>96 </field>
59 </record>97 </record>
6098
6199
=== modified file 'magentoerpconnect/product.py'
--- magentoerpconnect/product.py 2012-05-25 19:24:00 +0000
+++ magentoerpconnect/product.py 2012-07-06 14:53:18 +0000
@@ -28,9 +28,14 @@
28import pooler28import pooler
29import magerp_osv29import magerp_osv
30from tools.translate import _30from tools.translate import _
31<<<<<<< TREE
32=======
33import logging
34>>>>>>> MERGE-SOURCE
31import unicodedata35import unicodedata
32import base64, urllib36import base64, urllib
33import os37import os
38import xmlrpclib
34from lxml import etree39from lxml import etree
35import xmlrpclib40import xmlrpclib
3641
@@ -175,7 +180,7 @@
175 'description': fields.text('Description'),180 'description': fields.text('Description'),
176 'image': fields.binary('Image'),181 'image': fields.binary('Image'),
177 'image_name':fields.char('File Name', size=100),182 'image_name':fields.char('File Name', size=100),
178 'meta_title': fields.char('Title (Meta)', size=75),183 'meta_title': fields.char('Title (Meta)', size=255),
179 'meta_keywords': fields.text('Meta Keywords'),184 'meta_keywords': fields.text('Meta Keywords'),
180 'meta_description': fields.text('Meta Description'),185 'meta_description': fields.text('Meta Description'),
181 'url_key': fields.char('URL-key', size=100), #Readonly186 'url_key': fields.char('URL-key', size=100), #Readonly
@@ -209,6 +214,7 @@
209 vals['magerp_stamp'] = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)214 vals['magerp_stamp'] = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
210 return super(product_category, self).write(cr, uid, ids, vals, context)215 return super(product_category, self).write(cr, uid, ids, vals, context)
211216
217<<<<<<< TREE
212 def _get_external_resource_ids(self, cr, uid, external_session, resource_filter=None, mapping=None, context=None):218 def _get_external_resource_ids(self, cr, uid, external_session, resource_filter=None, mapping=None, context=None):
213 def get_child_ids(tree):219 def get_child_ids(tree):
214 result=[]220 result=[]
@@ -222,6 +228,77 @@
222 categ_tree = external_session.connection.call('catalog_category.tree') #Get the tree228 categ_tree = external_session.connection.call('catalog_category.tree') #Get the tree
223 ids = get_child_ids(categ_tree)229 ids = get_child_ids(categ_tree)
224 return ids230 return ids
231=======
232 def record_entire_tree(self, cr, uid, id, conn, categ_tree, DEBUG=False):
233 self.record_category(cr, uid, id, conn, int(categ_tree['category_id']))
234 for each in categ_tree['children']:
235 self.record_entire_tree(cr, uid, id, conn, each)
236 return True
237
238 def record_category(self, cr, uid, external_referential_id, conn, category_id):
239 #This function should record a category
240 #The parent has to be created before creating child
241 imp_vals = conn.call('category.info', [category_id])
242 self.ext_import(cr, uid, [imp_vals], external_referential_id, defaults={}, context={'conn_obj':conn})
243
244 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
245 #TODO Move this function in base_sale_multichannels
246 if context is None:
247 context = {}
248
249 if defaults is None:
250 defaults = {}
251
252 res = False
253 orig_ids = ids[:]
254 ids_exportable = self.search(cr, uid, [('id', 'in', ids), ('magento_exportable', '=', True)]) #restrict export to only exportable products
255 ids = [id for id in ids if id in ids_exportable] #we need to keep the order of the categories
256 if not ids:
257 logger = logging.getLogger('magentoerpconnect')
258 logger.warning('called ext_export with ids %s, of which none were exportable', orig_ids)
259 return res
260
261 shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id'])
262
263 context_dic = [context.copy()]
264 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
265 context_dic[0]['lang'] = shop.referential_id.default_lang_id.code
266
267 for storeview in shop.storeview_ids:
268 if storeview.lang_id and storeview.lang_id.code != shop.referential_id.default_lang_id.code:
269 context_dic += [context.copy()]
270 context_dic[len(context_dic)-1].update({'storeview_code': storeview.code, 'lang': storeview.lang_id.code})
271
272 if shop.last_products_export_date and not context.get('force_export'):
273 last_exported_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(shop.last_products_export_date[:19], DEFAULT_SERVER_DATETIME_FORMAT)))
274 else:
275 last_exported_time = False
276
277 if not last_exported_time:
278 for ctx_storeview in context_dic:
279 ctx_storeview['force'] = True
280 res = super(product_category, self).ext_export(cr, uid, ids, external_referential_ids, defaults, ctx_storeview)
281 else:
282 cr.execute("select write_date, create_date from product_category where id in %s", (tuple(ids),))
283 read = cr.fetchall()
284 for categ in read:
285 last_updated_categ = categ[0] and categ[0].split('.')[0] or categ[1] and categ[1].split('.')[0] or False
286 last_updated_categ_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(last_updated_categ[:19], DEFAULT_SERVER_DATETIME_FORMAT)))
287 if last_updated_categ_time and last_exported_time:
288 if last_exported_time - datetime.timedelta(seconds=1) < last_updated_categ_time:
289 for ctx_storeview in context_dic:
290 ctx_storeview['force'] = True
291 res = super(product_category, self).ext_export(cr, uid, ids, external_referential_ids, defaults, ctx_storeview)
292 break
293 return res
294
295 def try_ext_update(self, cr, uid, data, conn, method, oe_id, external_id, ir_model_data_id, create_method, context=None):
296 if context is None: context = {}
297 if context.get('storeview_code', False):
298 return conn.call(method, [external_id, data, context.get('storeview_code', False)])
299 else:
300 return conn.call(method, [external_id, data])
301>>>>>>> MERGE-SOURCE
225302
226product_category()303product_category()
227304
@@ -255,6 +332,7 @@
255 ('gallery', 'Gallery'),332 ('gallery', 'Gallery'),
256 ('weee', 'Fixed Product Tax'),333 ('weee', 'Fixed Product Tax'),
257 ('file', 'File'), #this option is not a magento native field it will be better to found a generic solutionto manage this kind of custom option334 ('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
335 ('weight', 'Weight'),
258 ], 'Frontend Input'336 ], 'Frontend Input'
259 ),337 ),
260 'frontend_class':fields.char('Frontend Class', size=100),338 'frontend_class':fields.char('Frontend Class', size=100),
@@ -290,13 +368,20 @@
290 #These parameters are for automatic management368 #These parameters are for automatic management
291 'field_name':fields.char('Open ERP Field name', size=100),369 'field_name':fields.char('Open ERP Field name', size=100),
292 'attribute_set_info':fields.text('Attribute Set Information'),370 'attribute_set_info':fields.text('Attribute Set Information'),
293 'based_on':fields.selection([('product_product', 'Product Product'), ('product_template', 'Product Template')], 'Based On'),371 'based_on':fields.selection([('product.product', 'Product Product'), ('product.template', 'Product Template')], 'Based On'),
294 }372 }
295373
296 _defaults = {374 _defaults = {
297 'based_on': lambda*a: 'product_template',375 'based_on': lambda*a: 'product.template',
298 }376 }
299377
378 def init(self, cr):
379 """ Replace product_product by product.product
380 and product_template by product.template for
381 consistency with model names"""
382 cr.execute("UPDATE magerp_product_attributes SET based_on = REPLACE(based_on, '_', '.')")
383 cr.execute("UPDATE magerp_product_attributes SET based_on = 'product.template' WHERE based_on IS NULL")
384
300 #mapping magentofield:(openerpfield,typecast,)385 #mapping magentofield:(openerpfield,typecast,)
301 #have an entry for each mapped field386 #have an entry for each mapped field
302 _no_create_list = [387 _no_create_list = [
@@ -372,6 +457,7 @@
372 'visibility',457 'visibility',
373 ]458 ]
374459
460<<<<<<< TREE
375461
376 #TODO check if this field have to be in only one way and if yes add this feature462 #TODO check if this field have to be in only one way and if yes add this feature
377 _sync_way = {463 _sync_way = {
@@ -382,19 +468,25 @@
382 def _is_attribute_translatable(self, vals):468 def _is_attribute_translatable(self, vals):
383 """Tells if field associated to attribute should be translatable or not.469 """Tells if field associated to attribute should be translatable or not.
384 For now we are using a default list, later we could say that any attribute470 For now we are using a default list, later we could say that any attribute
471=======
472 MODEL_SERIALIZED_FIELD = {
473 'product.template': 'magerp_tmpl',
474 'product.product': 'magerp_variant',
475 }
476
477 def _is_attribute_translatable(self, attribute):
478 """Tells if field associated to attribute
479 should be translatable or not.
480 For now we are using a default list,
481 later we could say that any attribute
482>>>>>>> MERGE-SOURCE
385 which scope in Magento is 'store' should be translated."""483 which scope in Magento is 'store' should be translated."""
386 if vals['attribute_code'] in self._translatable_default_codes:484 return bool(attribute.attribute_code in self._translatable_default_codes)
387 return True485
388 else:486 def create_ir_fields(self, cr, uid, ids, update_options=False, context=None):
389 return False487 if isinstance(ids, (int, long)):
390
391 def write(self, cr, uid, ids, vals, context=None):
392 """Will recreate the mapping attributes, beware if you customized some!"""
393 if context is None:
394 context = {}
395
396 if type(ids) == int:
397 ids = [ids]488 ids = [ids]
489<<<<<<< TREE
398 result = super(magerp_product_attributes, self).write(cr, uid, ids, vals, context)490 result = super(magerp_product_attributes, self).write(cr, uid, ids, vals, context)
399 model_ids = self.pool.get('ir.model').search(cr, uid, [('model', 'in', ['product.product', 'product.template'])])491 model_ids = self.pool.get('ir.model').search(cr, uid, [('model', 'in', ['product.product', 'product.template'])])
400 product_model_id = self.pool.get('ir.model').search(cr, uid, [('model', 'in', ['product.product'])])[0]492 product_model_id = self.pool.get('ir.model').search(cr, uid, [('model', 'in', ['product.product'])])[0]
@@ -402,11 +494,26 @@
402 for id in ids:494 for id in ids:
403 all_vals = self.read(cr, uid, id, [], context)495 all_vals = self.read(cr, uid, id, [], context)
404496
497=======
498
499 for attribute in self.browse(cr, uid, ids, context=context):
500 if attribute.attribute_code in self._no_create_list:
501 continue
502>>>>>>> MERGE-SOURCE
405 #Fetch Options503 #Fetch Options
504<<<<<<< TREE
406 if 'frontend_input' in all_vals.keys() and all_vals['frontend_input'] in ['select', 'multiselect']:505 if 'frontend_input' in all_vals.keys() and all_vals['frontend_input'] in ['select', 'multiselect']:
407 core_imp_conn = self.pool.get('external.referential').external_connection(cr, uid, [referential_id])506 core_imp_conn = self.pool.get('external.referential').external_connection(cr, uid, [referential_id])
408 options_data = core_imp_conn.call('ol_catalog_product_attribute.options', [all_vals['magento_id']])507 options_data = core_imp_conn.call('ol_catalog_product_attribute.options', [all_vals['magento_id']])
508=======
509 if attribute.frontend_input in ['select', 'multiselect']:
510 core_imp_conn = self.pool.get('external.referential').connect(
511 cr, uid, [attribute.referential_id.id])
512 options_data = core_imp_conn.call(
513 'ol_catalog_product_attribute.options', [attribute.magento_id])
514>>>>>>> MERGE-SOURCE
409 if options_data:515 if options_data:
516<<<<<<< TREE
410 self.pool.get('magerp.product_attribute_options').data_to_save(cr, uid, options_data, update=True, context={'attribute_id': id, 'referential_id': referential_id})517 self.pool.get('magerp.product_attribute_options').data_to_save(cr, uid, options_data, update=True, context={'attribute_id': id, 'referential_id': referential_id})
411518
412519
@@ -415,20 +522,123 @@
415 field_ids = self.pool.get('ir.model.fields').search(cr, uid, [('name', '=', field_name), ('model_id', 'in', model_ids)])522 field_ids = self.pool.get('ir.model.fields').search(cr, uid, [('name', '=', field_name), ('model_id', 'in', model_ids)])
416 if field_ids:523 if field_ids:
417 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)524 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)
525=======
526 options_obj = self.pool.get('magerp.product_attribute_options')
527 ctx_opt = dict(context,
528 attribute_id=attribute.id,
529 referential_id=attribute.referential_id.id)
530 options_obj.data_to_save(
531 cr, uid, options_data,
532 update=update_options,
533 context=ctx_opt)
534
535 # Create fields in ir.model.data if it does not already exist
536 # Create the field accordingly to the "based_on"
537 # configuration of the attribute (product.product or product.template)
538 if attribute.attribute_code and attribute.frontend_input:
539 model_ids = self.pool.get('ir.model').search(
540 cr, uid, [('model', '=', attribute.based_on)], context=context)
541
542 fields_obj = self.pool.get('ir.model.fields')
543 # Check if field already exists
544 field_ids = fields_obj.search(
545 cr, uid,
546 [('name', '=', attribute.field_name),
547 ('model', '=', attribute.based_on)],
548 context=context)
549 field_vals = {
550 'name': attribute.field_name,
551 'model_id': model_ids[0],
552 'model': attribute.based_on,
553 'field_description': attribute.frontend_label or \
554 attribute.attribute_code,
555 'ttype': self._type_conversion[attribute.frontend_input],
556 'translate': self._is_attribute_translatable(attribute),
557 }
558 if not attribute.attribute_code in self._not_store_in_json:
559 field_vals['serialization_field_id'] = fields_obj.search(
560 cr, uid,
561 [('name', '=', self.MODEL_SERIALIZED_FIELD[attribute.based_on]),
562 ('model', '=', attribute.based_on)],
563 context=context)[0]
564 if not field_ids:
565 #The field is not there create it
566 #IF char add size
567 if field_vals['ttype'] == 'char':
568 field_vals['size'] = 100
569 elif field_vals['ttype'] == 'many2one':
570 field_vals['relation'] = 'magerp.product_attribute_options'
571 field_vals['domain'] = "[('attribute_id', '=', %s)]" % attribute.id
572 elif field_vals['ttype'] == 'many2many':
573 field_vals['relation'] = 'magerp.product_attribute_options'
574 field_vals['domain'] = "[('attribute_id', '=', %s)]" % attribute.id
575 field_vals['state'] = 'manual'
576
577 #All field values are computed, now save
578 self.pool.get('ir.model.fields').create(
579 cr, uid, field_vals, context=context)
580 return True
581
582 def update_mapping(self, cr, uid, ids, context=None):
583 """Create mappings for the attributes
584 if they have a field name
585 and a field in ir.model.data"""
586 if isinstance(ids, (int, long)):
587 ids = [ids]
588
589 for attribute in self.browse(cr, uid, ids, context=context):
590 if not attribute.field_name:
591 continue
592 field_obj = self.pool.get('ir.model.fields')
593 field_ids = field_obj.search(
594 cr, uid,
595 [('name', '=', attribute.field_name),
596 ('model', '=', attribute.based_on)],
597 context=context)
598 if not field_ids:
599 continue
600 field = field_obj.browse(
601 cr, uid, field_ids[0], context=context)
602 self._create_mapping(
603 cr, uid,
604 attribute,
605 field,
606 context=context)
607 return True
608
609 def write(self, cr, uid, ids, vals, context=None):
610 """Will recreate the mapping attributes,
611 beware if you customized some!"""
612 if context is None:
613 context = {}
614
615 if isinstance(ids, (int, long)):
616 ids = [ids]
617
618 result = super(magerp_product_attributes, self).write(cr, uid, ids, vals, context=context)
619
620 self.create_ir_fields(
621 cr, uid, ids, update_options=True, context=context)
622
623 self.update_mapping(cr, uid, ids, context=context)
624>>>>>>> MERGE-SOURCE
418 return result625 return result
419626
420 def create(self, cr, uid, vals, context=None):627 def create(self, cr, uid, vals, context=None):
421 """Will create product.template new fields accordingly to Magento product custom attributes and also create mappings for them"""628 """Will create product.template new fields accordingly
629 to Magento product custom attributes
630 and also create mappings for them"""
422 if context is None:631 if context is None:
423 context = {}632 context = {}
424 if not vals['attribute_code'] in self._no_create_list:633 if not vals['attribute_code'] in self._no_create_list:
425 field_name = "x_magerp_" + vals['attribute_code']634 field_name = "x_magerp_" + vals['attribute_code']
426 field_name = convert_to_ascii(field_name)635 field_name = convert_to_ascii(field_name)
427 vals['field_name']= field_name636 vals['field_name'] = field_name
428 if 'attribute_set_info' in vals.keys():637 if 'attribute_set_info' in vals.keys():
429 attr_set_info = eval(vals.get('attribute_set_info',{}))638 attr_set_info = eval(vals.get('attribute_set_info',{}))
430 for each_key in attr_set_info.keys():639 for each_key in attr_set_info.keys():
431 vals['group_id'] = attr_set_info[each_key].get('group_id', False)640 vals['group_id'] = attr_set_info[each_key].get('group_id', False)
641<<<<<<< TREE
432642
433 crid = super(magerp_product_attributes, self).create(cr, uid, vals, context)643 crid = super(magerp_product_attributes, self).create(cr, uid, vals, context)
434 if not vals['attribute_code'] in self._no_create_list:644 if not vals['attribute_code'] in self._no_create_list:
@@ -494,7 +704,31 @@
494 #If the field have restriction on domain704 #If the field have restriction on domain
495 #Maybe we can give the posibility to map directly m2m and m2o field_description705 #Maybe we can give the posibility to map directly m2m and m2o field_description
496 #by filtrering directly with the domain and the string value706 #by filtrering directly with the domain and the string value
707=======
708
709 # By default some fields should be based on product variants
710 # instead of templates.
711 if vals['attribute_code'] in self._variant_fields:
712 vals['based_on'] = 'product.product'
713
714 attribute_id = super(magerp_product_attributes, self).create(
715 cr, uid, vals, context=context)
716
717 if attribute_id:
718 self.create_ir_fields(
719 cr, uid,
720 attribute_id,
721 update_options=False,
722 context=context)
723 self.update_mapping(cr, uid, attribute_id, context=context)
724 return attribute_id
725
726 def _default_mapping(self, cr, uid, attribute, field, context=None):
727 in_function = out_function = False
728 ttype = field.ttype
729>>>>>>> MERGE-SOURCE
497 if ttype in ['char', 'text', 'date', 'float', 'weee', 'boolean']:730 if ttype in ['char', 'text', 'date', 'float', 'weee', 'boolean']:
731<<<<<<< TREE
498 mapping_line['evaluation_type'] = 'direct'732 mapping_line['evaluation_type'] = 'direct'
499 if ttype == 'float':733 if ttype == 'float':
500 mapping_line['external_type'] = 'float'734 mapping_line['external_type'] = 'float'
@@ -503,7 +737,12 @@
503 else:737 else:
504 mapping_line['external_type'] = 'unicode'738 mapping_line['external_type'] = 'unicode'
505739
740=======
741 in_function = "result = [('%s', ifield)]" % (field.name,)
742 out_function = "result = [('%s', record['%s'])]" % (attribute.attribute_code, field.name)
743>>>>>>> MERGE-SOURCE
506 elif ttype in ['many2one']:744 elif ttype in ['many2one']:
745<<<<<<< TREE
507 mapping_line['evaluation_type'] = 'function'746 mapping_line['evaluation_type'] = 'function'
508 mapping_line['in_function'] = \747 mapping_line['in_function'] = \
509 ("if '%(attribute_code)s' in resource:\n"748 ("if '%(attribute_code)s' in resource:\n"
@@ -518,7 +757,20 @@
518 " option = self.pool.get('magerp.product_attribute_options').browse(cr, uid, resource['%(field_name)s'][0])\n"757 " option = self.pool.get('magerp.product_attribute_options').browse(cr, uid, resource['%(field_name)s'][0])\n"
519 " if option:\n"758 " if option:\n"
520 " result = [('%(attribute_code)s', option.value)]") % ({'field_name': field_name, 'attribute_code': vals['attribute_code']})759 " result = [('%(attribute_code)s', option.value)]") % ({'field_name': field_name, 'attribute_code': vals['attribute_code']})
760=======
761 in_function = ("if ifield:\n"
762 " option_id = self.pool.get('magerp.product_attribute_options').search(cr, uid, [('attribute_id','=',%(attribute_id)s),('value','=',ifield)])\n"
763 " if option_id:\n"
764 " result = [('%(field_name)s', option_id[0])]") % ({'attribute_id': attribute.id, 'field_name': field.name})
765 # we browse on record['%(field_name)s'][0] because record[field_name] is in the form (id, name)
766 out_function = ("result = [('%(attribute_code)s', False)]\n"
767 "if record.get('%(field_name)s'):\n"
768 " option = self.pool.get('magerp.product_attribute_options').browse(cr, uid, record['%(field_name)s'][0])\n"
769 " if option:\n"
770 " result = [('%(attribute_code)s', option.value)]") % ({'field_name': field.name, 'attribute_code': attribute.attribute_code})
771>>>>>>> MERGE-SOURCE
521 elif ttype in ['many2many']:772 elif ttype in ['many2many']:
773<<<<<<< TREE
522 mapping_line['evaluation_type'] = 'function'774 mapping_line['evaluation_type'] = 'function'
523 mapping_line['in_function'] = ("option_ids = []\n"775 mapping_line['in_function'] = ("option_ids = []\n"
524 "opt_obj = self.pool.get('magerp.product_attribute_options')\n"776 "opt_obj = self.pool.get('magerp.product_attribute_options')\n"
@@ -530,7 +782,20 @@
530 " options = self.pool.get('magerp.product_attribute_options').browse(cr, uid, resource['%(field_name)s'])\n"782 " options = self.pool.get('magerp.product_attribute_options').browse(cr, uid, resource['%(field_name)s'])\n"
531 " result = [('%(attribute_code)s', [option.value for option in options])]") % \783 " result = [('%(attribute_code)s', [option.value for option in options])]") % \
532 ({'field_name': field_name, 'attribute_code': vals['attribute_code']})784 ({'field_name': field_name, 'attribute_code': vals['attribute_code']})
785=======
786 in_function = ("option_ids = []\n"
787 "opt_obj = self.pool.get('magerp.product_attribute_options')\n"
788 "for ext_option_id in ifield:\n"
789 " option_ids.extend(opt_obj.search(cr, uid, [('attribute_id','=',%(attribute_id)s), ('value','=',ext_option_id)]))\n"
790 "result = [('%(field_name)s', [(6, 0, option_ids)])]") % ({'attribute_id': attribute.id, 'field_name': field.name})
791 out_function = ("result=[('%(attribute_code)s', [])]\n"
792 "if record.get('%(field_name)s'):\n"
793 " options = self.pool.get('magerp.product_attribute_options').browse(cr, uid, record['%(field_name)s'])\n"
794 " result = [('%(attribute_code)s', [option.value for option in options])]") % \
795 ({'field_name': field.name, 'attribute_code': attribute.attribute_code})
796>>>>>>> MERGE-SOURCE
533 elif ttype in ['binary']:797 elif ttype in ['binary']:
798<<<<<<< TREE
534 warning_text = "Binary mapping is actually not supported (attribute: %s)" % (vals['attribute_code'],)799 warning_text = "Binary mapping is actually not supported (attribute: %s)" % (vals['attribute_code'],)
535 _logger.warn(warning_text)800 _logger.warn(warning_text)
536 warning_msg = ("import logging\n"801 warning_msg = ("import logging\n"
@@ -538,11 +803,21 @@
538 "logger.warn('%s')") % (warning_text,)803 "logger.warn('%s')") % (warning_text,)
539 mapping_line['in_function'] = mapping_line['out_function'] = warning_msg804 mapping_line['in_function'] = mapping_line['out_function'] = warning_msg
540 return mapping_line805 return mapping_line
806=======
807 logger = logging.getLogger('ext synchro mapping')
808 logger.warn("Binary mapping is actually not supported (attribute: %s)", attribute.attribute_code)
809 warning_msg = ("import logging\n"
810 "logger = logging.getLogger('ext synchro mapping')\n"
811 "logger.warn('Binary mapping is actually not supported (attribute: %%s)', %s)") % (attribute.attribute_code)
812 in_function = out_function = warning_msg
813 return in_function, out_function
814>>>>>>> MERGE-SOURCE
541815
542 def _create_mapping(self, cr, uid, ttype, field_id, field_name, referential_id, model_id, vals, attribute_id):816 def _create_mapping(self, cr, uid, attribute, field, context=None):
543 """Search & create mapping entries"""817 """Search and create mapping entries"""
544 if vals['attribute_code'] in self._no_create_list:818 if attribute.attribute_code in self._no_create_list:
545 return False819 return False
820<<<<<<< TREE
546 mapping_id = self.pool.get('external.mapping').search(cr, uid, [('referential_id', '=', referential_id), ('model_id', '=', model_id)])821 mapping_id = self.pool.get('external.mapping').search(cr, uid, [('referential_id', '=', referential_id), ('model_id', '=', model_id)])
547 if mapping_id:822 if mapping_id:
548 existing_line = self.pool.get('external.mapping.line').search(cr, uid, [('external_field', '=', vals['attribute_code']), ('mapping_id', '=', mapping_id[0])])823 existing_line = self.pool.get('external.mapping.line').search(cr, uid, [('external_field', '=', vals['attribute_code']), ('mapping_id', '=', mapping_id[0])])
@@ -555,6 +830,38 @@
555 'field_id': field_id, }830 'field_id': field_id, }
556 mapping_line = self._default_mapping(cr, uid, ttype, field_name, vals, attribute_id, model_id, mapping_line, referential_id)831 mapping_line = self._default_mapping(cr, uid, ttype, field_name, vals, attribute_id, model_id, mapping_line, referential_id)
557 self.pool.get('external.mapping.line').create(cr, uid, mapping_line)832 self.pool.get('external.mapping.line').create(cr, uid, mapping_line)
833=======
834 # the mapping should always be created on the product.product
835 # model, and not on product.template
836 mapping_ids = self.pool.get('external.mapping').search(
837 cr, uid,
838 [('referential_id', '=', attribute.referential_id.id),
839 ('model_id.model', '=', 'product.product')],
840 context=context)
841 if not mapping_ids:
842 raise osv.except_osv(
843 _('Error'),
844 _("No Object Mapping \"Product\""
845 "for \"%s\"." % attribute.referential_id.name))
846 existing_line = self.pool.get('external.mapping.line').search(
847 cr, uid,
848 [('external_field', '=', attribute.attribute_code),
849 ('mapping_id', '=', mapping_ids[0])],
850 context=context)
851 if not existing_line:
852 mapping_line = {
853 'external_field': attribute.attribute_code,
854 'mapping_id': mapping_ids[0],
855 'type': 'in_out',
856 'external_type': self._type_casts[attribute.frontend_input],
857 'field_id': field.id,
858 'evaluation_type': 'function',
859 }
860 mapping_line['in_function'], mapping_line['out_function'] = \
861 self._default_mapping(cr, uid, attribute, field, context=context)
862 self.pool.get('external.mapping.line').create(
863 cr, uid, mapping_line, context=context)
864>>>>>>> MERGE-SOURCE
558 return True865 return True
559866
560magerp_product_attributes()867magerp_product_attributes()
@@ -683,6 +990,11 @@
683 cr.execute(query)990 cr.execute(query)
684 return True991 return True
685992
993<<<<<<< TREE
994=======
995 return True
996
997>>>>>>> MERGE-SOURCE
686magerp_product_attribute_set()998magerp_product_attribute_set()
687999
688class magerp_product_attribute_groups(magerp_osv.magerp_osv):1000class magerp_product_attribute_groups(magerp_osv.magerp_osv):
@@ -695,11 +1007,15 @@
695 for attribute_group in self.browse(cr, uid, ids, context):1007 for attribute_group in self.browse(cr, uid, ids, context):
696 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)1008 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)
697 return res1009 return res
1010<<<<<<< TREE
6981011
699 def _get_filter(self, cr, uid, external_session, step, previous_filter=None, context=None):1012 def _get_filter(self, cr, uid, external_session, step, previous_filter=None, context=None):
700 attrset_ids = self.pool.get('magerp.product_attribute_set').get_all_extid_from_referential(cr, uid, external_session.referential_id.id, context=context)1013 attrset_ids = self.pool.get('magerp.product_attribute_set').get_all_extid_from_referential(cr, uid, external_session.referential_id.id, context=context)
701 return {'attribute_set_id':{'in':attrset_ids}}1014 return {'attribute_set_id':{'in':attrset_ids}}
7021015
1016=======
1017
1018>>>>>>> MERGE-SOURCE
703 _columns = {1019 _columns = {
704 'attribute_set_id':fields.integer('Attribute Set ID'),1020 'attribute_set_id':fields.integer('Attribute Set ID'),
705 'attribute_set':fields.function(_get_set, type="many2one", relation="magerp.product_attribute_set", method=True, string="Attribute Set"),1021 'attribute_set':fields.function(_get_set, type="many2one", relation="magerp.product_attribute_set", method=True, string="Attribute Set"),
@@ -1133,12 +1449,25 @@
1133 #TODO base the import on the mapping and the function ext_import1449 #TODO base the import on the mapping and the function ext_import
1134 def import_product_image(self, cr, uid, id, referential_id, conn, ext_id=None, context=None):1450 def import_product_image(self, cr, uid, id, referential_id, conn, ext_id=None, context=None):
1135 image_obj = self.pool.get('product.images')1451 image_obj = self.pool.get('product.images')
1452<<<<<<< TREE
1453=======
1454 logger = logging.getLogger('ext synchro')
1455>>>>>>> MERGE-SOURCE
1136 if not ext_id:1456 if not ext_id:
1457<<<<<<< TREE
1137 ext_id = self.get_extid(cr, uid, id, referential_id, context=context)1458 ext_id = self.get_extid(cr, uid, id, referential_id, context=context)
1138 # TODO everythere will should pass the params 'id' for magento api in order to force1459 # TODO everythere will should pass the params 'id' for magento api in order to force
1460=======
1461 ext_id = self.oeid_to_extid(cr, uid, id, referential_id, context=None)
1462 # TODO everythere will should pass the params 'id' for magento api in order to force
1463>>>>>>> MERGE-SOURCE
1139 # to use the id as external key instead of mixed id/sku1464 # to use the id as external key instead of mixed id/sku
1140 img_list = conn.call('catalog_product_attribute_media.list', [ext_id, False, 'id'])1465 img_list = conn.call('catalog_product_attribute_media.list', [ext_id, False, 'id'])
1466<<<<<<< TREE
1141 _logger.info("Magento image for product ext_id %s: %s", ext_id, img_list)1467 _logger.info("Magento image for product ext_id %s: %s", ext_id, img_list)
1468=======
1469 logger.info("Magento image for product ext_id %s: %s", ext_id, img_list)
1470>>>>>>> MERGE-SOURCE
1142 images_name = []1471 images_name = []
1143 for image in img_list:1472 for image in img_list:
1144 img=False1473 img=False
@@ -1148,13 +1477,21 @@
1148 data = f.read()1477 data = f.read()
1149 f.close()1478 f.close()
1150 if "DOCTYPE html PUBLIC" in data:1479 if "DOCTYPE html PUBLIC" in data:
1480<<<<<<< TREE
1151 _logger.warn("failed to open the image %s from Magento", image['url'])1481 _logger.warn("failed to open the image %s from Magento", image['url'])
1482=======
1483 logger.warn("Failed to open the image %s from Magento", image['url'])
1484>>>>>>> MERGE-SOURCE
1152 continue1485 continue
1153 else:1486 else:
1154 img = base64.encodestring(data)1487 img = base64.encodestring(data)
1155 except Exception, e:1488 except Exception, e:
1156 #TODO raise correctly the error1489 #TODO raise correctly the error
1490<<<<<<< TREE
1157 _logger.error("failed to open the image %s from Magento, error : %s", image['url'], e, exc_info=True)1491 _logger.error("failed to open the image %s from Magento, error : %s", image['url'], e, exc_info=True)
1492=======
1493 logger.error("Failed to open the image %s from Magento, error : %s", image['url'], e, exc_info=True)
1494>>>>>>> MERGE-SOURCE
1158 continue1495 continue
1159 mag_filename, extention = os.path.splitext(os.path.basename(image['file']))1496 mag_filename, extention = os.path.splitext(os.path.basename(image['file']))
1160 data = {'name': image['label'] and not image['label'] in images_name and image['label'] or mag_filename,1497 data = {'name': image['label'] and not image['label'] in images_name and image['label'] or mag_filename,
@@ -1180,6 +1517,7 @@
1180 new_image_id = image_obj.create(cr, uid, data, context=context)1517 new_image_id = image_obj.create(cr, uid, data, context=context)
1181 image_obj.create_external_id_vals(cr, uid, new_image_id, image['file'], referential_id, context=context)1518 image_obj.create_external_id_vals(cr, uid, new_image_id, image['file'], referential_id, context=context)
1182 return True1519 return True
1520<<<<<<< TREE
11831521
1184 def get_field_to_export(self, cr, uid, ids, mapping, mapping_id, context=None):1522 def get_field_to_export(self, cr, uid, ids, mapping, mapping_id, context=None):
1185 res = super(product_product, self).get_field_to_export(cr, uid, ids, mapping, mapping_id, context=context)1523 res = super(product_product, self).get_field_to_export(cr, uid, ids, mapping, mapping_id, context=context)
@@ -1215,6 +1553,21 @@
1215 context=context1553 context=context
1216 ))1554 ))
1217 return resources1555 return resources
1556=======
1557
1558 def extid_to_existing_oeid(self, cr, uid, id, external_referential_id, context=None):
1559 """Returns the OpenERP id of a resource by its external id.
1560 Returns False if the resource does not exist."""
1561 if not context:
1562 context={}
1563 res = super(product_mag_osv, self).extid_to_existing_oeid(cr, uid, id, external_referential_id, context=context)
1564 # TODO : check if this can be replaced by _existing_oeid_for_extid_import (see example in res.partner)
1565 # thus when importing a product which do not already exists in OpenERP, ext_import will create the binding and update it directly
1566 if not res and context.get('magento_sku', False):
1567 product_id = self.search(cr, uid, [('magento_sku', '=', context['magento_sku'])], context=context)
1568 return product_id and product_id[0] or False
1569 return res
1570>>>>>>> MERGE-SOURCE
12181571
1219 def _product_type_get(self, cr, uid, context=None):1572 def _product_type_get(self, cr, uid, context=None):
1220 ids = self.pool.get('magerp.product_product_type').search(cr, uid, [], order='id')1573 ids = self.pool.get('magerp.product_product_type').search(cr, uid, [], order='id')
@@ -1344,6 +1697,266 @@
1344 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.'))1697 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.'))
1345 else:1698 else:
1346 return super(product_product, self).unlink(cr, uid, ids, context)1699 return super(product_product, self).unlink(cr, uid, ids, context)
1700<<<<<<< TREE
1701=======
1702
1703 #TODO move part of this to declarative mapping CSV template
1704 def extdata_from_oevals(self, cr, uid, external_referential_id, data_record, mapping_lines, defaults, context=None):
1705 product_data = super(product_product, self).extdata_from_oevals(cr, uid, external_referential_id, data_record, mapping_lines, defaults, context) #Aapply custom/attributes mappings
1706 if context is None: context = {}
1707 product = self.browse(cr, uid, data_record['id'], context)
1708 shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id'], context)
1709
1710 if not product_data.get('price', False):
1711 pl_default_id = shop.pricelist_id and shop.pricelist_id.id or self.pool.get('product.pricelist').search(cr, uid, [('type', '=', 'sale')])
1712 if isinstance(pl_default_id, int):
1713 pl_default_id = [pl_default_id]
1714 product_data.update({'price': self.pool.get('product.pricelist').price_get(cr, uid, pl_default_id, product.id, 1.0)[pl_default_id[0]]})
1715
1716 if not product_data.get('tax_class_id', False):
1717 product_data.update({'tax_class_id': 2}) #FIXME hugly!
1718
1719 if not product_data.get('status', False):
1720 product_data.update({'status': product.active and 1 or 0})
1721
1722 if not product_data.get('description', False):
1723 product_data.update({'description': product.description or _("description")})
1724 if not product_data.get('short_description', False):
1725 product_data.update({'short_description': product.description_sale or _("short description")})
1726 if not product_data.get('meta_title', False):
1727 product_data.update({'meta_title': product.name})
1728 if not product_data.get('meta_keyword', False):
1729 product_data.update({'meta_keyword': product.name})
1730 if not product_data.get('meta_description', False):
1731 product_data.update({'meta_description': product.description_sale and product.description_sale[:255]})
1732
1733 return product_data
1734
1735 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):
1736 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)
1737 # assign a default product type (Procurement, not the magento's one)
1738 if not res.get('type'):
1739 magerp_type_obj = self.pool.get('magerp.product_product_type')
1740 magerp_type_ids = magerp_type_obj.search(cr, uid, [('product_type', '=', data_record['type_id'])], context=context)
1741 if magerp_type_ids:
1742 res['type'] = magerp_type_obj.read(cr, uid, magerp_type_ids[0], ['default_type'], context=context)['default_type']
1743 return res
1744
1745 def product_to_sku(self, cr, uid, product):
1746 if product.magento_sku:
1747 sku = product.magento_sku
1748 else:
1749 code = product.code or 'mag'
1750 same_codes = self.search(cr, uid, [('magento_sku', '=', code)])
1751 if same_codes and len(same_codes) > 0:
1752 sku = code + "_" + str(product.id)
1753 else:
1754 sku = code
1755 return sku
1756
1757 def _ext_update_and_rebind(self, cr, uid, data, conn, oe_id, sku=None, context=None):
1758 if sku is None:
1759 product = self.browse(cr, uid, oe_id, context=context)
1760 sku = product.sku
1761 ext_data = conn.call('catalog_product.info', [sku, False, 'sku'])
1762 ext_id = ext_data['product_id']
1763 conn.call('ol_catalog_product.update', [ext_id, data, False, 'id'])
1764 return ext_id
1765
1766 def ext_create(self, cr, uid, data, conn, method, oe_id, context=None):
1767 if context is None: context = {}
1768 product = self.browse(cr, uid, oe_id, context=context)
1769 sku = self.product_to_sku(cr, uid, product)
1770 shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id'])
1771 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)
1772
1773 product_type = self.read(cr, uid, oe_id, ['product_type'])['product_type'] or 'simple'
1774
1775 try:
1776 ext_id = super(magerp_osv.magerp_osv, self).ext_create(
1777 cr, uid, [product_type, attr_set_id, sku, data], conn, method, oe_id, context)
1778 except xmlrpclib.Fault, e:
1779 # Magento raise error 1 when we try to create
1780 # a product with a SKU which already exists
1781 if e.faultCode == 1:
1782 ext_id = self._ext_update_and_rebind(
1783 cr, uid, data, conn, oe_id, sku=sku, context=context)
1784 else:
1785 raise
1786 self.write(cr, uid, oe_id, {'magento_sku': sku})
1787 return ext_id
1788
1789 def action_before_exporting_grouped_product(self, cr, uid, id, external_referential_ids=None, defaults=None, context=None):
1790 logger = logging.getLogger('ext synchro')
1791 if context.get('mrp_is_installed', False):
1792 bom_ids = self.read(cr, uid, id, ['bom_ids'])['bom_ids']
1793 if len(bom_ids): # it has or is part of a BoM
1794 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?
1795 results = cr.dictfetchall()
1796 child_ids = []
1797 quantities = {}
1798 for row in results:
1799 child_ids.append(row['product_id'])
1800 quantities.update({row['product_id']: row['product_qty']})
1801 if child_ids: #it is an assembly and it contains the products child_ids:
1802 self.ext_export(cr, uid, child_ids, external_referential_ids, defaults, context) #so we export them
1803 else:
1804 return False
1805 else:
1806 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")
1807 return quantities, child_ids
1808
1809 def action_before_exporting(self, cr, uid, id, product_type, external_referential_ids=None, defaults=None, context=None):
1810 '''Hook to allow your external module to execute some code before exporting a product'''
1811 return True
1812
1813 #todo move this code to a generic module
1814 def get_last_update_date(self, cr, uid, product_read, context=None):
1815 """if a product have a depends on other object like bom for grouped product, or other product for configurable
1816 the date of last update should be based on the last update of the dependence object"""
1817 conn = context.get('conn_obj', False)
1818 last_updated_date = product_read['write_date'] or product_read['create_date'] or False
1819 if product_read['product_type'] == 'grouped':
1820 if context.get('mrp_is_installed', False):
1821 #TODO improve this part of code as the group product can be based on nan_product_pack
1822 cr.execute("select id, write_date, create_date from mrp_bom where product_id = %s", (product_read['id'],))
1823 read_bom = cr.dictfetchall()
1824 for bom in read_bom:
1825 last_updated_bom_date = bom['write_date'] or bom['create_date'] or False
1826 if last_updated_bom_date > last_updated_date:
1827 last_updated_date=last_updated_bom_date
1828 else:
1829 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")
1830 return last_updated_date
1831
1832
1833 def get_ordered_ids(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None):
1834 #TODO pass the shop better than the referentials
1835 dates_2_ids = []
1836 ids_2_dates = {}
1837 shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id'])
1838 if shop.last_products_export_date:
1839 last_exported_date = shop.last_products_export_date
1840 else:
1841 last_exported_date = False
1842 #strangely seems that on inherits structure, write_date/create_date are False for children
1843 #TODO check previous comment and check the write date on product template also for variant of product
1844 cr.execute("select id, write_date, create_date, product_type from product_product where id in %s", (tuple(ids),))
1845 read = cr.dictfetchall()
1846 ids = []
1847 context['force']=True
1848
1849 for product_read in read:
1850 last_updated_date = self.get_last_update_date(cr, uid, product_read, context=context)
1851 if last_exported_date and last_updated_date < last_exported_date:
1852 continue
1853 dates_2_ids += [(last_updated_date, product_read['id'])]
1854 ids_2_dates[product_read['id']] = last_updated_date
1855
1856 dates_2_ids.sort()
1857 ids = [x[1] for x in dates_2_ids]
1858
1859 return ids, ids_2_dates
1860
1861 def _ext_export_one(self, cr, uid, record_data, referential_id, defaults=None, context=None):
1862 res = super(product_product, self)._ext_export_one(
1863 cr, uid, record_data, referential_id, defaults=defaults, context=context)
1864
1865 self.ext_assign_links(
1866 cr, uid,
1867 record_data['id'],
1868 external_referential_ids=[referential_id],
1869 defaults=defaults,
1870 context=context)
1871
1872 return res
1873
1874 def ext_export(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None):
1875 #check if mrp is installed
1876 cr.execute('select * from ir_module_module where name=%s and state=%s', ('mrp','installed'))
1877 data_record = cr.fetchone()
1878 if data_record and 'mrp' in data_record:
1879 context['mrp_is_installed']=True
1880
1881 if context is None:
1882 context = {}
1883
1884 if defaults is None:
1885 defaults = {}
1886 #TODO Is external_referential_ids is still used?
1887 if external_referential_ids is None:
1888 external_referential_ids = []
1889
1890 result = {'create_ids':[], 'write_ids':[]}
1891 shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id'])
1892 context['external_referential_id'] = shop.referential_id.id
1893 #TODO It will be better if this check was done before
1894 #restrict export to only exportable products
1895 ids = self.search(cr, uid, [('id', 'in', ids), ('magento_exportable', '=', True)])
1896 if not ids:
1897 return result
1898
1899 if not context.get('force_export', False):
1900 ids, ids_2_dates = self.get_ordered_ids(cr, uid, ids, external_referential_ids, defaults, context)
1901
1902 #set the default_set_id in context and avoid extra request for each product upload
1903
1904 conn = context.get('conn_obj', False)
1905 attr_sets = conn.call('product_attribute_set.list')
1906 default_set_id = 1
1907 for attr_set in attr_sets:
1908 if attr_set['name'] == 'Default':
1909 default_set_id = attr_set['set_id']
1910 break
1911 context['default_set_id'] = default_set_id
1912
1913 context_dic = [context.copy()]
1914 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
1915 context_dic[0]['lang'] = shop.referential_id.default_lang_id.code
1916
1917 for storeview in shop.storeview_ids:
1918 if storeview.lang_id and storeview.lang_id.code != shop.referential_id.default_lang_id.code:
1919 context_dic += [context.copy()]
1920 context_dic[len(context_dic)-1].update({'storeview_code': storeview.code, 'lang': storeview.lang_id.code})
1921
1922 last_export_date = None
1923 try:
1924 for id in ids:
1925 child_ids = []
1926 product_type = self.read(cr, uid, id, ['product_type'])['product_type']
1927 if product_type == 'grouped': # lookup for Magento "grouped product"
1928 quantities, child_ids = self.action_before_exporting_grouped_product(cr, uid, id, external_referential_ids, defaults, context)
1929
1930 self.action_before_exporting(cr, uid, id, product_type, external_referential_ids, defaults, context=context)
1931
1932 for context_storeview in context_dic:
1933 temp_result = super(magerp_osv.magerp_osv, self).ext_export(cr, uid, [id], external_referential_ids, defaults, context_storeview)
1934 #TODO maybe refactor this part, did we need to assign and make the link for every store?
1935 if child_ids:
1936 self.ext_product_assign(cr, uid, 'grouped', id, child_ids, quantities=quantities, external_referential_ids=external_referential_ids, defaults=defaults, context=context_storeview)
1937 if not context.get('force_export'):
1938 last_export_date = ids_2_dates[id]
1939
1940 result['create_ids'] += temp_result['create_ids']
1941 result['write_ids'] += temp_result['write_ids']
1942 finally:
1943 if last_export_date is not None:
1944 self.pool.get('sale.shop').write(
1945 cr, uid, context['shop_id'], {'last_products_export_date': last_export_date}, context=context)
1946 return result
1947
1948 def try_ext_update(self, cr, uid, data, conn, method, oe_id, external_id, ir_model_data_id, create_method, context=None):
1949 if context is None: context = {}
1950 if context.get('storeview_code', False):
1951 return conn.call(method, [external_id, data, context.get('storeview_code', False)])
1952 else:
1953 return conn.call(method, [external_id, data])
1954
1955 def ext_update(self, cr, uid, data, conn, method, oe_id, external_id, ir_model_data_id, create_method, context=None):
1956 product = self.browse(cr, uid, oe_id)
1957 sku = self.product_to_sku(cr, uid, product)
1958 return super(magerp_osv.magerp_osv, self).ext_update(cr, uid, data, conn, method, oe_id, sku, ir_model_data_id, create_method, context)
1959>>>>>>> MERGE-SOURCE
13471960
1348 def _prepare_inventory_magento_vals(self, cr, uid, product, stock, shop,1961 def _prepare_inventory_magento_vals(self, cr, uid, product, stock, shop,
1349 context=None):1962 context=None):
@@ -1380,6 +1993,10 @@
1380 #TODO get also the list of product which the option mag_manage_stock have changed1993 #TODO get also the list of product which the option mag_manage_stock have changed
1381 #This can be base on the group_fields that can try tle last write date of a group of fields1994 #This can be base on the group_fields that can try tle last write date of a group of fields
1382 if context is None: context = {}1995 if context is None: context = {}
1996<<<<<<< TREE
1997=======
1998 logger = logging.getLogger('ext synchro')
1999>>>>>>> MERGE-SOURCE
13832000
1384 shop = external_session.sync_from_object2001 shop = external_session.sync_from_object
13852002
@@ -1400,6 +2017,7 @@
1400 cr, uid, stock_product_ids, context=location_ctx)2017 cr, uid, stock_product_ids, context=location_ctx)
14012018
1402 for product in products:2019 for product in products:
2020<<<<<<< TREE
1403 self._export_inventory(cr, uid, external_session, product, stock, context=location_ctx)2021 self._export_inventory(cr, uid, external_session, product, stock, context=location_ctx)
1404 return True2022 return True
14052023
@@ -1424,6 +2042,30 @@
1424 # ol_catalog_product.update2042 # ol_catalog_product.update
1425 def ext_update_link_data(self, cr, uid, external_session, resources, mapping=None, mapping_id=None, context=None):2043 def ext_update_link_data(self, cr, uid, external_session, resources, mapping=None, mapping_id=None, context=None):
1426 for resource_id, resource in resources.items():2044 for resource_id, resource in resources.items():
2045=======
2046 mag_product_id = self.oeid_to_extid(
2047 cr, uid, product.id, referential.id, context=context)
2048 if not mag_product_id:
2049 continue # skip products which are not exported
2050 inventory_vals = self._prepare_inventory_magento_vals(
2051 cr, uid, product, stock, shop, context=location_ctx)
2052
2053 connection.call('product_stock.update',
2054 [mag_product_id, inventory_vals])
2055
2056 logger.info(
2057 "Successfully updated stock level at %s for product with SKU %s",
2058 inventory_vals.get('qty', 'N/A'),
2059 product.magento_sku
2060 )
2061 return True
2062
2063 def ext_assign_links(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None):
2064 """ Assign links of type up-sell, cross-sell, related """
2065 if isinstance(ids, (int, long)):
2066 ids = [ids]
2067 for product in self.browse(cr, uid, ids, context):
2068>>>>>>> MERGE-SOURCE
1427 for type_selection in self.pool.get('product.link').get_link_type_selection(cr, uid, context):2069 for type_selection in self.pool.get('product.link').get_link_type_selection(cr, uid, context):
1428 link_type = type_selection[0]2070 link_type = type_selection[0]
1429 position = {}2071 position = {}
@@ -1442,6 +2084,7 @@
1442 context = context or {}2084 context = context or {}
1443 position = position or {}2085 position = position or {}
1444 quantities = quantities or {}2086 quantities = quantities or {}
2087<<<<<<< TREE
14452088
14462089
1447 #Patch for magento api prototype2090 #Patch for magento api prototype
@@ -1493,6 +2136,83 @@
1493 'qty': quantities.get(c_ext_id, 1)}])2136 'qty': quantities.get(c_ext_id, 1)}])
1494 external_session.logger.info(("Successfully updated assignment of type %s of"2137 external_session.logger.info(("Successfully updated assignment of type %s of"
1495 "product %s to product %s") %(link_type, ext_parent_id, c_ext_id))2138 "product %s to product %s") %(link_type, ext_parent_id, c_ext_id))
2139=======
2140 external_referential_ids = external_referential_ids or []
2141 logger = logging.getLogger('ext assign')
2142 conn = context.get('conn_obj', False)
2143
2144 for ref_id in external_referential_ids:
2145 # ensure that the product to link is exported before assigning it,
2146 # export it if necessary
2147 ids_to_export = []
2148 for child_id in child_ids:
2149 if not self.oeid_to_extid(cr, uid, child_id, ref_id, context=context):
2150 ids_to_export.append(child_id)
2151 export_ctx = context.copy()
2152 export_ctx['force_export'] = True
2153 self.ext_export(
2154 cr, uid, ids_to_export, [ref_id], defaults=defaults, context=export_ctx)
2155
2156 ext_id = self.oeid_to_extid(
2157 cr, uid, parent_id, ref_id, context=context)
2158 if not ext_id:
2159 continue
2160
2161 # get the sku of the products already assigned
2162 magento_args = [type, ext_id]
2163
2164 # magento existing children ids
2165 child_list = conn.call('product_link.list', magento_args)
2166 old_child_ext_ids = [x['product_id'] for x in child_list]
2167
2168 ext_id_to_remove = []
2169 ext_id_to_assign = []
2170 ext_id_to_update = []
2171
2172 # list of children setup on openerp
2173 new_child_ext_ids = dict([(self.oeid_to_extid(cr, uid, child_id, ref_id, context=context),
2174 child_id)
2175 for child_id in child_ids])
2176
2177 skus = dict([(p.id, p.magento_sku)
2178 for p in
2179 self.browse(
2180 cr, uid, child_ids + [parent_id], context=context)])
2181
2182 # compute the diff between openerp and magento
2183 for c_ext_id in old_child_ext_ids:
2184 if c_ext_id not in new_child_ext_ids:
2185 ext_id_to_remove.append(c_ext_id)
2186 for c_ext_id in new_child_ext_ids.keys():
2187 if c_ext_id in old_child_ext_ids:
2188 ext_id_to_update.append(c_ext_id)
2189 else:
2190 ext_id_to_assign.append(c_ext_id)
2191
2192 # calls to magento to delete, create or update the links
2193 for c_ext_id in ext_id_to_remove:
2194 # remove the product links that are no more setup on openerp
2195 conn.call('product_link.remove', magento_args + [c_ext_id])
2196 logger.info("Successfully removed assignment of type %s for product %s to product %s", type, skus[parent_id], c_ext_id)
2197 for child_ext_id in ext_id_to_assign:
2198 # assign new product links
2199 product_id = new_child_ext_ids[child_ext_id]
2200 conn.call('product_link.assign',
2201 magento_args +
2202 [child_ext_id,
2203 {'position': position.get(product_id, 0),
2204 'qty': quantities.get(product_id, 1)}])
2205 logger.info("Successfully assigned product %s to product %s with type %s", skus[parent_id], skus[product_id], type)
2206 for child_ext_id in ext_id_to_update:
2207 # update products links already assigned
2208 product_id = new_child_ext_ids[child_ext_id]
2209 conn.call('product_link.update',
2210 magento_args +
2211 [child_ext_id,
2212 {'position': position.get(product_id, 0),
2213 'qty': quantities.get(product_id, 1)}])
2214 logger.info("Successfully updated assignment of type %s of product %s to product %s", type, skus[parent_id], skus[product_id])
2215>>>>>>> MERGE-SOURCE
1496 return True2216 return True
14972217
1498 #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 generic2218 #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
@@ -1508,7 +2228,11 @@
15082228
1509 def _mag_import_product_links_type(self, cr, uid, product, link_type, external_session, context=None):2229 def _mag_import_product_links_type(self, cr, uid, product, link_type, external_session, context=None):
1510 if context is None: context = {}2230 if context is None: context = {}
2231<<<<<<< TREE
1511 conn = external_session.connection2232 conn = external_session.connection
2233=======
2234 logger = logging.getLogger('ext synchro')
2235>>>>>>> MERGE-SOURCE
1512 product_link_obj = self.pool.get('product.link')2236 product_link_obj = self.pool.get('product.link')
1513 selection_link_types = product_link_obj.get_link_type_selection(cr, uid, context)2237 selection_link_types = product_link_obj.get_link_type_selection(cr, uid, context)
1514 mag_product_id = self.get_extid(2238 mag_product_id = self.get_extid(
@@ -1520,8 +2244,13 @@
1520 try:2244 try:
1521 product_links = conn.call('product_link.list', [link_type, mag_product_id])2245 product_links = conn.call('product_link.list', [link_type, mag_product_id])
1522 except Exception, e:2246 except Exception, e:
2247<<<<<<< TREE
1523 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,))2248 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,))
1524 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,))2249 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,))
2250=======
2251 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,))
2252 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)
2253>>>>>>> MERGE-SOURCE
15252254
1526 for product_link in product_links:2255 for product_link in product_links:
1527 linked_product_id = self.get_or_create_oeid(2256 linked_product_id = self.get_or_create_oeid(
@@ -1545,7 +2274,11 @@
1545 product_link_obj.write(cr, uid, existing_link, link_data, context=context)2274 product_link_obj.write(cr, uid, existing_link, link_data, context=context)
1546 else:2275 else:
1547 product_link_obj.create(cr, uid, link_data, context=context)2276 product_link_obj.create(cr, uid, link_data, context=context)
2277<<<<<<< TREE
1548 conn.logger.info("Successfully imported product link of type %s on product %s to product %s" %(link_type, product.id, linked_product_id))2278 conn.logger.info("Successfully imported product link of type %s on product %s to product %s" %(link_type, product.id, linked_product_id))
2279=======
2280 logger.info("Successfully imported product link of type %s on product %s to product %s", link_type, product.id, linked_product_id)
2281>>>>>>> MERGE-SOURCE
1549 return True2282 return True
15502283
1551 def mag_import_product_links_types(self, cr, uid, ids, link_types, external_session, context=None):2284 def mag_import_product_links_types(self, cr, uid, ids, link_types, external_session, context=None):
15522285
=== modified file 'magentoerpconnect/product_images.py'
--- magentoerpconnect/product_images.py 2012-05-09 15:40:38 +0000
+++ magentoerpconnect/product_images.py 2012-07-06 14:53:18 +0000
@@ -23,7 +23,7 @@
23from osv import osv, fields23from osv import osv, fields
24import magerp_osv24import magerp_osv
25import mimetypes25import mimetypes
26import netsvc26import logging
27from tools.translate import _27from tools.translate import _
28import base6428import base64
2929
@@ -52,12 +52,12 @@
52 'thumbnail':lambda * a:True,52 'thumbnail':lambda * a:True,
53 'exclude':lambda * a:False53 'exclude':lambda * a:False
54 }54 }
55 55
56 def get_changed_ids(self, cr, uid, start_date=False):56 def get_changed_ids(self, cr, uid, start_date=False):
57 proxy = self.pool.get('product.images')57 proxy = self.pool.get('product.images')
58 domain = start_date and ['|', ('create_date', '>', start_date), ('write_date', '>', start_date)] or []58 domain = start_date and ['|', ('create_date', '>', start_date), ('write_date', '>', start_date)] or []
59 return proxy.search(cr, uid, domain)59 return proxy.search(cr, uid, domain)
60 60
61 def del_image_name(self, cr, uid, id, context=None):61 def del_image_name(self, cr, uid, id, context=None):
62 if context is None: context = {}62 if context is None: context = {}
63 image_ext_name_obj = self.pool.get('product.images.external.name')63 image_ext_name_obj = self.pool.get('product.images.external.name')
@@ -69,6 +69,13 @@
69 def update_remote_images(self, cr, uid, external_session, ids, context=None):69 def update_remote_images(self, cr, uid, external_session, ids, context=None):
70 if context is None:70 if context is None:
71 context = {}71 context = {}
72<<<<<<< TREE
73=======
74 logger = logging.getLogger('ext synchro')
75 conn = context.get('conn_obj', False)
76 if not conn:
77 return False
78>>>>>>> MERGE-SOURCE
7279
73 ir_model_data_obj = self.pool.get('ir.model.data')80 ir_model_data_obj = self.pool.get('ir.model.data')
7481
@@ -112,12 +119,13 @@
112 image_2_date[image['id']] = image['write_date'] or image['create_date']119 image_2_date[image['id']] = image['write_date'] or image['create_date']
113 list_date = date_2_image.keys()120 list_date = date_2_image.keys()
114 list_date.sort()121 list_date.sort()
115 122
116 ids = [date_2_image[date] for date in list_date]123 ids = [date_2_image[date] for date in list_date]
117124
118 while ids:125 while ids:
119 product_images = self.browse_w_order(cr, uid, ids[:1000], context=context)126 product_images = self.browse_w_order(cr, uid, ids[:1000], context=context)
120 for each in product_images:127 for each in product_images:
128<<<<<<< TREE
121 product_extid = each.product_id.get_extid(external_session.referential_id.id)129 product_extid = each.product_id.get_extid(external_session.referential_id.id)
122 if not product_extid:130 if not product_extid:
123 external_session.logger.info("The product %s do not exist on magento" %(each.product_id.default_code))131 external_session.logger.info("The product %s do not exist on magento" %(each.product_id.default_code))
@@ -163,10 +171,51 @@
163171
164172
165 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 past173 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
174=======
175 need_to_be_created = True
176 ext_file_name = each.oeid_to_extid(context['external_referential_id'])
177 if ext_file_name: #If update
178 try:
179 logger.info("Updating %s's image: %s", each.product_id.magento_sku, each.name)
180 result = update_image(ext_file_name, each)
181 logger.info("%s's image updated with sucess: %s", each.product_id.magento_sku, each.name)
182 need_to_be_created = False
183 except Exception, e:
184 logger.error(_("Error in connecting:%s"), e, exc_info=True)
185 if not "Fault 103" in str(e):
186 logger.error(_("Unknow error stop export"))
187 raise
188 else:
189 #If the image was deleded in magento, the external name is automatically deleded before trying to re-create the image in magento
190 model_data_ids = ir_model_data_obj.search(cr, uid, [('model', '=', self._name), ('res_id', '=', each.id), ('external_referential_id', '=', context['external_referential_id'])])
191 if model_data_ids and len(model_data_ids) > 0:
192 ir_model_data_obj.unlink(cr, uid, model_data_ids, context=context)
193 logger.error(_("The image don't exist in magento, try to create it"))
194 if need_to_be_created:
195 if each.product_id.magento_sku:
196 logger.info("Sending %s's image: %s", each.product_id.magento_sku, each.name)
197 result = conn.call('catalog_product_attribute_media.create',
198 [each.product_id.magento_sku,
199 {'file':{
200 'name':each.name,
201 'content': each.file,
202 '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',
203 }
204 }
205 ])
206 self.create_external_id_vals(cr, uid, each.id, result, context['external_referential_id'], context=context)
207 result = update_image(result, each)
208 logger.info("%s's image send with sucess: %s", each.product_id.magento_sku, each.name)
209 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
210>>>>>>> MERGE-SOURCE
166 self.pool.get('sale.shop').write(cr,uid,context['shop_id'],{'last_images_export_date':image_2_date[each.id]})211 self.pool.get('sale.shop').write(cr,uid,context['shop_id'],{'last_images_export_date':image_2_date[each.id]})
167 cr.commit()212 cr.commit()
168 ids = ids[1000:]213 ids = ids[1000:]
214<<<<<<< TREE
169 external_session.logger.info("still %s image to export" %len(ids))215 external_session.logger.info("still %s image to export" %len(ids))
216=======
217 logger.info("still %s image to export", len(ids))
218>>>>>>> MERGE-SOURCE
170 return True219 return True
171 220
172product_images()221product_images()
173222
=== modified file 'magentoerpconnect/sale.py'
--- magentoerpconnect/sale.py 2012-05-28 19:39:10 +0000
+++ magentoerpconnect/sale.py 2012-07-06 14:53:18 +0000
@@ -26,6 +26,7 @@
26import pooler26import pooler
27import magerp_osv27import magerp_osv
28import netsvc28import netsvc
29import logging
29from tools.translate import _30from tools.translate import _
30import string31import string
31import tools32import tools
@@ -56,6 +57,7 @@
5657
57class sale_shop(magerp_osv.magerp_osv):58class sale_shop(magerp_osv.magerp_osv):
58 _inherit = "sale.shop"59 _inherit = "sale.shop"
60<<<<<<< TREE
5961
60 @only_for_referential('magento')62 @only_for_referential('magento')
61 def init_context_before_exporting_resource(self, cr, uid, external_session, object_id, resource_name, context=None):63 def init_context_before_exporting_resource(self, cr, uid, external_session, object_id, resource_name, context=None):
@@ -73,6 +75,9 @@
7375
7476
7577
78=======
79
80>>>>>>> MERGE-SOURCE
76 def _get_exportable_product_ids(self, cr, uid, ids, name, args, context=None):81 def _get_exportable_product_ids(self, cr, uid, ids, name, args, context=None):
77 res = super(sale_shop, self)._get_exportable_product_ids(cr, uid, ids, name, args, context=None)82 res = super(sale_shop, self)._get_exportable_product_ids(cr, uid, ids, name, args, context=None)
78 for shop_id in res:83 for shop_id in res:
@@ -95,6 +100,10 @@
95100
96 def export_images(self, cr, uid, ids, context=None):101 def export_images(self, cr, uid, ids, context=None):
97 if context is None: context = {}102 if context is None: context = {}
103<<<<<<< TREE
104=======
105 logger = logging.getLogger('ext synchro')
106>>>>>>> MERGE-SOURCE
98 start_date = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)107 start_date = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
99 image_obj = self.pool.get('product.images')108 image_obj = self.pool.get('product.images')
100 for shop in self.browse(cr, uid, ids):109 for shop in self.browse(cr, uid, ids):
@@ -102,11 +111,19 @@
102 exportable_product_ids = self.read(cr, uid, shop.id, ['exportable_product_ids'], context=context)['exportable_product_ids']111 exportable_product_ids = self.read(cr, uid, shop.id, ['exportable_product_ids'], context=context)['exportable_product_ids']
103 res = self.pool.get('product.product').get_exportable_images(cr, uid, external_session, exportable_product_ids, context=context)112 res = self.pool.get('product.product').get_exportable_images(cr, uid, external_session, exportable_product_ids, context=context)
104 if res:113 if res:
114<<<<<<< TREE
105 _logger.info("Creating %s images", len(res['to_create']))115 _logger.info("Creating %s images", len(res['to_create']))
106 _logger.info("Updating %s images", len(res['to_update']))116 _logger.info("Updating %s images", len(res['to_update']))
107 image_obj.update_remote_images(cr, uid, external_session, res['to_update']+res['to_create'], context)117 image_obj.update_remote_images(cr, uid, external_session, res['to_update']+res['to_create'], context)
108 shop.write({'last_images_export_date': start_date})118 shop.write({'last_images_export_date': start_date})
119=======
120 logger.info("Creating %s images", len(res['to_create']))
121 logger.info("Updating %s images", len(res['to_update']))
122 image_obj.update_remote_images(cr, uid, res['to_update']+res['to_create'], context)
123 self.write(cr,uid,context['shop_id'],{'last_images_export_date': start_date})
124>>>>>>> MERGE-SOURCE
109 return True125 return True
126<<<<<<< TREE
110127
111 #TODO refactor the ay to export images128 #TODO refactor the ay to export images
112 #No time for doing it now so I just overwrite the generic function129 #No time for doing it now so I just overwrite the generic function
@@ -119,6 +136,11 @@
119 return super(sale_shop, self).export_resources(cr, uid, ids, resource_name, context=context)136 return super(sale_shop, self).export_resources(cr, uid, ids, resource_name, context=context)
120137
121 def _get_rootcategory(self, cr, uid, ids, name, value, context=None):138 def _get_rootcategory(self, cr, uid, ids, name, value, context=None):
139=======
140
141
142 def _get_rootcategory(self, cr, uid, ids, prop, unknow_none, context=None):
143>>>>>>> MERGE-SOURCE
122 res = {}144 res = {}
123 for shop in self.browse(cr, uid, ids, context):145 for shop in self.browse(cr, uid, ids, context):
124 if shop.root_category_id and shop.shop_group_id.referential_id:146 if shop.root_category_id and shop.shop_group_id.referential_id:
@@ -175,12 +197,66 @@
175 'allow_magento_notification': lambda * a: False,197 'allow_magento_notification': lambda * a: False,
176 }198 }
177199
200<<<<<<< TREE
178 def _get_magento_status(self, cr, uid, order, context=None):201 def _get_magento_status(self, cr, uid, order, context=None):
179 return ORDER_STATUS_MAPPING.get(order.state)202 return ORDER_STATUS_MAPPING.get(order.state)
180203
181 def update_shop_orders(self, cr, uid, external_session, order, ext_id, context=None):204 def update_shop_orders(self, cr, uid, external_session, order, ext_id, context=None):
182 if context is None: context = {}205 if context is None: context = {}
183 result = False206 result = False
207=======
208
209 def import_shop_orders(self, cr, uid, shop, defaults, context=None):
210 if context is None: context = {}
211 result = super(sale_shop, self).import_shop_orders(cr, uid, shop, defaults=defaults, context=context)
212 [result.setdefault(key, []) for key in ['create_ids', 'write_ids', 'unchanged_ids']]
213 if shop.magento_shop:
214 self.check_need_to_update(cr, uid, [shop.id], context=context)
215 for storeview in shop.storeview_ids:
216 magento_storeview_id = self.pool.get('magerp.storeviews').oeid_to_extid(cr, uid, storeview.id, shop.referential_id.id, context={})
217 ids_or_filter = {'store_id': {'eq': magento_storeview_id}, 'state': {'neq': 'canceled'}}
218 if shop.import_orders_from_date:
219 ids_or_filter.update({'created_at' : {'gt': shop.import_orders_from_date}})
220 nb_last_created_ids = SALE_ORDER_IMPORT_STEP
221 while nb_last_created_ids:
222 defaults['magento_storeview_id'] = storeview.id
223 ctx = context.copy()
224 ctx['ids_or_filter'] = ids_or_filter
225 resp = self.pool.get('sale.order').mage_import_base(cr, uid, context.get('conn_obj', False),
226 shop.referential_id.id, defaults=defaults,
227 context=ctx)
228 result['create_ids'] += resp.get('create_ids', [])
229 result['write_ids'] += resp.get('write_ids', [])
230 result['unchanged_ids'] += resp.get('unchanged_ids', [])
231 nb_last_created_ids = len(resp.get('create_ids', []) + resp.get('write_ids', []) + resp.get('unchanged_ids', []))
232 print nb_last_created_ids
233 return result
234
235 def check_need_to_update(self, cr, uid, ids, context=None):
236 """ This function will update the order status in OpenERP for
237 the order which are in the state 'need to update' """
238 so_obj = self.pool.get('sale.order')
239
240 for shop in self.browse(cr, uid, ids):
241 conn = shop.referential_id.external_connection()
242 # Update the state of orders in OERP that are in "need_to_update":True
243 # from the Magento's corresponding orders
244
245 # Get all need_to_update orders in OERP
246 orders_to_update = so_obj.search(
247 cr, uid,
248 [('need_to_update', '=', True),
249 ('shop_id', '=', shop.id)],
250 context=context)
251 so_obj.check_need_to_update(
252 cr, uid, orders_to_update, conn, context=context)
253 return False
254
255 def update_shop_orders(self, cr, uid, order, ext_id, context=None):
256 if context is None: context = {}
257 result = {}
258
259>>>>>>> MERGE-SOURCE
184 if order.shop_id.allow_magento_order_status_push:260 if order.shop_id.allow_magento_order_status_push:
185 sale_obj = self.pool.get('sale.order')261 sale_obj = self.pool.get('sale.order')
186 #status update:262 #status update:
@@ -252,6 +328,7 @@
252 cr.execute("ALTER TABLE account_invoice_line ALTER COLUMN discount TYPE numeric(16,6);")328 cr.execute("ALTER TABLE account_invoice_line ALTER COLUMN discount TYPE numeric(16,6);")
253 self.pool.get('sale.report').init(cr)329 self.pool.get('sale.report').init(cr)
254 super(sale_order, self)._auto_init(cr, context)330 super(sale_order, self)._auto_init(cr, context)
331<<<<<<< TREE
255332
256#TODO reimplement the check on tva in a good way333#TODO reimplement the check on tva in a good way
257# # Adds vat number (country code+magento vat) if base_vat module is installed and Magento sends customer_taxvat334# # Adds vat number (country code+magento vat) if base_vat module is installed and Magento sends customer_taxvat
@@ -296,6 +373,389 @@
296 vals['paid'] = True373 vals['paid'] = True
297 vals['amount'] = float(payment_info['amount_paid'])374 vals['amount'] = float(payment_info['amount_paid'])
298 return vals375 return vals
376=======
377
378 def get_order_addresses(self, cr, uid, referential_id, data_record, context=None):
379 partner_obj = self.pool.get('res.partner')
380 partner_address_obj = self.pool.get('res.partner.address')
381 res = {}
382
383 # Magento allows to create a sale order
384 # without register as a user
385 is_guest_order = bool(int(data_record.get('customer_is_guest', 0)))
386
387 # for a guest order or when magento
388 # does not provide customer_id on a normal order
389 # (it happens magento inconsistencies are common)
390 if (is_guest_order or
391 (data_record.get('website_id') and
392 not data_record.get('customer_id'))):
393
394 website_obj = self.pool.get('external.shop.group')
395 oerp_website_id = website_obj.extid_to_oeid(
396 cr, uid, data_record['website_id'], referential_id, context=context)
397
398 # first, try to find an already bound partner
399 # with same mail for same website
400 partner_id = partner_obj.search_magento_partner(
401 cr, uid,
402 data_record['customer_email'],
403 oerp_website_id,
404 is_bound=True, # search only for partners already bound
405 context=context)
406
407 # if we have found one, we "fix" the data_record
408 # with the magento customer id
409 if partner_id:
410 ext_customer_id = partner_obj.oeid_to_extid(
411 cr, uid, partner_id, referential_id, context=context)
412 data_record['customer_id'] = ext_customer_id
413
414 # no bound partner matching
415 # means that we have to consider it as a guest order
416 else:
417 is_guest_order = True
418
419 # if we do not have a customer_id, the sale order
420 # is a guest sale order, so we cannot link the customer
421 if is_guest_order:
422 # when we import a guest sale order, we create the partner
423 # on the fly and we do not bind it ir.model.data
424
425 # as we do not have a customer data record in the sale order
426 # data record, we manually populate one from the magento
427 # sale order record and import it with the standard mappings
428 address = data_record['billing_address']
429
430 customer_record = {
431 'firstname': address['firstname'],
432 'middlename': address['middlename'],
433 'lastname': address['lastname'],
434 'prefix': address['prefix'],
435 'suffix': address.get('suffix', False),
436 'email': data_record.get('customer_email', False),
437 'taxvat': data_record.get('customer_taxvat', False),
438 'group_id': data_record.get('customer_group_id', False),
439 'gender': data_record.get('customer_gender', False),
440 'store_id': data_record['store_id'],
441 'created_at': data_record['created_at'],
442 'updated_at': False,
443 'created_in': False,
444 'dob': data_record.get('customer_dob', False),
445 'website_id': data_record.get('website_id', False),
446 }
447 partner_defaults = {'is_magento_guest': True}
448 partner_id = partner_obj.ext_import_unbound(
449 cr, uid, customer_record, referential_id,
450 defaults=partner_defaults, context=context)
451 else:
452 # always update the customer when importing an order
453 imp_ctx = dict(context)
454 imp_ctx['id'] = data_record['customer_id']
455 partner_obj.get_external_data(
456 cr, uid,
457 context.get('conn_obj'),
458 referential_id,
459 defaults={},
460 context=imp_ctx)
461 partner_id = partner_obj.extid_to_oeid(
462 cr, uid, data_record['customer_id'], referential_id)
463
464 # update the address book of the customer, this addresses
465 # will be available in the partner form and the searches
466 partner_obj.import_magento_address_book(
467 cr, uid, partner_id, referential_id, context=context)
468
469 # The addresses of the sale order are imported as active=false
470 # so they are linked with the sale order but they are not displayed
471 # in the customer form and the searches.
472
473 # We import the addresses of the sale order as Active = False
474 # so they will be available in the documents generated as the
475 # sale order or the picking, but they won't be available on
476 # the partner form or the searches. Too many adresses would
477 # be displayed.
478 # They are never synchronized,
479 # we keep the revision of the sale order
480 # For the orders which are from guests, we let the addresses
481 # as active because they doesn't have an address book.
482 addresses_defaults = {'partner_id': partner_id,
483 'email': data_record.get('customer_email', False),
484 'active': is_guest_order,
485 'is_magento_order_address': True}
486 # We import the addresses as unbound becauses Magento is not able to
487 # give us an ID when the address is created during the order.
488 # It gives an empty id, a 0 or worse, a wrong id.
489 billing_address = data_record['billing_address'].copy()
490 # remove customer_id because we force it in the defaults
491 # it avoid to try to import the partner by customer_id
492 billing_address.pop('customer_id', False)
493 billing_id = partner_address_obj.ext_import_unbound(
494 cr, uid, billing_address,
495 referential_id, defaults=addresses_defaults,
496 context=context)
497
498 shipping_id = False
499 if data_record['shipping_address']:
500 shipping_address = data_record['shipping_address'].copy()
501 # remove customer_id because we force it in the defaults
502 # it avoid to try to import the partner by customer_id
503 shipping_address.pop('customer_id', False)
504 shipping_id = partner_address_obj.ext_import_unbound(
505 cr, uid, shipping_address,
506 referential_id, defaults=addresses_defaults,
507 context=context)
508
509 # default addresses ids for the sale order
510 res['partner_id'] = partner_id
511 res['partner_order_id'] = res['partner_invoice_id'] = billing_id
512 res['partner_shipping_id'] = shipping_id or billing_id
513
514 if data_record.get('customer_taxvat'):
515 partner_obj.add_magento_vat_number(
516 cr, uid, partner_id,
517 data_record['customer_taxvat'],
518 data_record['billing_address'].get('country_id'),
519 context=context)
520 return res
521
522 def add_order_extra_line(self, cr, uid, res, data_record, ext_field, product_ref, defaults, context=None):
523 """ Add or substract amount on order as a separate line item with single quantity for each type of amounts like :
524 shipping, cash on delivery, discount, gift certificates...
525
526 @param res: dict of the order to create
527 @param data_record: full data dict of the order
528 @param ext_field: name of the field in data_record where the amount of the extra lineis stored
529 @param product_ref: tuple with module and xml_id (module, xml_id) of the product to use for the extra line
530
531 Optional arguments in context:
532 sign: multiply the amount with the sign to add or substract it from the sale order
533 ext_tax_field: name of the field in data_record where the tax amount is stored
534 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
535 """
536 if context is None: context = {}
537 model_data_obj = self.pool.get('ir.model.data')
538 sign = 'sign' in context and context['sign'] or 1
539 ext_tax_field = 'ext_tax_field' in context and context['ext_tax_field'] or None
540 ext_code_field = 'ext_code_field' in context and context['ext_code_field'] or None
541
542 model, product_id = model_data_obj.get_object_reference(cr, uid, *product_ref)
543 product = self.pool.get('product.product').browse(cr, uid, product_id, context)
544 is_tax_included = context.get('price_is_tax_included', False)
545 amount = float(data_record[ext_field]) * sign
546 name = product.name
547 if ext_code_field and data_record.get(ext_code_field, False):
548 name = "%s [%s]" % (name, data_record[ext_code_field])
549
550 if is_tax_included:
551 price_unit = float(amount) + float(data_record[ext_tax_field])
552 else:
553 price_unit = float(amount)
554
555 extra_line = {
556 'product_id': product.id,
557 'name': name,
558 'product_uom': product.uom_id.id,
559 'product_uom_qty': 1,
560 'price_unit': price_unit,
561 }
562
563 if not res.get('order_line'):
564 res['order_line'] = []
565
566 if context.get('use_external_tax'):
567 # get the tax computed by the external system
568 tax_vat = abs(float(data_record[ext_tax_field]) / amount)
569 line_tax_id = self.pool.get('account.tax').get_tax_from_rate(cr, uid, tax_vat, context.get('is_tax_included'), context=context)
570 extra_line['tax_id'] = [(6, 0, line_tax_id)]
571 else:
572 # compute the taxes, apply fiscal positions, default values and so on
573 extra_line = self.pool.get('sale.order.line').play_sale_order_line_onchange(cr, uid, extra_line, res, res['order_line'], defaults, context=context)
574 res['order_line'].append((0, 0, extra_line))
575
576 return res
577
578 def add_order_shipping(self, cr, uid, res, external_referential_id, data_record, defaults, context=None):
579 if context is None: context = {}
580 if data_record.get('shipping_amount', False) and float(data_record.get('shipping_amount', False)) > 0:
581 ctx = context.copy()
582 ctx.update({
583 'ext_tax_field': 'shipping_tax_amount',
584 })
585 product_ref = ('base_sale_multichannels', 'product_product_shipping')
586 res = self.add_order_extra_line(cr, uid, res, data_record, 'shipping_amount', product_ref, defaults, ctx)
587 return res
588
589 def add_gift_certificates(self, cr, uid, res, external_referential_id, data_record, defaults, context=None):
590 if context is None: context = {}
591 if data_record.get('giftcert_amount', False) and float(data_record.get('giftcert_amount', False)) > 0:
592 ctx = context.copy()
593 ctx.update({
594 'ext_code_field': 'giftcert_code',
595 'sign': -1,
596 })
597 product_ref = ('magentoerpconnect', 'product_product_gift')
598 res = self.add_order_extra_line(cr, uid, res, data_record, 'giftcert_amount', product_ref, defaults, ctx)
599 return res
600
601 def add_discount(self, cr, uid, res, external_referential_id, data_record, defaults, context=None):
602 #TODO fix me rev 476
603 #if data_record.get('discount_amount', False) and float(data_record.get('discount_amount', False)) < 0:
604 # ctx = context.copy()
605 # ctx.update({
606 # 'ext_code_field': 'coupon_code',
607 # })
608 # product_ref = ('magentoerpconnect', 'product_product_discount')
609 # res = self.add_order_extra_line(cr, uid, res, data_record, 'discount_amount', product_ref, defaults, ctx)
610 return res
611
612 def add_cash_on_delivery(self, cr, uid, res, external_referential_id, data_record, defaults, context=None):
613 if context is None: context = {}
614 if data_record.get('cod_fee', False) and float(data_record.get('cod_fee', False)) > 0:
615 ctx = context.copy()
616 ctx.update({
617 'ext_tax_field': 'cod_tax_amount',
618 })
619 product_ref = ('magentoerpconnect', 'product_product_cash_on_delivery')
620 res = self.add_order_extra_line(cr, uid, res, data_record, 'cod_fee', product_ref, defaults, ctx)
621 return res
622
623 def convert_extdata_into_oedata(self, cr, uid, external_data, external_referential_id, parent_data=None, defaults=None, context=None):
624 res = super(sale_order, self).convert_extdata_into_oedata(cr, uid, external_data, external_referential_id, parent_data=parent_data, defaults=defaults, context=context)
625 res=res[0]
626 external_data = external_data[0]
627 res = self.add_order_shipping(cr, uid, res, external_referential_id, external_data, defaults, context)
628 res = self.add_gift_certificates(cr, uid, res, external_referential_id, external_data, defaults, context)
629 res = self.add_discount(cr, uid, res, external_referential_id, external_data, defaults, context)
630 res = self.add_cash_on_delivery(cr, uid, res, external_referential_id, external_data, defaults, context)
631 return [res]
632
633 def _merge_sub_items(self, cr, uid, product_type, top_item, child_items, context=None):
634 """
635 Manage the sub items of the magento sale order lines. A top item contains one
636 or many child_items. For some product types, we want to merge them in the main
637 item, or keep them as order line.
638
639 A list may be returned to add many items (ie to keep all child_items as items.
640
641 :param top_item: main item (bundle, configurable)
642 :param child_items: list of childs of the top item
643 :return: item or list of items
644 """
645 if product_type == 'configurable':
646 item = top_item.copy()
647 # For configurable product all information regarding the price is in the configurable item
648 # In the child a lot of information is empty, but contains the right sku and product_id
649 # So the real product_id and the sku and the name have to be extracted from the child
650 for field in ['sku', 'product_id', 'name']:
651 item[field] = child_items[0][field]
652 return item
653 return top_item
654
655 def data_record_filter(self, cr, uid, data_record, context=None):
656 child_items = {} # key is the parent item id
657 top_items = []
658
659 # Group the childs with their parent
660 for item in data_record['items']:
661 if item.get('parent_item_id'):
662 child_items.setdefault(item['parent_item_id'], []).append(item)
663 else:
664 top_items.append(item)
665
666 all_items = []
667 for top_item in top_items:
668 if top_item['item_id'] in child_items:
669 item_modified = self._merge_sub_items(cr, uid,
670 top_item['product_type'],
671 top_item,
672 child_items[top_item['item_id']],
673 context=context)
674 if not isinstance(item_modified, list):
675 item_modified = [item_modified]
676 all_items.extend(item_modified)
677 else:
678 all_items.append(top_item)
679
680 data_record['items'] = all_items
681 return data_record
682
683 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):
684 if context is None: context = {}
685 if data_record.get('items', False):
686 data_record = self.data_record_filter(cr, uid, data_record, context=context)
687 #TODO refactor this code regarding the new feature of sub-mapping in base_external_referential
688 if not context.get('one_by_one', False):
689 # we fix the website_id when it is empty because we need it to
690 # find the correct partner (based on email + website_id)
691 # website is based on the store_id which is:
692 # website m2o -> store
693 if not data_record.get('website_id') and data_record.get('store_id'):
694 store_obj = self.pool.get('magerp.storeviews')
695 store_id = store_obj.extid_to_oeid(
696 cr, uid, data_record['store_id'], external_referential_id)
697 store = store_obj.browse(cr, uid, store_id, context=context)
698 data_record['website_id'] = store.website_id.oeid_to_extid(
699 external_referential_id=external_referential_id, context=context)
700
701 defaults.update(self.get_order_addresses(
702 cr, uid, external_referential_id, data_record, context=context))
703 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)
704
705 #Move me in a mapping
706 if not context.get('one_by_one', False):
707 if data_record.get('status_history', False) and len(data_record['status_history']) > 0:
708 res['date_order'] = data_record['status_history'][len(data_record['status_history'])-1]['created_at']
709 return res
710
711 def _parse_external_payment(self, cr, uid, order_data, context=None):
712 """
713 Parse the external order data and return if the sale order
714 has been paid and the amount to pay or to be paid
715
716 :param dict order_data: payment information of the magento sale
717 order
718 :return: tuple where :
719 - first item indicates if the payment has been done (True or False)
720 - second item represents the amount paid or to be paid
721 """
722 paid = amount = False
723 payment_info = order_data.get('payment')
724 if payment_info:
725 amount = False
726 if payment_info.get('amount_paid', False):
727 amount = payment_info.get('amount_paid', False)
728 paid = True
729 elif payment_info.get('amount_ordered', False):
730 amount = payment_info.get('amount_ordered', False)
731 return paid, amount
732
733 def create_payments(self, cr, uid, order_id, data_record, context=None):
734 if context is None:
735 context = {}
736
737 if 'Magento' in context.get('external_referential_type', ''):
738 payment_info = data_record.get('payment')
739 paid, amount = self._parse_external_payment(
740 cr, uid, data_record, context=context)
741 if paid:
742 order = self.pool.get('sale.order').browse(
743 cr, uid, order_id, context)
744 self.generate_payment_with_pay_code(
745 cr, uid,
746 payment_info['method'],
747 order.partner_id.id,
748 float(amount),
749 "mag_" + payment_info['payment_id'],
750 "mag_" + data_record['increment_id'],
751 order.date_order,
752 paid,
753 context=context)
754 else:
755 paid = super(sale_order, self).create_payments(
756 cr, uid, order_id, data_record, context=context)
757 return paid
758>>>>>>> MERGE-SOURCE
299759
300 def _chain_cancel_orders(self, cr, uid, external_id, external_referential_id, defaults=None, context=None):760 def _chain_cancel_orders(self, cr, uid, external_id, external_referential_id, defaults=None, context=None):
301 """ Get all the chain of edited orders (an edited order is canceled on Magento)761 """ Get all the chain of edited orders (an edited order is canceled on Magento)
@@ -304,6 +764,10 @@
304 """764 """
305 if context is None:765 if context is None:
306 context = {}766 context = {}
767<<<<<<< TREE
768=======
769 logger = logging.getLogger('ext synchro')
770>>>>>>> MERGE-SOURCE
307 conn = context.get('conn_obj', False)771 conn = context.get('conn_obj', False)
308 parent_list = []772 parent_list = []
309 # get all parents orders (to cancel) of the sale orders773 # get all parents orders (to cancel) of the sale orders
@@ -319,7 +783,11 @@
319 try:783 try:
320 wf_service.trg_validate(uid, 'sale.order', canceled_order_id, 'cancel', cr)784 wf_service.trg_validate(uid, 'sale.order', canceled_order_id, 'cancel', cr)
321 self.log(cr, uid, canceled_order_id, "order %s canceled when updated from external system" % (canceled_order_id,))785 self.log(cr, uid, canceled_order_id, "order %s canceled when updated from external system" % (canceled_order_id,))
786<<<<<<< TREE
322 _logger.info("Order %s canceled when updated from external system because it has been replaced by a new one", canceled_order_id)787 _logger.info("Order %s canceled when updated from external system because it has been replaced by a new one", canceled_order_id)
788=======
789 logger.info("Order %s canceled when updated from external system because it has been replaced by a new one", canceled_order_id)
790>>>>>>> MERGE-SOURCE
323 except osv.except_osv, e:791 except osv.except_osv, e:
324 #TODO: generic reporting of errors in magentoerpconnect792 #TODO: generic reporting of errors in magentoerpconnect
325 # except if the sale order has been confirmed for example, we cannot cancel the order793 # except if the sale order has been confirmed for example, we cannot cancel the order
@@ -342,6 +810,7 @@
342 'priority': '2'810 'priority': '2'
343 })811 })
344812
813<<<<<<< TREE
345#NEW FEATURE814#NEW FEATURE
346815
347#TODO reimplement chain cancel orders816#TODO reimplement chain cancel orders
@@ -433,6 +902,118 @@
433902
434 @only_for_referential('magento')903 @only_for_referential('magento')
435 def _check_need_to_update_single(self, cr, uid, external_session, order, context=None):904 def _check_need_to_update_single(self, cr, uid, external_session, order, context=None):
905=======
906 def _ext_import_one(self, cr, uid, external_id, vals, external_data, referential_id, defaults=None, context=None):
907 """
908 Inherit the method to flag the order to "Imported" on Magento right after the importation
909 Before the import, check if the order is already imported and in a such case, skip the import
910 and flag "imported" on Magento.
911 """
912 if context is None: context = {}
913 if not (context.get('external_referential_type', False) and 'Magento' in context['external_referential_type']):
914 return super(sale_order, self)._ext_import_one(
915 cr, uid, external_id, vals, external_data, referential_id, defaults=defaults, context=context)
916
917 res = False, False
918 if not self.extid_to_existing_oeid(cr, uid, external_id, referential_id, context=context):
919 res = super(sale_order, self)._ext_import_one(
920 cr, uid, external_id, vals, external_data, referential_id, defaults=defaults, context=context)
921
922 if any(res):
923 # if a created order has a relation_parent_real_id,
924 # the new one replaces the original, so we have to cancel the old ones
925 if external_data.get('relation_parent_real_id', False):
926 self._chain_cancel_orders(cr, uid, external_id, referential_id, defaults=defaults, context=context)
927
928 return res
929
930 def _ext_import_one_cr(self, cr, uid, external_data, referential_id, defaults=None, context=None):
931 """ Import one external resource, with cursor management, open a new cursor
932 which is commited on each import
933
934 This method can be inherited to do an action which have to be done after
935 that the imported resource is commited in database.
936
937 @param dict external_data: vals of the external resource before conversion
938 @param external_referential_id: external referential id from where we import the resource
939 @param defaults: defaults value for fields which are not in vals
940 @return: tuple created id / updated id
941 """
942
943 cid, wid = super(sale_order, self)._ext_import_one_cr(
944 cr, uid, external_data, referential_id, defaults=defaults, context=context)
945
946 if (cid or wid and
947 (context.get('external_referential_type') and
948 'Magento' in context['external_referential_type'])):
949 ext_id = self.oeid_to_extid(cr, uid, cid or wid, referential_id,
950 context=context)
951 # set the "imported" flag to true on Magento
952 self.ext_set_order_imported(cr, uid, ext_id, referential_id, context=context)
953 return cid, wid
954
955 def ext_set_order_imported(self, cr, uid, external_id, external_referential_id, context=None):
956 if context is None:
957 context = {}
958 logger = logging.getLogger('ext synchro')
959 conn = context.get('conn_obj', False)
960 conn.call('sales_order.done', [external_id])
961 logger.info("Successfully set the imported flag on Magento on sale order %s", external_id)
962 return True
963
964 def mage_import_base(self, cr, uid, conn, external_referential_id, defaults=None, context=None):
965 """ Inherited method for Sales orders in order to import only order not flagged as "imported" on Magento
966 """
967 if context is None:
968 context = {}
969 if not 'ids_or_filter' in context.keys():
970 context['ids_or_filter'] = []
971 result = {'create_ids': [], 'write_ids': []}
972
973 # returns the non already imported order (limit returns the n first orders)
974 order_retrieve_params = {
975 'imported': False,
976 'limit': SALE_ORDER_IMPORT_STEP,
977 'filters': context['ids_or_filter'],
978 }
979 ext_order_ids = conn.call('sales_order.search', [order_retrieve_params])
980 result = self._import_orders(
981 cr, uid, conn, ext_order_ids, external_referential_id, defaults=defaults, context=context)
982 return result
983
984 def _import_orders(self, cr, uid, conn, external_ids, referential_id, defaults=None, context=None):
985 if context is None:
986 context = {}
987
988 logger = logging.getLogger('ext synchro')
989 mapping_id = self.pool.get('external.mapping').search(
990 cr, uid,
991 [('model', '=', self._name),
992 ('referential_id', '=', referential_id)],
993 context=context)
994
995 context = dict(context)
996 # we will need the connection to set the flag to "imported" on magento after each order import
997 context['conn_obj'] = conn
998 # use the external log for the orders import
999 context['use_external_log'] = True
1000 order_ids_filtred = []
1001 unchanged_ids = []
1002 for ext_order_id in external_ids:
1003 existing_id = self.extid_to_existing_oeid(cr, uid, ext_order_id, referential_id, context=context)
1004 if existing_id:
1005 unchanged_ids.append(existing_id)
1006 logger.info("the order %s already exist in OpenERP", ext_order_id)
1007 self.ext_set_order_imported(cr, uid, ext_order_id, referential_id, context=context)
1008 else:
1009 order_ids_filtred.append({'increment_id' : ext_order_id})
1010 result = self.mage_import_one_by_one(
1011 cr, uid, conn, referential_id, mapping_id[0], order_ids_filtred, defaults, context)
1012 result['unchanged_ids'] = unchanged_ids
1013 return result
1014
1015 def _check_need_to_update_single(self, cr, uid, order, conn, context=None):
1016>>>>>>> MERGE-SOURCE
436 """1017 """
437 For one order, check on Magento if it has been paid since last1018 For one order, check on Magento if it has been paid since last
438 check. If so, it will launch the defined flow based on the1019 check. If so, it will launch the defined flow based on the
@@ -535,6 +1116,7 @@
5351116
536 return created1117 return created
5371118
1119<<<<<<< TREE
538########################################################################################################################1120########################################################################################################################
539#1121#
540# CODE THAT CLEAN MAGENTO DATA BEFORE IMPORTING IT THE BEST WILL BE TO REFACTOR MAGENTO API1122# CODE THAT CLEAN MAGENTO DATA BEFORE IMPORTING IT THE BEST WILL BE TO REFACTOR MAGENTO API
@@ -632,6 +1214,18 @@
632 resource['shipping_address']['customer_id'] = resource['customer_id']1214 resource['shipping_address']['customer_id'] = resource['customer_id']
633 return resource1215 return resource
6341216
1217=======
1218 def retry_import(self, cr, uid, id, ext_id, external_referential_id, defaults=None, context=None):
1219 """ When we import again a previously failed import"""
1220 conn = self.pool.get('external.referential').external_connection(
1221 cr, uid, external_referential_id)
1222 res = self._import_orders(
1223 cr, uid, conn, [ext_id], external_referential_id, defaults=defaults, context=context)
1224 if any(res.values()):
1225 return True
1226 return False
1227
1228>>>>>>> MERGE-SOURCE
635sale_order()1229sale_order()
6361230
6371231
6381232
=== modified file 'magentoerpconnect/sale_view.xml'
--- magentoerpconnect/sale_view.xml 2012-05-11 15:14:05 +0000
+++ magentoerpconnect/sale_view.xml 2012-07-06 14:53:18 +0000
@@ -55,6 +55,25 @@
55 </field>55 </field>
56 </record>56 </record>
5757
58<<<<<<< TREE
59=======
60 <record id="magerp_view_shop_auto_import_form" model="ir.ui.view">
61 <field name="name">magerp_view_shop_auto_import_form</field>
62 <field name="model">sale.shop</field>
63 <field name="type">form</field>
64 <field name="inherit_id" ref="base_sale_multichannels.base_sale_multichannels_view_shop_form"/>
65 <field name="arch" type="xml">
66 <xpath expr="/form/notebook" position="inside">
67 <page string="Magento Information" attrs="{'invisible': [('magento_shop','=',False)]}">
68 <field name="magento_shop" />
69 <field name="allow_magento_order_status_push" />
70 <field name="allow_magento_notification"/>
71 </page>
72 </xpath>
73 </field>
74 </record>
75
76>>>>>>> MERGE-SOURCE
58 <record id="base_sale_multichannel_view_order_form_magento" model="ir.ui.view">77 <record id="base_sale_multichannel_view_order_form_magento" model="ir.ui.view">
59 <field name="name">base_sale_multichannel_view_order_form.magento</field>78 <field name="name">base_sale_multichannel_view_order_form.magento</field>
60 <field name="model">sale.order</field>79 <field name="model">sale.order</field>
6180
=== modified file 'magentoerpconnect/settings/1.3.2.4/external.mapping.template.csv'
--- magentoerpconnect/settings/1.3.2.4/external.mapping.template.csv 2012-03-27 09:52:57 +0000
+++ magentoerpconnect/settings/1.3.2.4/external.mapping.template.csv 2012-07-06 14:53:18 +0000
@@ -10,5 +10,5 @@
10"magento_1324_attr","magento1324","model_magerp_product_attributes","ol_catalog_product_attribute.list",,,,,"attribute_id"10"magento_1324_attr","magento1324","model_magerp_product_attributes","ol_catalog_product_attribute.list",,,,,"attribute_id"
11"magento_1324_prd","magento1324","product.model_product_product","catalog_product.list","catalog_product.info","ol_catalog_product.update","ol_catalog_product.create",,"product_id"11"magento_1324_prd","magento1324","product.model_product_product","catalog_product.list","catalog_product.info","ol_catalog_product.update","ol_catalog_product.create",,"product_id"
12"magento_1324_cst_grp","magento1324","base.model_res_partner_category","ol_customer_groups.list",,,,,"customer_group_id"12"magento_1324_cst_grp","magento1324","base.model_res_partner_category","ol_customer_groups.list",,,,,"customer_group_id"
13"magento_1324_prt_adr","magento1324","base.model_res_partner_address","ol_customer_address.list","ol_customer_address.info",,,,"customer_address_id"13"magento_1324_prt_adr","magento1324","base.model_res_partner_address","ol_customer_address.list","ol_customer_address.info",,,,"entity_id"
14"magento_1324_prt","magento1324","base.model_res_partner","customer.list","customer.info","customer.update",,,"customer_id"14"magento_1324_prt","magento1324","base.model_res_partner","customer.list","customer.info","customer.update",,,"customer_id"
1515
=== modified file 'magentoerpconnect/settings/1.3.2.4/external.mappinglines.template.csv'
--- magentoerpconnect/settings/1.3.2.4/external.mappinglines.template.csv 2012-05-24 19:50:22 +0000
+++ magentoerpconnect/settings/1.3.2.4/external.mappinglines.template.csv 2012-07-06 14:53:18 +0000
@@ -1,3 +1,4 @@
1<<<<<<< TREE
1"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"2"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"
2"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'])]"3"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'])]"
3"mag_1324_erp_s_code","magento1324","base_sale_multichannels.model_external_shop_group","code",,"in_out","function","unicode",,"result=[('code',ifield)]",4"mag_1324_erp_s_code","magento1324","base_sale_multichannels.model_external_shop_group","code",,"in_out","function","unicode",,"result=[('code',ifield)]",
@@ -19,6 +20,29 @@
19"mag_1324_erp_so_total_amount","magento1324","sale.model_sale_order","grand_total",,"in_out","function","float",,"result=[('ext_total_amount',str(ifield))]",20"mag_1324_erp_so_total_amount","magento1324","sale.model_sale_order","grand_total",,"in_out","function","float",,"result=[('ext_total_amount',str(ifield))]",
20"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))]",21"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))]",
21"mag_1324_erp_so_carrier_id","magento1324","sale.model_sale_order","shipping_method",,"in_out","function","unicode",,"if ifield:22"mag_1324_erp_so_carrier_id","magento1324","sale.model_sale_order","shipping_method",,"in_out","function","unicode",,"if ifield:
23=======
24id,type_id:id,model_id:id,external_field,field_id:id,type,evaluation_type,external_type,child_mapping_id:id,in_function,out_function
25mag_1324_erp_s_name,magento1324,base_sale_multichannels.model_external_shop_group,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
26mag_1324_erp_s_code,magento1324,base_sale_multichannels.model_external_shop_group,code,,in_out,function,unicode,,"result=[('code',ifield)]",
27mag_1324_erp_s_web,magento1324,base_sale_multichannels.model_external_shop_group,website_id,,in_out,function,int,,"result=[('website_id',ifield)]",
28mag_1324_erp_s_isa,magento1324,base_sale_multichannels.model_external_shop_group,is_default,,in_out,function,unicode,,"result=[('is_default',bool(eval(ifield)))]",
29mag_1324_erp_s_stord,magento1324,base_sale_multichannels.model_external_shop_group,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]",
30mag_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)]",
31mag_1324_erp_sv_name,magento1324,model_magerp_storeviews,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
32mag_1324_erp_sv_code,magento1324,model_magerp_storeviews,code,,in_out,function,unicode,,"result=[('code',ifield)]",
33mag_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))]",
34mag_1324_erp_sv_isa,magento1324,model_magerp_storeviews,is_active,,in_out,function,unicode,,"result=[('is_active',bool(eval(ifield)))]",
35mag_1324_erp_sv_stord,magento1324,model_magerp_storeviews,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]",
36mag_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))]",
37mag_1324_erp_st_name,magento1324,sale.model_sale_shop,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
38mag_1324_erp_st_gpid,magento1324,sale.model_sale_shop,group_id,,in_out,function,int,,"result=[('group_id',ifield)]",
39mag_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))]",
40mag_1324_erp_st_default_st,magento1324,sale.model_sale_shop,default_store_id,,in_out,function,int,,"result=[('default_storeview_integer_id',ifield)]",
41mag_1324_erp_st_root_categ,magento1324,sale.model_sale_shop,root_category_id,,in_out,function,int,,"result=[('root_category_id',ifield)]",
42mag_1324_erp_so_total_amount,magento1324,sale.model_sale_order,grand_total,,in_out,function,float,,"result=[('ext_total_amount',str(ifield))]",
43mag_1324_erp_so_name,magento1324,sale.model_sale_order,increment_id,,in_out,function,unicode,,"result=[('magento_incrementid',str(ifield)), ('name','mag_' + str(ifield))]",
44mag_1324_erp_so_carrier_id,magento1324,sale.model_sale_order,shipping_method,,in_out,function,unicode,,"if ifield:
45>>>>>>> MERGE-SOURCE
22 carrier_ids = self.pool.get('delivery.carrier').search(cr, uid, [('magento_code', '=', ifield)])46 carrier_ids = self.pool.get('delivery.carrier').search(cr, uid, [('magento_code', '=', ifield)])
23 if carrier_ids:47 if carrier_ids:
24 result=[('carrier_id', carrier_ids[0])]48 result=[('carrier_id', carrier_ids[0])]
@@ -41,16 +65,24 @@
41 clean = re.sub('\w:\w:|\w:\w+;', '', ifield)65 clean = re.sub('\w:\w:|\w:\w+;', '', ifield)
42 for each in clean.split('{'):66 for each in clean.split('{'):
43 if each.startswith('""label""'):67 if each.startswith('""label""'):
44 split_info = each.split(';') 68 split_info = each.split(';')
45 options_label.append('%s: %s [%s]' % (split_info[1], split_info[3], data['sku']))69 options_label.append('%s: %s [%s]' % (split_info[1], split_info[3], data['sku']))
46 70
47 result=[('notes', """".join(options_label).replace('""""', '\n').replace('""', ''))]71 result=[('notes', """".join(options_label).replace('""""', '\n').replace('""', ''))]
48",72",
73<<<<<<< TREE
49"mag_1324_erp_soline_pid","magento1324","sale.model_sale_order_line","product_id",,"in_out","function","unicode",,"context['alternative_key'] = data['sku']74"mag_1324_erp_soline_pid","magento1324","sale.model_sale_order_line","product_id",,"in_out","function","unicode",,"context['alternative_key'] = data['sku']
50result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, external_session, ifield, referential_id))]",75result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, external_session, ifield, referential_id))]",
51"mag_1324_erp_soline_uomqty","magento1324","sale.model_sale_order_line","qty_ordered",,"in_out","function","unicode",,"result=[('product_uom_qty',ifield)]",76"mag_1324_erp_soline_uomqty","magento1324","sale.model_sale_order_line","qty_ordered",,"in_out","function","unicode",,"result=[('product_uom_qty',ifield)]",
52"mag_1324_erp_soline_uosqty","magento1324","sale.model_sale_order_line","qty_ordered",,"in","function","unicode",,"result=[('product_uos_qty',ifield)]",77"mag_1324_erp_soline_uosqty","magento1324","sale.model_sale_order_line","qty_ordered",,"in","function","unicode",,"result=[('product_uos_qty',ifield)]",
53"mag_1324_erp_soline_price","magento1324","sale.model_sale_order_line","price",,"in","function","unicode",,"if context.get('price_is_tax_included', False): 78"mag_1324_erp_soline_price","magento1324","sale.model_sale_order_line","price",,"in","function","unicode",,"if context.get('price_is_tax_included', False):
79=======
80mag_1324_erp_soline_pid,magento1324,sale.model_sale_order_line,product_id,,in_out,function,unicode,,"context['alternative_key'] = data['sku']
81result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]",
82mag_1324_erp_soline_uomqty,magento1324,sale.model_sale_order_line,qty_ordered,,in_out,function,unicode,,"result=[('product_uom_qty',ifield)]",
83mag_1324_erp_soline_uosqty,magento1324,sale.model_sale_order_line,qty_ordered,,in,function,unicode,,"result=[('product_uos_qty',ifield)]",
84mag_1324_erp_soline_price,magento1324,sale.model_sale_order_line,price,,in,function,unicode,,"if context.get('price_is_tax_included', False):
85>>>>>>> MERGE-SOURCE
54 result=[('price_unit', (float(data['row_total']) + float(data['tax_amount']))/float(data['qty_ordered']))]86 result=[('price_unit', (float(data['row_total']) + float(data['tax_amount']))/float(data['qty_ordered']))]
55else:87else:
56 result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]",88 result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]",
@@ -60,15 +92,23 @@
60"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))])92"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))])
61parent_id = False93parent_id = False
62if record_id:94if record_id:
63 parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[])95 parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[])
64 parent_id=parent_rec.get('res_id',False)96 parent_id=parent_rec.get('res_id',False)
65result=[('magento_parent_id',ifield),('parent_id',parent_id)]","magento_parent_id = False97result=[('magento_parent_id',ifield),('parent_id',parent_id)]","magento_parent_id = False
66if record.get('parent_id',False):98if record.get('parent_id',False):
99<<<<<<< TREE
67 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], referential_id)100 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], referential_id)
68 if not magento_parent_id:101 if not magento_parent_id:
69 self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[referential_id],{},context=context)102 self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[referential_id],{},context=context)
70 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], referential_id)103 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], referential_id)
104=======
105 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id)
106 if not magento_parent_id:
107 self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[external_referential_id],{},context=context)
108 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id)
109>>>>>>> MERGE-SOURCE
71if magento_parent_id:110if magento_parent_id:
111<<<<<<< TREE
72 result = [('parent_id',magento_parent_id)]"112 result = [('parent_id',magento_parent_id)]"
73"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'])]"113"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'])]"
74"mag_1324_erp_procat_5","magento1324","product.model_product_category","description",,"in_out","function","unicode",,"result=[('description',ifield)]","result=[('description',record['description'])]"114"mag_1324_erp_procat_5","magento1324","product.model_product_category","description",,"in_out","function","unicode",,"result=[('description',ifield)]","result=[('description',record['description'])]"
@@ -76,6 +116,15 @@
76"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'])]"116"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'])]"
77"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'])]"117"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'])]"
78"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) :118"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) :
119=======
120 result = [('parent_id',magento_parent_id)]"
121mag_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'])]"
122mag_1324_erp_procat_5,magento1324,product.model_product_category,description,,in_out,function,unicode,,"result=[('description',ifield)]","result=[('description',record['description'])]"
123mag_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'])]"
124mag_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'])]"
125mag_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'])]"
126mag_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) :
127>>>>>>> MERGE-SOURCE
79 result=[('url_key',record['url_key'])]"128 result=[('url_key',record['url_key'])]"
80"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'])]"129"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'])]"
81"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'])]"130"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'])]"
@@ -97,30 +146,44 @@
97 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'sort_by', context=context)146 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'sort_by', context=context)
98else:147else:
99 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, 'None','sort_by', context=context)148 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, 'None','sort_by', context=context)
100result=[('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)149result=[('default_sort_by',att_id)]","options_obj = self.pool.get('magerp.product_category_attribute_options')
150cat_attr_option_id = record['default_sort_by']
151if cat_attr_option_id:
152 cat_attr_option_id = cat_attr_option_id[0]
153else:
154 cat_attr_option_id = options_obj._get_default_option(cr, uid, 'sort_by', 'None', context=context)
155
156cat_attr_option = options_obj.browse(cr, uid, cat_attr_option_id, context=context)
101result=[('default_sort_by', cat_attr_option.value)]"157result=[('default_sort_by', cat_attr_option.value)]"
102"mag_1324_erp_procat_14","magento1324","product.model_product_category","updated_at",,"in","function","unicode",,"result=[('magerp_stamp',ifield)]",158"mag_1324_erp_procat_14","magento1324","product.model_product_category","updated_at",,"in","function","unicode",,"result=[('magerp_stamp',ifield)]",
103"mag_1324_erp_procat_15","magento1324","product.model_product_category","image",,"in_out","function","unicode",,"image_binary = False159"mag_1324_erp_procat_15","magento1324","product.model_product_category","image",,"in_out","function","unicode",,"image_binary = False
104if ifield and not ifield=='None':160if ifield and not ifield=='None':
105 try:161 try:
106 image_binary = conn.call('ol_catalog_category_media.info', [int(data['category_id'])])162 image_binary = conn.call('ol_catalog_category_media.info', [int(data['category_id'])])
107 except Exception, e:163 except Exception, e:
108 print e164 print e
109 pass165 pass
110 if image_binary:166 if image_binary:
111 image_binary = base64.encodestring(base64.urlsafe_b64decode(image_binary[0]['image_data']))167 image_binary = base64.encodestring(base64.urlsafe_b64decode(image_binary[0]['image_data']))
112result=[('image_name',ifield),('image',image_binary)]","if record['image']:168result=[('image_name',ifield),('image',image_binary)]","if record['image']:
113 img = base64.decodestring(record['image'])169 img = base64.decodestring(record['image'])
114 img_bin_enc = base64.encodestring(img) 170 img_bin_enc = base64.encodestring(img)
115 conn.call('ol_catalog_category_media.create', [record['image_name'], img_bin_enc])171 conn.call('ol_catalog_category_media.create', [record['image_name'], img_bin_enc])
116 result = [('image',record['image_name'])]172 result = [('image',record['image_name'])]
117else:173else:
174<<<<<<< TREE
118 result=[]"175 result=[]"
119"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'])]"176"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'])]"
120"mag_1324_erp_procat_17","magento1324","product.model_product_category","page_layout",,"in_out","function","unicode",,"if ifield:177"mag_1324_erp_procat_17","magento1324","product.model_product_category","page_layout",,"in_out","function","unicode",,"if ifield:
178=======
179 result=[]"
180mag_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'])]"
181mag_1324_erp_procat_17,magento1324,product.model_product_category,page_layout,,in_out,function,unicode,,"if ifield:
182>>>>>>> MERGE-SOURCE
121 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'page_layout', context=context)183 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'page_layout', context=context)
122else:184else:
123 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, 'None','page_layout', context=context)185 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, 'None','page_layout', context=context)
186<<<<<<< TREE
124result=[('page_layout',att_id)]","result=[('page_layout', record['page_layout'][1] or '')]"187result=[('page_layout',att_id)]","result=[('page_layout', record['page_layout'][1] or '')]"
125"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'])]"188"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'])]"
126"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'])]"189"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'])]"
@@ -155,6 +218,43 @@
155"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'])]"218"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'])]"
156"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']))]"219"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']))]"
157"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) :220"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) :
221=======
222result=[('page_layout',att_id)]","page_layout = record['page_layout'] and record['page_layout'][1] or ''
223result=[('page_layout', page_layout)]"
224mag_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'])]"
225mag_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'])]"
226mag_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'])]"
227mag_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'])]"
228mag_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'])]"
229mag_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'])]"
230mag_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'])]"
231mag_1324_erp_attr_1,magento1324,model_magerp_product_attributes,attribute_code,,in_out,function,unicode,,"result=[('attribute_code', ifield)]","result=[('code', record['attribute_code'])]"
232mag_1324_erp_attr_2,magento1324,model_magerp_product_attributes,attribute_id,,in_out,function,int,,"result=[('magento_id', ifield)]",
233mag_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'])]"
234mag_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'])]"
235mag_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'])]"
236mag_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'])]"
237mag_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'])]"
238mag_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'])]"
239mag_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'])]"
240mag_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'])]"
241mag_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'])]"
242mag_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'])]"
243mag_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'])]"
244mag_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'])]"
245mag_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'])]"
246mag_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'])]"
247mag_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'])]"
248mag_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'])]"
249mag_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'])]"
250mag_1324_erp_attr_20,magento1324,model_magerp_product_attributes,position,,in_out,function,int,,"result=[('position', ifield)]","result=[('position', record['position'])]"
251mag_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'])]"
252mag_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'])]"
253mag_1324_erp_attr_23,magento1324,model_magerp_product_attributes,note,,in_out,function,unicode,,"result=[('note', ifield)]","result=[('note', record['note'])]"
254mag_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'])]"
255mag_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']))]"
256mag_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) :
257>>>>>>> MERGE-SOURCE
158 result=[('url_key',record['x_magerp_url_key'])]"258 result=[('url_key',record['x_magerp_url_key'])]"
159"mag_1324_erp_prd_2","magento1324","product.model_product_product","name",,"in_out","function","unicode",,"result = [('name',ifield)]","result = [('name',record['name'])]"259"mag_1324_erp_prd_2","magento1324","product.model_product_product","name",,"in_out","function","unicode",,"result = [('name',ifield)]","result = [('name',record['name'])]"
160"mag_1324_erp_prd_3","magento1324","product.model_product_product","description",,"in_out","function","unicode",,"result = [('description',ifield)]",260"mag_1324_erp_prd_3","magento1324","product.model_product_product","description",,"in_out","function","unicode",,"result = [('description',ifield)]",
@@ -164,13 +264,18 @@
164"mag_1324_erp_prd_7","magento1324","product.model_product_product","category_ids",,"in_out","function","list",,"categ_ids =[]264"mag_1324_erp_prd_7","magento1324","product.model_product_product","category_ids",,"in_out","function","list",,"categ_ids =[]
165if ifield and len(ifield) > 0:265if ifield and len(ifield) > 0:
166 for category_ids in ifield:266 for category_ids in ifield:
267<<<<<<< TREE
167 categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, external_session, category_ids, referential_id))268 categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, external_session, category_ids, referential_id))
269=======
270 categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, category_ids, external_referential_id, context=context))
271>>>>>>> MERGE-SOURCE
168 categ_id = categ_ids.pop()272 categ_id = categ_ids.pop()
169else:273else:
170 categ_id = self.pool.get('external.referential').browse(cr, uid, referential_id).default_pro_cat.id274 categ_id = self.pool.get('external.referential').browse(cr, uid, referential_id).default_pro_cat.id
171result = [('categ_id', categ_id), ('categ_ids',[(6, 0, categ_ids)])]","275result = [('categ_id', categ_id), ('categ_ids',[(6, 0, categ_ids)])]","
172cat_obj = self.pool.get('product.category')276cat_obj = self.pool.get('product.category')
173product = self.browse(cr, uid, record['id'])277product = self.browse(cr, uid, record['id'])
278<<<<<<< TREE
174categ_ids = [product.categ_id.id] + [categ.id for categ in product.categ_ids]279categ_ids = [product.categ_id.id] + [categ.id for categ in product.categ_ids]
175mag_categ_ids = []280mag_categ_ids = []
176for categ_id in categ_ids:281for categ_id in categ_ids:
@@ -186,6 +291,23 @@
186"mag_1324_erp_prd_11","magento1324","product.model_product_product","special_price",,"in_out","function","float",,"result = [('x_magerp_special_price',ifield)]",291"mag_1324_erp_prd_11","magento1324","product.model_product_product","special_price",,"in_out","function","float",,"result = [('x_magerp_special_price',ifield)]",
187"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"292"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"
188"mag_1324_erp_prd_13","magento1324","product.model_product_product","minimal_price",,"in_out","function","float",,"result = [('x_magerp_minimal_price',ifield)]","293"mag_1324_erp_prd_13","magento1324","product.model_product_product","minimal_price",,"in_out","function","float",,"result = [('x_magerp_minimal_price',ifield)]","
294=======
295categ_ids = [categ.id for categ in ([product.categ_id] + product.categ_ids) if categ.magento_exportable]
296mag_categ_ids = []
297for categ_id in categ_ids:
298 mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id)
299 if not mag_categ_id:
300 cat_obj.ext_export(cr, uid, [categ_id], [external_referential_id], context=context)
301 mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id)
302 mag_categ_ids.append(mag_categ_id)
303result=[('category_ids', mag_categ_ids)]"
304mag_1324_erp_prd_8,magento1324,product.model_product_product,price,,in_out,function,float,,"result=[('list_price',ifield)]",result=[]#map later
305mag_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)]"
306mag_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))]",
307mag_1324_erp_prd_11,magento1324,product.model_product_product,special_price,,in_out,function,float,,"result = [('x_magerp_special_price',ifield)]",
308mag_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
309mag_1324_erp_prd_13,magento1324,product.model_product_product,minimal_price,,in_out,function,float,,"result = [('x_magerp_minimal_price',ifield)]","
310>>>>>>> MERGE-SOURCE
189if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0:311if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0:
190 result = [('minimal_price',record['x_magerp_minimal_price'])]312 result = [('minimal_price',record['x_magerp_minimal_price'])]
191else:313else:
@@ -199,7 +321,11 @@
199 result = [('type_id','simple')]"321 result = [('type_id','simple')]"
200"mag_1324_erp_prd_15","magento1324","product.model_product_product","websites",,"in_out","function","list",,"websites_ids = []322"mag_1324_erp_prd_15","magento1324","product.model_product_product","websites",,"in_out","function","list",,"websites_ids = []
201for ext_id in ifield:323for ext_id in ifield:
324<<<<<<< TREE
202 websites_ids.append(self.pool.get('external.shop.group').extid_to_oeid(cr, uid, external_session, ext_id, context=context))325 websites_ids.append(self.pool.get('external.shop.group').extid_to_oeid(cr, uid, external_session, ext_id, context=context))
326=======
327 websites_ids.append(self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ext_id, external_referential_id, context=context))
328>>>>>>> MERGE-SOURCE
203329
204##### OPTION START, with this if the field websites of the product is empty the product is exported on every website330##### OPTION START, with this if the field websites of the product is empty the product is exported on every website
205all_oe_websites_ids = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', referential_id)])331all_oe_websites_ids = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', referential_id)])
@@ -217,6 +343,7 @@
217 ext_websites_ids.append(self.pool.get('external.shop.group').oeid_to_extid(cr, uid, oe_id, referential_id))343 ext_websites_ids.append(self.pool.get('external.shop.group').oeid_to_extid(cr, uid, oe_id, referential_id))
218344
219result=[('websites', ext_websites_ids)]"345result=[('websites', ext_websites_ids)]"
346<<<<<<< TREE
220"mag_1324_erp_prd_16","magento1324","product.model_product_product","has_options",,"in","function","unicode",,"result =[('x_magerp_has_options',ifield)]",347"mag_1324_erp_prd_16","magento1324","product.model_product_product","has_options",,"in","function","unicode",,"result =[('x_magerp_has_options',ifield)]",
221"magento_1324_cst_grp_1","magento1324","base.model_res_partner_category","customer_group_code",,"in","function","unicode",,"result=[('name',ifield)]",348"magento_1324_cst_grp_1","magento1324","base.model_res_partner_category","customer_group_code",,"in","function","unicode",,"result=[('name',ifield)]",
222"magento_1324_cst_grp_3","magento1324","base.model_res_partner_category","tax_class_id",,"in","function","int",,"result=[('tax_class_id',ifield)]",349"magento_1324_cst_grp_3","magento1324","base.model_res_partner_category","tax_class_id",,"in","function","int",,"result=[('tax_class_id',ifield)]",
@@ -225,17 +352,39 @@
225"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 ''))]",352"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 ''))]",
226"magento_1324_prt_adr_6","magento1324","base.model_res_partner_address","is_active",,"in_out","function","unicode",,"result=[('active',bool(eval(ifield)))]",353"magento_1324_prt_adr_6","magento1324","base.model_res_partner_address","is_active",,"in_out","function","unicode",,"result=[('active',bool(eval(ifield)))]",
227"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)])354"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)])
355=======
356mag_1324_erp_prd_16,magento1324,product.model_product_product,has_options,,in,function,unicode,,"result =[('x_magerp_has_options',ifield)]",
357magento_1324_cst_grp_1,magento1324,base.model_res_partner_category,customer_group_code,,in,function,unicode,,"result=[('name',ifield)]",
358magento_1324_cst_grp_3,magento1324,base.model_res_partner_category,tax_class_id,,in,function,int,,"result=[('tax_class_id',ifield)]",
359magento_1324_prt_adr_2,magento1324,base.model_res_partner_address,city,,in_out,function,unicode,,"result=[('city',ifield)]",
360magento_1324_prt_adr_3,magento1324,base.model_res_partner_address,fax,,in_out,function,unicode,,"result=[('fax',ifield)]",
361magento_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])
362if data.get('company'):
363 name = ""%s ; %s"" % (data['company'], name)
364result = [('name', name), ('firstname', ifield), ('lastname', data['lastname'])]",
365magento_1324_prt_adr_6,magento1324,base.model_res_partner_address,is_active,,in_out,function,unicode,,"result=[('active',bool(eval(ifield)))]",
366magento_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)])
367>>>>>>> MERGE-SOURCE
228if result and len(result)==1:368if result and len(result)==1:
229 result=[('country_id',result[0])]369 result=[('country_id',result[0])]
230else:370else:
231 result=[]371 result=[]
232",372",
373<<<<<<< TREE
233"magento_1324_prt_adr_8","magento1324","base.model_res_partner_address","street",,"in_out","function","unicode",,"if ifield:374"magento_1324_prt_adr_8","magento1324","base.model_res_partner_address","street",,"in_out","function","unicode",,"if ifield:
234 if len(ifield.split('\n')) ==2 :375 if len(ifield.split('\n')) ==2 :
235 result = [('street', ifield.split('\n')[0]) , ('street2', ifield.split('\n')[1])]376 result = [('street', ifield.split('\n')[0]) , ('street2', ifield.split('\n')[1])]
236 else :377 else :
237 result = [('street',ifield.replace('\\n',','))]378 result = [('street',ifield.replace('\\n',','))]
379=======
380magento_1324_prt_adr_8,magento1324,base.model_res_partner_address,street,,in_out,function,unicode,,"if ifield:
381 if len(ifield.split('\n')) ==2 :
382 result = [('street', ifield.split('\n')[0]) , ('street2', ifield.split('\n')[1])]
383 else :
384 result = [('street',ifield.replace('\\n',','))]
385>>>>>>> MERGE-SOURCE
238else:386else:
387<<<<<<< TREE
239 result = []",388 result = []",
240"magento_1324_prt_adr_9","magento1324","base.model_res_partner_address","postcode",,"in_out","function","unicode",,"result=[('zip',ifield)]",389"magento_1324_prt_adr_9","magento1324","base.model_res_partner_address","postcode",,"in_out","function","unicode",,"result=[('zip',ifield)]",
241"magento_1324_prt_adr_10","magento1324","base.model_res_partner_address","telephone",,"in_out","function","unicode",,"result=[('phone',ifield)]",390"magento_1324_prt_adr_10","magento1324","base.model_res_partner_address","telephone",,"in_out","function","unicode",,"result=[('phone',ifield)]",
@@ -245,16 +394,39 @@
245 result = [('state_id',result[0])]394 result = [('state_id',result[0])]
246 else:395 else:
247 result=[]396 result=[]
397=======
398 result = []",
399magento_1324_prt_adr_9,magento1324,base.model_res_partner_address,postcode,,in_out,function,unicode,,"result=[('zip',ifield)]",
400magento_1324_prt_adr_10,magento1324,base.model_res_partner_address,telephone,,in_out,function,unicode,,"result=[('phone',ifield)]",
401magento_1324_prt_adr_11,magento1324,base.model_res_partner_address,region,,in_out,function,unicode,,"if ifield:
402 result = self.pool.get('res.country.state').search(cr,uid,[('name','=ilike',ifield)])
403 if result and len(result)==1:
404 result = [('state_id',result[0])]
405 else:
406 result=[]
407>>>>>>> MERGE-SOURCE
248else:408else:
409<<<<<<< TREE
249 result=[]",410 result=[]",
250"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)411"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)
412=======
413 result=[]",
414magento_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)
415>>>>>>> MERGE-SOURCE
251if result:416if result:
252 result=[('partner_id',result)]417 result=[('partner_id',result)]
253else:418else:
419<<<<<<< TREE
254 result=[('partner_id',False)]",420 result=[('partner_id',False)]",
255"magento_1324_prt_adr_14","magento1324","base.model_res_partner_address","address_type",,"in_out","function","unicode",,"if ifield=='billing':421"magento_1324_prt_adr_14","magento1324","base.model_res_partner_address","address_type",,"in_out","function","unicode",,"if ifield=='billing':
256 result=[('type','invoice')]422 result=[('type','invoice')]
423=======
424 result=[('partner_id',False)]",
425magento_1324_prt_adr_14,magento1324,base.model_res_partner_address,address_type,,in_out,function,unicode,,"if ifield=='billing':
426 result=[('type','invoice')]
427>>>>>>> MERGE-SOURCE
257elif ifield=='shipping':428elif ifield=='shipping':
429<<<<<<< TREE
258 result=[('type','delivery')]430 result=[('type','delivery')]
259else:431else:
260 result=[]",432 result=[]",
@@ -276,15 +448,67 @@
276"magento_1324_prt_6","magento1324","base.model_res_partner","created_at",,"in_out","function","unicode",,"result=[('created_at',ifield)]",448"magento_1324_prt_6","magento1324","base.model_res_partner","created_at",,"in_out","function","unicode",,"result=[('created_at',ifield)]",
277"magento_1324_prt_7","magento1324","base.model_res_partner","updated_at",,"in_out","function","unicode",,"result=[('updated_at',ifield)]",449"magento_1324_prt_7","magento1324","base.model_res_partner","updated_at",,"in_out","function","unicode",,"result=[('updated_at',ifield)]",
278"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'])450"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'])
451=======
452 result=[('type','delivery')]
453else:
454 result=[]",
455magento_1324_prt_adr_15,magento1324,base.model_res_partner_address,email,,in_out,function,unicode,,"result = [('email', False)]
456if ifield:
457 result = [('email', ifield)]
458else:
459 partner_obj = self.pool.get('res.partner')
460 partner_id = partner_obj.extid_to_existing_oeid(cr, uid, data['customer_id'] ,external_referential_id)
461 if partner_id:
462 result = [('email', partner_obj.browse(cr, uid, partner_id).emailid)]",
463magento_1324_prt_adr_17,magento1324,base.model_res_partner_address,default_billing,,in_out,function,unicode,,"result = [('type', 'other')]
464if data.get('default_billing') and data.get('default_shipping'):
465 result = [('type', 'default')]
466elif data.get('default_billing'):
467 result = [('type', 'invoice')]
468elif data.get('default_shipping'):
469 result = [('type', 'delivery')]",
470magento_1324_prt_2,magento1324,base.model_res_partner,group_id,,in_out,function,int,,"if ifield:
471 result=self.pool.get('res.partner.category').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
472 if result:
473 result=[('group_id',result)]",
474magento_1324_prt_3,magento1324,base.model_res_partner,store_id,,in_out,function,int,,"if ifield:
475 result=self.pool.get('magerp.storeviews').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
476 if result:
477 store = self.pool.get('magerp.storeviews').browse(cr, uid, result)
478 lang = store.lang_id
479 result=[('store_id',result),('lang',lang and lang.code or False)]
480 if not data.get('website_id'):
481 result.append(('website_id', store.website_id.id))",
482magento_1324_prt_4,magento1324,base.model_res_partner,website_id,,in_out,function,int,,"if ifield:
483 result=self.pool.get('external.shop.group').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
484 if result:
485 result=[('website_id',result)]",
486magento_1324_prt_5,magento1324,base.model_res_partner,created_in,,in_out,function,unicode,,"result=[('created_in',ifield)]",
487magento_1324_prt_6,magento1324,base.model_res_partner,created_at,,in_out,function,unicode,,"result=[('created_at',ifield)]",
488magento_1324_prt_7,magento1324,base.model_res_partner,updated_at,,in_out,function,unicode,,"result=[('updated_at',ifield)]",
489magento_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'])
490>>>>>>> MERGE-SOURCE
279fn = add_id.address[0].firstname491fn = add_id.address[0].firstname
280ln = add_id.address[0].lastname492ln = add_id.address[0].lastname
281result=[('firstname', fn), ('lastname', ln)]"493result=[('firstname', fn), ('lastname', ln)]"
494<<<<<<< TREE
282"magento_1324_prt_10","magento1324","base.model_res_partner","email",,"in_out","function","unicode",,"result=[('emailid',ifield)]",495"magento_1324_prt_10","magento1324","base.model_res_partner","email",,"in_out","function","unicode",,"result=[('emailid',ifield)]",
283"magento_1324_prt_11","magento1324","base.model_res_partner","taxvat",,"in_out","function","unicode",,"if ifield:496"magento_1324_prt_11","magento1324","base.model_res_partner","taxvat",,"in_out","function","unicode",,"if ifield:
284 result=[('mag_vat',ifield)]497 result=[('mag_vat',ifield)]
498=======
499magento_1324_prt_10,magento1324,base.model_res_partner,email,,in_out,function,unicode,,"result=[('emailid',ifield)]",
500magento_1324_prt_11,magento1324,base.model_res_partner,taxvat,,in_out,function,unicode,,"if ifield:
501 result=[('mag_vat',ifield)]
502>>>>>>> MERGE-SOURCE
285else:503else:
504<<<<<<< TREE
286 result=[]",505 result=[]",
287"magento_1324_prt_12","magento1324","base.model_res_partner","dob",,"in_out","function","unicode",,"if ifield:506"magento_1324_prt_12","magento1324","base.model_res_partner","dob",,"in_out","function","unicode",,"if ifield:
288 result =[('mag_birthday',ifield[:10])]507 result =[('mag_birthday',ifield[:10])]
508=======
509 result=[]",
510magento_1324_prt_12,magento1324,base.model_res_partner,dob,,in_out,function,unicode,,"if ifield:
511 result =[('mag_birthday',ifield[:10])]
512>>>>>>> MERGE-SOURCE
289else:513else:
290 result=[]",514 result=[]",
291515
=== added directory 'magentoerpconnect/settings/1.4.0.0'
=== added file 'magentoerpconnect/settings/1.4.0.0/external.mapping.template.csv'
--- magentoerpconnect/settings/1.4.0.0/external.mapping.template.csv 1970-01-01 00:00:00 +0000
+++ magentoerpconnect/settings/1.4.0.0/external.mapping.template.csv 2012-07-06 14:53:18 +0000
@@ -0,0 +1,14 @@
1"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"
2"magento_1400_website","magento1400","base_sale_multichannels.model_external_shop_group","ol_websites.list",,,,,"website_id"
3"magento_1400_storeview","magento1400","model_magerp_storeviews","ol_storeviews.list",,,,,"store_id"
4"magento_1400_store","magento1400","sale.model_sale_shop","ol_groups.list",,,,,"group_id"
5"magento_1400_order","magento1400","sale.model_sale_order","sales_order.list","sales_order.info",,,,"increment_id"
6"magento_1400_order_line","magento1400","sale.model_sale_order_line",,,,,,"item_id"
7"magento_1400_pro_cat","magento1400","product.model_product_category","category.list","category.info","catalog_category.update","catalog_category.create",,"category_id"
8"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"
9"magento_1400_attr_set","magento1400","model_magerp_product_attribute_set","ol_catalog_product_attributeset.list",,,,,"attribute_set_id"
10"magento_1400_attr","magento1400","model_magerp_product_attributes","ol_catalog_product_attribute.list",,,,,"attribute_id"
11"magento_1400_prd","magento1400","product.model_product_product","catalog_product.list","catalog_product.info","ol_catalog_product.update","ol_catalog_product.create",,"product_id"
12"magento_1400_cst_grp","magento1400","base.model_res_partner_category","ol_customer_groups.list",,,,,"customer_group_id"
13"magento_1400_prt_adr","magento1400","base.model_res_partner_address","ol_customer_address.list","ol_customer_address.info",,,,"entity_id"
14"magento_1400_prt","magento1400","base.model_res_partner","customer.list","customer.info","customer.update",,,"customer_id"
015
=== added file 'magentoerpconnect/settings/1.4.0.0/external.mappinglines.template.csv'
--- magentoerpconnect/settings/1.4.0.0/external.mappinglines.template.csv 1970-01-01 00:00:00 +0000
+++ magentoerpconnect/settings/1.4.0.0/external.mappinglines.template.csv 2012-07-06 14:53:18 +0000
@@ -0,0 +1,321 @@
1id,type_id:id,model_id:id,external_field,field_id:id,type,evaluation_type,external_type,child_mapping_id:id,in_function,out_function
2mag_1400_erp_s_name,magento1400,base_sale_multichannels.model_external_shop_group,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
3mag_1400_erp_s_code,magento1400,base_sale_multichannels.model_external_shop_group,code,,in_out,function,unicode,,"result=[('code',ifield)]",
4mag_1400_erp_s_web,magento1400,base_sale_multichannels.model_external_shop_group,website_id,,in_out,function,int,,"result=[('website_id',ifield)]",
5mag_1400_erp_s_isa,magento1400,base_sale_multichannels.model_external_shop_group,is_default,,in_out,function,unicode,,"result=[('is_default',bool(eval(ifield)))]",
6mag_1400_erp_s_stord,magento1400,base_sale_multichannels.model_external_shop_group,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]",
7mag_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)]",
8mag_1400_erp_sv_name,magento1400,model_magerp_storeviews,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
9mag_1400_erp_sv_code,magento1400,model_magerp_storeviews,code,,in_out,function,unicode,,"result=[('code',ifield)]",
10mag_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))]",
11mag_1400_erp_sv_isa,magento1400,model_magerp_storeviews,is_active,,in_out,function,unicode,,"result=[('is_active',bool(eval(ifield)))]",
12mag_1400_erp_sv_stord,magento1400,model_magerp_storeviews,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]",
13mag_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))]",
14mag_1400_erp_st_name,magento1400,sale.model_sale_shop,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
15mag_1400_erp_st_gpid,magento1400,sale.model_sale_shop,group_id,,in_out,function,int,,"result=[('group_id',ifield)]",
16mag_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))]",
17mag_1400_erp_st_default_st,magento1400,sale.model_sale_shop,default_store_id,,in_out,function,int,,"result=[('default_storeview_integer_id',ifield)]",
18mag_1400_erp_st_root_categ,magento1400,sale.model_sale_shop,root_category_id,,in_out,function,int,,"result=[('root_category_id',ifield)]",
19mag_1400_erp_so_total_amount,magento1400,sale.model_sale_order,grand_total,,in_out,function,float,,"result=[('ext_total_amount',str(ifield))]",
20mag_1400_erp_so_name,magento1400,sale.model_sale_order,increment_id,,in_out,function,unicode,,"result=[('magento_incrementid',str(ifield)), ('name','mag_' + str(ifield))]",
21mag_1400_erp_so_carrier_id,magento1400,sale.model_sale_order,shipping_method,,in_out,function,unicode,,"if ifield:
22 carrier_ids = self.pool.get('delivery.carrier').search(cr, uid, [('magento_code', '=', ifield)])
23 if carrier_ids:
24 result=[('carrier_id', carrier_ids[0])]
25 else:
26 fake_partner_id = self.pool.get('res.partner').search(cr, uid, [])[0]
27 model_data_obj = self.pool.get('ir.model.data')
28 model, product_id = model_data_obj.get_object_reference(cr, uid, 'base_sale_multichannels', 'product_product_shipping')
29 carrier_id = self.pool.get('delivery.carrier').create(cr, uid, {'partner_id' : fake_partner_id, 'product_id' : product_id, 'name' : ifield, 'magento_code' : ifield})
30 result=[('carrier_id', carrier_id)]",
31mag_1400_erp_so_pay,magento1400,sale.model_sale_order,payment,,in_out,function,unicode,,"
32payments_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'}
33ifield=eval(ifield)
34result=[('order_policy', ifield['method'] in payments_mapping and payments_mapping[ifield['method']] or 'prepaid'), ('ext_payment_method', ifield['method'])]",
35mag_1400_erp_so_item,magento1400,sale.model_sale_order,items,sale.field_sale_order_order_line,in,sub-mapping,dict,magento_1400_order_line,,
36"mag_1400_erp_soline_name","magento1400","sale.model_sale_order_line","name",,"in_out","function","unicode",,"result=[('name', ifield)]
37",
38"mag_1400_erp_soline_note","magento1400","sale.model_sale_order_line","product_options",,"in","function","unicode",,"if ifield:
39 import re
40 options_label = []
41 clean = re.sub('\w:\w:|\w:\w+;', '', ifield)
42 for each in clean.split('{'):
43 if each.startswith('""label""'):
44 split_info = each.split(';')
45 options_label.append('%s: %s [%s]' % (split_info[1], split_info[3], data['sku']))
46
47 result=[('notes', """".join(options_label).replace('""""', '\n').replace('""', ''))]
48",
49mag_1400_erp_soline_pid,magento1400,sale.model_sale_order_line,product_id,,in_out,function,unicode,,"context['alternative_key'] = data['sku']
50result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]",
51mag_1400_erp_soline_uomqty,magento1400,sale.model_sale_order_line,qty_ordered,,in_out,function,unicode,,"result=[('product_uom_qty',ifield)]",
52mag_1400_erp_soline_uosqty,magento1400,sale.model_sale_order_line,qty_ordered,,in,function,unicode,,"result=[('product_uos_qty',ifield)]",
53mag_1400_erp_soline_price,magento1400,sale.model_sale_order_line,price,,in,function,unicode,,"if context.get('price_is_tax_included', False):
54 result=[('price_unit', (float(data['row_total']) + float(data['tax_amount']))/float(data['qty_ordered']))]
55else:
56 result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]",
57mag_1400_erp_soline_disc,magento1400,sale.model_sale_order_line,discount_amount,,in,function,float,,"if ifield:
58 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)]",
59mag_1400_erp_procat_2,magento1400,product.model_product_category,level,,in,function,int,,"result=[('sequence',ifield),('level',ifield)]",
60mag_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))])
61parent_id = False
62if record_id:
63 parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[])
64 parent_id=parent_rec.get('res_id',False)
65result=[('magento_parent_id',ifield),('parent_id',parent_id)]","magento_parent_id = False
66if record.get('parent_id',False):
67 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id)
68 if not magento_parent_id:
69 self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[external_referential_id],{},context=context)
70 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id)
71if magento_parent_id:
72 result = [('parent_id',magento_parent_id)]"
73mag_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'])]"
74mag_1400_erp_procat_5,magento1400,product.model_product_category,description,,in_out,function,unicode,,"result=[('description',ifield)]","result=[('description',record['description'])]"
75mag_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'])]"
76mag_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'])]"
77mag_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'])]"
78mag_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) :
79 result=[('url_key',record['url_key'])]"
80mag_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'])]"
81mag_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'])]"
82mag_1400_erp_procat_12,magento1400,product.model_product_category,available_sort_by,,in_out,function,list,,"attr_ids = []
83cat_attr_obj = self.pool.get('magerp.product_category_attribute_options')
84if ifield:
85 for val in ifield:
86 attr_ids.append(cat_attr_obj.get_create_option_id(cr, uid, val,'sort_by', context=context))
87 result=[('available_sort_by', [(6, 0, attr_ids)]), ('use_default_available_sort_by', False)]
88else:
89 result=[('use_default_available_sort_by', True)]","if record['use_default_available_sort_by']:
90 res = u''
91else:
92 res = []
93 for cat_attr_option in self.pool.get('magerp.product_category_attribute_options').browse(cr, uid, record['available_sort_by'], context=context):
94 res.append(cat_attr_option.value)
95 # comment out the following line if you can run the following SQL query on the Magento database:
96 # update eav_attribute set is_required = 0 where attribute_code = 'available_sort_by';
97 res = u''
98result=[('available_sort_by', res)]"
99mag_1400_erp_procat_13,magento1400,product.model_product_category,default_sort_by,,in_out,function,unicode,,"if ifield:
100 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'sort_by', context=context)
101else:
102 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','sort_by', context=context)
103result=[('default_sort_by',att_id)]","options_obj = self.pool.get('magerp.product_category_attribute_options')
104cat_attr_option_id = record['default_sort_by']
105if cat_attr_option_id:
106 cat_attr_option_id = cat_attr_option_id[0]
107else:
108 cat_attr_option_id = options_obj._get_default_option(cr, uid, 'sort_by', '', context=context)
109
110cat_attr_option = options_obj.browse(cr, uid, cat_attr_option_id, context=context)
111result=[('default_sort_by', cat_attr_option.value)]"
112mag_1400_erp_procat_14,magento1400,product.model_product_category,updated_at,,in,function,unicode,,"result=[('magerp_stamp',ifield)]",
113mag_1400_erp_procat_15,magento1400,product.model_product_category,image,,in_out,function,unicode,,"image_binary = False
114if ifield and not ifield=='None':
115 try:
116 image_binary = conn.call('ol_catalog_category_media.info', [int(data['category_id'])])
117 except Exception, e:
118 print e
119 pass
120 if image_binary:
121 image_binary = base64.encodestring(base64.urlsafe_b64decode(image_binary[0]['image_data']))
122result=[('image_name',ifield),('image',image_binary)]","if record['image']:
123 img = base64.decodestring(record['image'])
124 img_bin_enc = base64.encodestring(img)
125 conn.call('ol_catalog_category_media.create', [record['image_name'], img_bin_enc])
126 result = [('image',record['image_name'])]
127else:
128 result=[]"
129mag_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'])]"
130mag_1400_erp_procat_17,magento1400,product.model_product_category,page_layout,,in_out,function,unicode,,"if ifield:
131 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'page_layout', context=context)
132else:
133 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','page_layout', context=context)
134result=[('page_layout',att_id)]","page_layout = record['page_layout'] and record['page_layout'][1] or ''
135result=[('page_layout', page_layout)]"
136mag_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'])]"
137mag_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'])]"
138mag_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'])]"
139mag_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'])]"
140mag_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'])]"
141mag_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'])]"
142mag_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'])]"
143mag_1400_erp_attr_1,magento1400,model_magerp_product_attributes,attribute_code,,in_out,function,unicode,,"result=[('attribute_code', ifield)]","result=[('code', record['attribute_code'])]"
144mag_1400_erp_attr_2,magento1400,model_magerp_product_attributes,attribute_id,,in_out,function,int,,"result=[('magento_id', ifield)]",
145mag_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'])]"
146mag_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'])]"
147mag_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'])]"
148mag_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'])]"
149mag_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'])]"
150mag_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'])]"
151mag_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'])]"
152mag_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'])]"
153mag_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'])]"
154mag_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'])]"
155mag_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'])]"
156mag_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'])]"
157mag_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'])]"
158mag_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'])]"
159mag_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'])]"
160mag_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'])]"
161mag_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'])]"
162mag_1400_erp_attr_20,magento1400,model_magerp_product_attributes,position,,in_out,function,int,,"result=[('position', ifield)]","result=[('position', record['position'])]"
163mag_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'])]"
164mag_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'])]"
165mag_1400_erp_attr_23,magento1400,model_magerp_product_attributes,note,,in_out,function,unicode,,"result=[('note', ifield)]","result=[('note', record['note'])]"
166mag_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'])]"
167mag_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']))]"
168mag_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) :
169 result=[('url_key',record['x_magerp_url_key'])]"
170mag_1400_erp_prd_2,magento1400,product.model_product_product,name,,in_out,function,unicode,,"result = [('name',ifield)]","result = [('name',record['name'])]"
171mag_1400_erp_prd_3,magento1400,product.model_product_product,description,,in_out,function,unicode,,"result = [('description',ifield)]",
172mag_1400_erp_prd_4,magento1400,product.model_product_product,short_description,,in_out,function,unicode,,"result = [('description_sale',ifield)]",
173mag_1400_erp_prd_5,magento1400,product.model_product_product,sku,,in_out,function,unicode,,"result = [('magento_sku',ifield), ('default_code',ifield)]",
174mag_1400_erp_prd_6,magento1400,product.model_product_product,weight,,in_out,function,float,,"result = [('weight',ifield)]","result = [('weight',record['weight'] or 0)]"
175mag_1400_erp_prd_7,magento1400,product.model_product_product,category_ids,,in_out,function,list,,"categ_ids =[]
176if ifield and len(ifield) > 0:
177 for category_ids in ifield:
178 categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, category_ids, external_referential_id, context=context))
179 categ_id = categ_ids.pop()
180else:
181 categ_id = self.pool.get('external.referential').browse(cr, uid, external_referential_id).default_pro_cat.id
182result = [('categ_id', categ_id), ('categ_ids',[(6, 0, categ_ids)])]","
183cat_obj = self.pool.get('product.category')
184product = self.browse(cr, uid, record['id'])
185categ_ids = [categ.id for categ in ([product.categ_id] + product.categ_ids) if categ.magento_exportable]
186mag_categ_ids = []
187for categ_id in categ_ids:
188 mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id)
189 if not mag_categ_id:
190 cat_obj.ext_export(cr, uid, [categ_id], [external_referential_id], context=context)
191 mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id)
192 mag_categ_ids.append(mag_categ_id)
193result=[('category_ids', mag_categ_ids)]"
194mag_1400_erp_prd_8,magento1400,product.model_product_product,price,,in_out,function,float,,"result=[('list_price',ifield)]",result=[]#map later
195mag_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)]"
196mag_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))]",
197mag_1400_erp_prd_11,magento1400,product.model_product_product,special_price,,in_out,function,float,,"result = [('x_magerp_special_price',ifield)]",
198mag_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
199mag_1400_erp_prd_13,magento1400,product.model_product_product,minimal_price,,in_out,function,float,,"result = [('x_magerp_minimal_price',ifield)]","
200if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0:
201 result = [('minimal_price',record['x_magerp_minimal_price'])]
202else:
203 result = [('minimal_price',False)]"
204mag_1400_erp_prd_14,magento1400,product.model_product_product,type_id,,in_out,function,unicode,,"if ifield:
205 product_type_ids = self.pool.get('magerp.product_product_type').search(cr,uid,[('product_type','=',ifield)])
206 if product_type_ids:
207 result = [('product_type',ifield)]","if 'product_type' in record and record['product_type']:
208 result = [('type_id',record['product_type'])]
209else:
210 result = [('type_id','simple')]"
211mag_1400_erp_prd_15,magento1400,product.model_product_product,websites,,in_out,function,list,,"websites_ids = []
212for ext_id in ifield:
213 websites_ids.append(self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ext_id, external_referential_id, context=context))
214
215##### OPTION START, with this if the field websites of the product is empty the product is exported on every website
216all_oe_websites_ids = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)])
217if set(websites_ids) == set(all_oe_websites_ids):
218 websites_ids =[]
219##### OPTION END
220
221result=[('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
222if not record['websites_ids']:
223 record['websites_ids'] = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)])
224##### OPTION END
225
226ext_websites_ids = []
227for oe_id in record['websites_ids']:
228 ext_websites_ids.append(self.pool.get('external.shop.group').oeid_to_extid(cr, uid, oe_id, external_referential_id))
229
230result=[('websites', ext_websites_ids)]"
231mag_1400_erp_prd_16,magento1400,product.model_product_product,has_options,,in,function,unicode,,"result =[('x_magerp_has_options',ifield)]",
232magento_1400_cst_grp_1,magento1400,base.model_res_partner_category,customer_group_code,,in,function,unicode,,"result=[('name',ifield)]",
233magento_1400_cst_grp_3,magento1400,base.model_res_partner_category,tax_class_id,,in,function,int,,"result=[('tax_class_id',ifield)]",
234magento_1400_prt_adr_2,magento1400,base.model_res_partner_address,city,,in_out,function,unicode,,"result=[('city',ifield)]",
235magento_1400_prt_adr_3,magento1400,base.model_res_partner_address,fax,,in_out,function,unicode,,"result=[('fax',ifield)]",
236magento_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])
237if data.get('company'):
238 name = ""%s ; %s"" % (data['company'], name)
239result = [('name', name), ('firstname', ifield), ('lastname', data['lastname'])]",
240magento_1400_prt_adr_6,magento1400,base.model_res_partner_address,is_active,,in_out,function,unicode,,"result=[('active',bool(eval(ifield)))]",
241magento_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)])
242if result and len(result)==1:
243 result=[('country_id',result[0])]
244else:
245 result=[]
246",
247magento_1400_prt_adr_8,magento1400,base.model_res_partner_address,street,,in_out,function,unicode,,"if ifield:
248 if len(ifield.split('\n')) ==2 :
249 result = [('street', ifield.split('\n')[0]) , ('street2', ifield.split('\n')[1])]
250 else :
251 result = [('street',ifield.replace('\\n',','))]
252else:
253 result = []",
254magento_1400_prt_adr_9,magento1400,base.model_res_partner_address,postcode,,in_out,function,unicode,,"result=[('zip',ifield)]",
255magento_1400_prt_adr_10,magento1400,base.model_res_partner_address,telephone,,in_out,function,unicode,,"result=[('phone',ifield)]",
256magento_1400_prt_adr_11,magento1400,base.model_res_partner_address,region,,in_out,function,unicode,,"if ifield:
257 result = self.pool.get('res.country.state').search(cr,uid,[('name','=ilike',ifield)])
258 if result and len(result)==1:
259 result = [('state_id',result[0])]
260 else:
261 result=[]
262else:
263 result=[]",
264magento_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)
265if result:
266 result=[('partner_id',result)]
267else:
268 result=[('partner_id',False)]",
269magento_1400_prt_adr_14,magento1400,base.model_res_partner_address,address_type,,in_out,function,unicode,,"if ifield=='billing':
270 result=[('type','invoice')]
271elif ifield=='shipping':
272 result=[('type','delivery')]
273else:
274 result=[]",
275magento_1400_prt_adr_15,magento1400,base.model_res_partner_address,email,,in_out,function,unicode,,"result = [('email', False)]
276if ifield:
277 result = [('email', ifield)]
278else:
279 partner_obj = self.pool.get('res.partner')
280 partner_id = partner_obj.extid_to_existing_oeid(cr, uid, data['customer_id'] ,external_referential_id)
281 if partner_id:
282 result = [('email', partner_obj.browse(cr, uid, partner_id).emailid)]",
283magento_1400_prt_adr_17,magento1400,base.model_res_partner_address,default_billing,,in_out,function,unicode,,"result = [('type', 'other')]
284if data.get('default_billing') and data.get('default_shipping'):
285 result = [('type', 'default')]
286elif data.get('default_billing'):
287 result = [('type', 'invoice')]
288elif data.get('default_shipping'):
289 result = [('type', 'delivery')]",
290magento_1400_prt_2,magento1400,base.model_res_partner,group_id,,in_out,function,int,,"if ifield:
291 result=self.pool.get('res.partner.category').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
292 if result:
293 result=[('group_id',result)]",
294magento_1400_prt_3,magento1400,base.model_res_partner,store_id,,in_out,function,int,,"if ifield:
295 result=self.pool.get('magerp.storeviews').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
296 if result:
297 store = self.pool.get('magerp.storeviews').browse(cr, uid, result)
298 lang = store.lang_id
299 result=[('store_id',result),('lang',lang and lang.code or False)]
300 if not data.get('website_id'):
301 result.append(('website_id', store.website_id.id))",
302magento_1400_prt_4,magento1400,base.model_res_partner,website_id,,in_out,function,int,,"if ifield:
303 result=self.pool.get('external.shop.group').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
304 if result:
305 result=[('website_id',result)]",
306magento_1400_prt_5,magento1400,base.model_res_partner,created_in,,in_out,function,unicode,,"result=[('created_in',ifield)]",
307magento_1400_prt_6,magento1400,base.model_res_partner,created_at,,in_out,function,unicode,,"result=[('created_at',ifield)]",
308magento_1400_prt_7,magento1400,base.model_res_partner,updated_at,,in_out,function,unicode,,"result=[('updated_at',ifield)]",
309magento_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'])
310fn = add_id.address[0].firstname
311ln = add_id.address[0].lastname
312result=[('firstname', fn), ('lastname', ln)]"
313magento_1400_prt_10,magento1400,base.model_res_partner,email,,in_out,function,unicode,,"result=[('emailid',ifield)]",
314magento_1400_prt_11,magento1400,base.model_res_partner,taxvat,,in_out,function,unicode,,"if ifield:
315 result=[('mag_vat',ifield)]
316else:
317 result=[]",
318magento_1400_prt_12,magento1400,base.model_res_partner,dob,,in_out,function,unicode,,"if ifield:
319 result =[('mag_birthday',ifield[:10])]
320else:
321 result=[]",
0322
=== added file 'magentoerpconnect/settings/1.4.0.0/external.referential.type.csv'
--- magentoerpconnect/settings/1.4.0.0/external.referential.type.csv 1970-01-01 00:00:00 +0000
+++ magentoerpconnect/settings/1.4.0.0/external.referential.type.csv 2012-07-06 14:53:18 +0000
@@ -0,0 +1,2 @@
1"id","name"
2"magento1400","Magento Version 1.4.0.0+"
03
=== added directory 'magentoerpconnect/settings/1.4.2.0'
=== added file 'magentoerpconnect/settings/1.4.2.0/external.mapping.template.csv'
--- magentoerpconnect/settings/1.4.2.0/external.mapping.template.csv 1970-01-01 00:00:00 +0000
+++ magentoerpconnect/settings/1.4.2.0/external.mapping.template.csv 2012-07-06 14:53:18 +0000
@@ -0,0 +1,14 @@
1"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"
2"magento_1420_website","magento1420","base_sale_multichannels.model_external_shop_group","ol_websites.list",,,,,"website_id"
3"magento_1420_storeview","magento1420","model_magerp_storeviews","ol_storeviews.list",,,,,"store_id"
4"magento_1420_store","magento1420","sale.model_sale_shop","ol_groups.list",,,,,"group_id"
5"magento_1420_order","magento1420","sale.model_sale_order","sales_order.list","sales_order.info",,,,"increment_id"
6"magento_1420_order_line","magento1420","sale.model_sale_order_line",,,,,,"item_id"
7"magento_1420_pro_cat","magento1420","product.model_product_category","category.list","category.info","catalog_category.update","catalog_category.create",,"category_id"
8"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"
9"magento_1420_attr_set","magento1420","model_magerp_product_attribute_set","ol_catalog_product_attributeset.list",,,,,"attribute_set_id"
10"magento_1420_attr","magento1420","model_magerp_product_attributes","ol_catalog_product_attribute.list",,,,,"attribute_id"
11"magento_1420_prd","magento1420","product.model_product_product","catalog_product.list","catalog_product.info","ol_catalog_product.update","ol_catalog_product.create",,"product_id"
12"magento_1420_cst_grp","magento1420","base.model_res_partner_category","ol_customer_groups.list",,,,,"customer_group_id"
13"magento_1420_prt_adr","magento1420","base.model_res_partner_address","ol_customer_address.list","ol_customer_address.info",,,,"entity_id"
14"magento_1420_prt","magento1420","base.model_res_partner","customer.list","customer.info","customer.update",,,"customer_id"
015
=== added file 'magentoerpconnect/settings/1.4.2.0/external.mappinglines.template.csv'
--- magentoerpconnect/settings/1.4.2.0/external.mappinglines.template.csv 1970-01-01 00:00:00 +0000
+++ magentoerpconnect/settings/1.4.2.0/external.mappinglines.template.csv 2012-07-06 14:53:18 +0000
@@ -0,0 +1,318 @@
1id,type_id:id,model_id:id,external_field,field_id:id,type,evaluation_type,external_type,child_mapping_id:id,in_function,out_function
2mag_1420_erp_s_name,magento1420,base_sale_multichannels.model_external_shop_group,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
3mag_1420_erp_s_code,magento1420,base_sale_multichannels.model_external_shop_group,code,,in_out,function,unicode,,"result=[('code',ifield)]",
4mag_1420_erp_s_web,magento1420,base_sale_multichannels.model_external_shop_group,website_id,,in_out,function,int,,"result=[('website_id',ifield)]",
5mag_1420_erp_s_isa,magento1420,base_sale_multichannels.model_external_shop_group,is_default,,in_out,function,unicode,,"result=[('is_default',bool(eval(ifield)))]",
6mag_1420_erp_s_stord,magento1420,base_sale_multichannels.model_external_shop_group,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]",
7mag_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)]",
8mag_1420_erp_sv_name,magento1420,model_magerp_storeviews,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
9mag_1420_erp_sv_code,magento1420,model_magerp_storeviews,code,,in_out,function,unicode,,"result=[('code',ifield)]",
10mag_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))]",
11mag_1420_erp_sv_isa,magento1420,model_magerp_storeviews,is_active,,in_out,function,unicode,,"result=[('is_active',bool(eval(ifield)))]",
12mag_1420_erp_sv_stord,magento1420,model_magerp_storeviews,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]",
13mag_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))]",
14mag_1420_erp_st_name,magento1420,sale.model_sale_shop,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
15mag_1420_erp_st_gpid,magento1420,sale.model_sale_shop,group_id,,in_out,function,int,,"result=[('group_id',ifield)]",
16mag_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))]",
17mag_1420_erp_st_default_st,magento1420,sale.model_sale_shop,default_store_id,,in_out,function,int,,"result=[('default_storeview_integer_id',ifield)]",
18mag_1420_erp_st_root_categ,magento1420,sale.model_sale_shop,root_category_id,,in_out,function,int,,"result=[('root_category_id',ifield)]",
19mag_1420_erp_so_total_amount,magento1420,sale.model_sale_order,grand_total,,in_out,function,float,,"result=[('ext_total_amount',str(ifield))]",
20mag_1420_erp_so_name,magento1420,sale.model_sale_order,increment_id,,in_out,function,unicode,,"result=[('magento_incrementid',str(ifield)), ('name','mag_' + str(ifield))]",
21mag_1420_erp_so_carrier_id,magento1420,sale.model_sale_order,shipping_method,,in_out,function,unicode,,"if ifield:
22 carrier_ids = self.pool.get('delivery.carrier').search(cr, uid, [('magento_code', '=', ifield)])
23 if carrier_ids:
24 result=[('carrier_id', carrier_ids[0])]
25 else:
26 fake_partner_id = self.pool.get('res.partner').search(cr, uid, [])[0]
27 model_data_obj = self.pool.get('ir.model.data')
28 model, product_id = model_data_obj.get_object_reference(cr, uid, 'base_sale_multichannels', 'product_product_shipping')
29 carrier_id = self.pool.get('delivery.carrier').create(cr, uid, {'partner_id' : fake_partner_id, 'product_id' : product_id, 'name' : ifield, 'magento_code' : ifield})
30 result=[('carrier_id', carrier_id)]",
31mag_1420_erp_so_pay,magento1420,sale.model_sale_order,payment,,in_out,function,unicode,,"
32payments_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'}
33ifield=eval(ifield)
34result=[('order_policy', ifield['method'] in payments_mapping and payments_mapping[ifield['method']] or 'prepaid'), ('ext_payment_method', ifield['method'])]",
35mag_1420_erp_so_item,magento1420,sale.model_sale_order,items,sale.field_sale_order_order_line,in,sub-mapping,dict,magento_1420_order_line,,
36"mag_1420_erp_soline_name","magento1420","sale.model_sale_order_line","name",,"in_out","function","unicode",,"result=[('name', ifield)]
37",
38"mag_1420_erp_soline_note","magento1420","sale.model_sale_order_line","product_options",,"in","function","unicode",,"if ifield:
39 import re
40 options_label = []
41 clean = re.sub('\w:\w:|\w:\w+;', '', ifield)
42 for each in clean.split('{'):
43 if each.startswith('""label""'):
44 split_info = each.split(';')
45 options_label.append('%s: %s [%s]' % (split_info[1], split_info[3], data['sku']))
46
47 result=[('notes', """".join(options_label).replace('""""', '\n').replace('""', ''))]
48",
49mag_1420_erp_soline_pid,magento1420,sale.model_sale_order_line,product_id,,in_out,function,unicode,,"context['alternative_key'] = data['sku']
50result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]",
51mag_1420_erp_soline_uomqty,magento1420,sale.model_sale_order_line,qty_ordered,,in_out,function,unicode,,"result=[('product_uom_qty',ifield)]",
52mag_1420_erp_soline_uosqty,magento1420,sale.model_sale_order_line,qty_ordered,,in,function,unicode,,"result=[('product_uos_qty',ifield)]",
53mag_1420_erp_soline_price,magento1420,sale.model_sale_order_line,price,,in,function,unicode,,"if context.get('price_is_tax_included', False):
54 result=[('price_unit', (float(data['row_total']) + float(data['tax_amount']))/float(data['qty_ordered']))]
55else:
56 result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]",
57mag_1420_erp_soline_disc,magento1420,sale.model_sale_order_line,discount_amount,,in,function,float,,"if ifield:
58 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)]",
59mag_1420_erp_procat_2,magento1420,product.model_product_category,level,,in,function,int,,"result=[('sequence',ifield),('level',ifield)]",
60mag_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))])
61parent_id = False
62if record_id:
63 parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[])
64 parent_id=parent_rec.get('res_id',False)
65result=[('magento_parent_id',ifield),('parent_id',parent_id)]","magento_parent_id = False
66if record.get('parent_id',False):
67 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id)
68 if not magento_parent_id:
69 self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[external_referential_id],{},context=context)
70 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id)
71if magento_parent_id:
72 result = [('parent_id',magento_parent_id)]"
73mag_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'])]"
74mag_1420_erp_procat_5,magento1420,product.model_product_category,description,,in_out,function,unicode,,"result=[('description',ifield)]","result=[('description',record['description'])]"
75mag_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'])]"
76mag_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'])]"
77mag_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'])]"
78mag_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) :
79 result=[('url_key',record['url_key'])]"
80mag_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'])]"
81mag_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'])]"
82mag_1420_erp_procat_12,magento1420,product.model_product_category,available_sort_by,,in_out,function,list,,"attr_ids = []
83cat_attr_obj = self.pool.get('magerp.product_category_attribute_options')
84if ifield:
85 for val in ifield:
86 attr_ids.append(cat_attr_obj.get_create_option_id(cr, uid, val,'sort_by', context=context))
87 result=[('available_sort_by', [(6, 0, attr_ids)]), ('use_default_available_sort_by', False)]
88else:
89 result=[('use_default_available_sort_by', True)]","if record['use_default_available_sort_by']:
90 res = u''
91else:
92 res = []
93 for cat_attr_option in self.pool.get('magerp.product_category_attribute_options').browse(cr, uid, record['available_sort_by'], context=context):
94 res.append(cat_attr_option.value)
95result=[('available_sort_by', res)]"
96mag_1420_erp_procat_13,magento1420,product.model_product_category,default_sort_by,,in_out,function,unicode,,"if ifield:
97 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'sort_by', context=context)
98else:
99 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','sort_by', context=context)
100result=[('default_sort_by',att_id)]","options_obj = self.pool.get('magerp.product_category_attribute_options')
101cat_attr_option_id = record['default_sort_by']
102if cat_attr_option_id:
103 cat_attr_option_id = cat_attr_option_id[0]
104else:
105 cat_attr_option_id = options_obj._get_default_option(cr, uid, 'sort_by', '', context=context)
106
107cat_attr_option = options_obj.browse(cr, uid, cat_attr_option_id, context=context)
108result=[('default_sort_by', cat_attr_option.value)]"
109mag_1420_erp_procat_14,magento1420,product.model_product_category,updated_at,,in,function,unicode,,"result=[('magerp_stamp',ifield)]",
110mag_1420_erp_procat_15,magento1420,product.model_product_category,image,,in_out,function,unicode,,"image_binary = False
111if ifield and not ifield=='None':
112 try:
113 image_binary = conn.call('ol_catalog_category_media.info', [int(data['category_id'])])
114 except Exception, e:
115 print e
116 pass
117 if image_binary:
118 image_binary = base64.encodestring(base64.urlsafe_b64decode(image_binary[0]['image_data']))
119result=[('image_name',ifield),('image',image_binary)]","if record['image']:
120 img = base64.decodestring(record['image'])
121 img_bin_enc = base64.encodestring(img)
122 conn.call('ol_catalog_category_media.create', [record['image_name'], img_bin_enc])
123 result = [('image',record['image_name'])]
124else:
125 result=[]"
126mag_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'])]"
127mag_1420_erp_procat_17,magento1420,product.model_product_category,page_layout,,in_out,function,unicode,,"if ifield:
128 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'page_layout', context=context)
129else:
130 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','page_layout', context=context)
131result=[('page_layout',att_id)]","page_layout = record['page_layout'] and record['page_layout'][1] or ''
132result=[('page_layout', page_layout)]"
133mag_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'])]"
134mag_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'])]"
135mag_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'])]"
136mag_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'])]"
137mag_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'])]"
138mag_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'])]"
139mag_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'])]"
140mag_1420_erp_attr_1,magento1420,model_magerp_product_attributes,attribute_code,,in_out,function,unicode,,"result=[('attribute_code', ifield)]","result=[('code', record['attribute_code'])]"
141mag_1420_erp_attr_2,magento1420,model_magerp_product_attributes,attribute_id,,in_out,function,int,,"result=[('magento_id', ifield)]",
142mag_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'])]"
143mag_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'])]"
144mag_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'])]"
145mag_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'])]"
146mag_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'])]"
147mag_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'])]"
148mag_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'])]"
149mag_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'])]"
150mag_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'])]"
151mag_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'])]"
152mag_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'])]"
153mag_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'])]"
154mag_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'])]"
155mag_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'])]"
156mag_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'])]"
157mag_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'])]"
158mag_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'])]"
159mag_1420_erp_attr_20,magento1420,model_magerp_product_attributes,position,,in_out,function,int,,"result=[('position', ifield)]","result=[('position', record['position'])]"
160mag_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'])]"
161mag_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'])]"
162mag_1420_erp_attr_23,magento1420,model_magerp_product_attributes,note,,in_out,function,unicode,,"result=[('note', ifield)]","result=[('note', record['note'])]"
163mag_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'])]"
164mag_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']))]"
165mag_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) :
166 result=[('url_key',record['x_magerp_url_key'])]"
167mag_1420_erp_prd_2,magento1420,product.model_product_product,name,,in_out,function,unicode,,"result = [('name',ifield)]","result = [('name',record['name'])]"
168mag_1420_erp_prd_3,magento1420,product.model_product_product,description,,in_out,function,unicode,,"result = [('description',ifield)]",
169mag_1420_erp_prd_4,magento1420,product.model_product_product,short_description,,in_out,function,unicode,,"result = [('description_sale',ifield)]",
170mag_1420_erp_prd_5,magento1420,product.model_product_product,sku,,in_out,function,unicode,,"result = [('magento_sku',ifield), ('default_code',ifield)]",
171mag_1420_erp_prd_6,magento1420,product.model_product_product,weight,,in_out,function,float,,"result = [('weight',ifield)]","result = [('weight',record['weight'] or 0)]"
172mag_1420_erp_prd_7,magento1420,product.model_product_product,category_ids,,in_out,function,list,,"categ_ids =[]
173if ifield and len(ifield) > 0:
174 for category_ids in ifield:
175 categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, category_ids, external_referential_id, context=context))
176 categ_id = categ_ids.pop()
177else:
178 categ_id = self.pool.get('external.referential').browse(cr, uid, external_referential_id).default_pro_cat.id
179result = [('categ_id', categ_id), ('categ_ids',[(6, 0, categ_ids)])]","
180cat_obj = self.pool.get('product.category')
181product = self.browse(cr, uid, record['id'])
182categ_ids = [categ.id for categ in ([product.categ_id] + product.categ_ids) if categ.magento_exportable]
183mag_categ_ids = []
184for categ_id in categ_ids:
185 mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id)
186 if not mag_categ_id:
187 cat_obj.ext_export(cr, uid, [categ_id], [external_referential_id], context=context)
188 mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id)
189 mag_categ_ids.append(mag_categ_id)
190result=[('category_ids', mag_categ_ids)]"
191mag_1420_erp_prd_8,magento1420,product.model_product_product,price,,in_out,function,float,,"result=[('list_price',ifield)]",result=[]#map later
192mag_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)]"
193mag_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))]",
194mag_1420_erp_prd_11,magento1420,product.model_product_product,special_price,,in_out,function,float,,"result = [('x_magerp_special_price',ifield)]",
195mag_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
196mag_1420_erp_prd_13,magento1420,product.model_product_product,minimal_price,,in_out,function,float,,"result = [('x_magerp_minimal_price',ifield)]","
197if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0:
198 result = [('minimal_price',record['x_magerp_minimal_price'])]
199else:
200 result = [('minimal_price',False)]"
201mag_1420_erp_prd_14,magento1420,product.model_product_product,type_id,,in_out,function,unicode,,"if ifield:
202 product_type_ids = self.pool.get('magerp.product_product_type').search(cr,uid,[('product_type','=',ifield)])
203 if product_type_ids:
204 result = [('product_type',ifield)]","if 'product_type' in record and record['product_type']:
205 result = [('type_id',record['product_type'])]
206else:
207 result = [('type_id','simple')]"
208mag_1420_erp_prd_15,magento1420,product.model_product_product,websites,,in_out,function,list,,"websites_ids = []
209for ext_id in ifield:
210 websites_ids.append(self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ext_id, external_referential_id, context=context))
211
212##### OPTION START, with this if the field websites of the product is empty the product is exported on every website
213all_oe_websites_ids = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)])
214if set(websites_ids) == set(all_oe_websites_ids):
215 websites_ids =[]
216##### OPTION END
217
218result=[('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
219if not record['websites_ids']:
220 record['websites_ids'] = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)])
221##### OPTION END
222
223ext_websites_ids = []
224for oe_id in record['websites_ids']:
225 ext_websites_ids.append(self.pool.get('external.shop.group').oeid_to_extid(cr, uid, oe_id, external_referential_id))
226
227result=[('websites', ext_websites_ids)]"
228mag_1420_erp_prd_16,magento1420,product.model_product_product,has_options,,in,function,unicode,,"result =[('x_magerp_has_options',ifield)]",
229magento_1420_cst_grp_1,magento1420,base.model_res_partner_category,customer_group_code,,in,function,unicode,,"result=[('name',ifield)]",
230magento_1420_cst_grp_3,magento1420,base.model_res_partner_category,tax_class_id,,in,function,int,,"result=[('tax_class_id',ifield)]",
231magento_1420_prt_adr_2,magento1420,base.model_res_partner_address,city,,in_out,function,unicode,,"result=[('city',ifield)]",
232magento_1420_prt_adr_3,magento1420,base.model_res_partner_address,fax,,in_out,function,unicode,,"result=[('fax',ifield)]",
233magento_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])
234if data.get('company'):
235 name = ""%s ; %s"" % (data['company'], name)
236result = [('name', name), ('firstname', ifield), ('lastname', data['lastname'])]",
237magento_1420_prt_adr_6,magento1420,base.model_res_partner_address,is_active,,in_out,function,unicode,,"result=[('active',bool(eval(ifield)))]",
238magento_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)])
239if result and len(result)==1:
240 result=[('country_id',result[0])]
241else:
242 result=[]
243",
244magento_1420_prt_adr_8,magento1420,base.model_res_partner_address,street,,in_out,function,unicode,,"if ifield:
245 if len(ifield.split('\n')) ==2 :
246 result = [('street', ifield.split('\n')[0]) , ('street2', ifield.split('\n')[1])]
247 else :
248 result = [('street',ifield.replace('\\n',','))]
249else:
250 result = []",
251magento_1420_prt_adr_9,magento1420,base.model_res_partner_address,postcode,,in_out,function,unicode,,"result=[('zip',ifield)]",
252magento_1420_prt_adr_10,magento1420,base.model_res_partner_address,telephone,,in_out,function,unicode,,"result=[('phone',ifield)]",
253magento_1420_prt_adr_11,magento1420,base.model_res_partner_address,region,,in_out,function,unicode,,"if ifield:
254 result = self.pool.get('res.country.state').search(cr,uid,[('name','=ilike',ifield)])
255 if result and len(result)==1:
256 result = [('state_id',result[0])]
257 else:
258 result=[]
259else:
260 result=[]",
261magento_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)
262if result:
263 result=[('partner_id',result)]
264else:
265 result=[('partner_id',False)]",
266magento_1420_prt_adr_14,magento1420,base.model_res_partner_address,address_type,,in_out,function,unicode,,"if ifield=='billing':
267 result=[('type','invoice')]
268elif ifield=='shipping':
269 result=[('type','delivery')]
270else:
271 result=[]",
272magento_1420_prt_adr_15,magento1420,base.model_res_partner_address,email,,in_out,function,unicode,,"result = [('email', False)]
273if ifield:
274 result = [('email', ifield)]
275else:
276 partner_obj = self.pool.get('res.partner')
277 partner_id = partner_obj.extid_to_existing_oeid(cr, uid, data['customer_id'] ,external_referential_id)
278 if partner_id:
279 result = [('email', partner_obj.browse(cr, uid, partner_id).emailid)]",
280magento_1420_prt_adr_17,magento1420,base.model_res_partner_address,default_billing,,in_out,function,unicode,,"result = [('type', 'other')]
281if data.get('default_billing') and data.get('default_shipping'):
282 result = [('type', 'default')]
283elif data.get('default_billing'):
284 result = [('type', 'invoice')]
285elif data.get('default_shipping'):
286 result = [('type', 'delivery')]",
287magento_1420_prt_2,magento1420,base.model_res_partner,group_id,,in_out,function,int,,"if ifield:
288 result=self.pool.get('res.partner.category').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
289 if result:
290 result=[('group_id',result)]",
291magento_1420_prt_3,magento1420,base.model_res_partner,store_id,,in_out,function,int,,"if ifield:
292 result=self.pool.get('magerp.storeviews').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
293 if result:
294 store = self.pool.get('magerp.storeviews').browse(cr, uid, result)
295 lang = store.lang_id
296 result=[('store_id',result),('lang',lang and lang.code or False)]
297 if not data.get('website_id'):
298 result.append(('website_id', store.website_id.id))",
299magento_1420_prt_4,magento1420,base.model_res_partner,website_id,,in_out,function,int,,"if ifield:
300 result=self.pool.get('external.shop.group').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
301 if result:
302 result=[('website_id',result)]",
303magento_1420_prt_5,magento1420,base.model_res_partner,created_in,,in_out,function,unicode,,"result=[('created_in',ifield)]",
304magento_1420_prt_6,magento1420,base.model_res_partner,created_at,,in_out,function,unicode,,"result=[('created_at',ifield)]",
305magento_1420_prt_7,magento1420,base.model_res_partner,updated_at,,in_out,function,unicode,,"result=[('updated_at',ifield)]",
306magento_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'])
307fn = add_id.address[0].firstname
308ln = add_id.address[0].lastname
309result=[('firstname', fn), ('lastname', ln)]"
310magento_1420_prt_10,magento1420,base.model_res_partner,email,,in_out,function,unicode,,"result=[('emailid',ifield)]",
311magento_1420_prt_11,magento1420,base.model_res_partner,taxvat,,in_out,function,unicode,,"if ifield:
312 result=[('mag_vat',ifield)]
313else:
314 result=[]",
315magento_1420_prt_12,magento1420,base.model_res_partner,dob,,in_out,function,unicode,,"if ifield:
316 result =[('mag_birthday',ifield[:10])]
317else:
318 result=[]",
0319
=== added file 'magentoerpconnect/settings/1.4.2.0/external.referential.type.csv'
--- magentoerpconnect/settings/1.4.2.0/external.referential.type.csv 1970-01-01 00:00:00 +0000
+++ magentoerpconnect/settings/1.4.2.0/external.referential.type.csv 2012-07-06 14:53:18 +0000
@@ -0,0 +1,2 @@
1"id","name"
2"magento1420","Magento Version 1.4.2.0+"
03
=== modified file 'magentoerpconnect/settings/1.5.0.0/external.mapping.template.csv'
--- magentoerpconnect/settings/1.5.0.0/external.mapping.template.csv 2012-05-19 11:35:11 +0000
+++ magentoerpconnect/settings/1.5.0.0/external.mapping.template.csv 2012-07-06 14:53:18 +0000
@@ -1,3 +1,4 @@
1<<<<<<< TREE
1id,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_name2id,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
2mag1500_external_shop_group,,magentoerpconnect.magento1500,base_sale_multichannels.model_external_shop_group,ol_websites.list,,,,,,,website_id,3mag1500_external_shop_group,,magentoerpconnect.magento1500,base_sale_multichannels.model_external_shop_group,ol_websites.list,,,,,,,website_id,
3mag1500_magerp_storeviews,,magentoerpconnect.magento1500,magentoerpconnect.model_magerp_storeviews,ol_storeviews.list,,,,,,,store_id,4mag1500_magerp_storeviews,,magentoerpconnect.magento1500,magentoerpconnect.model_magerp_storeviews,ol_storeviews.list,,,,,,,store_id,
@@ -14,3 +15,19 @@
14mag1500_sale_order,,magentoerpconnect.magento1500,base_sale_multichannels.model_sale_order,sales_order.list,sales_order.info,,,,sales_order.search,sales_order.done,increment_id,15mag1500_sale_order,,magentoerpconnect.magento1500,base_sale_multichannels.model_sale_order,sales_order.list,sales_order.info,,,,sales_order.search,sales_order.done,increment_id,
15mag1500_account_invoice,,magentoerpconnect.magento1500,account.model_account_invoice,,,,,,,,,16mag1500_account_invoice,,magentoerpconnect.magento1500,account.model_account_invoice,,,,,,,,,
16mag1500_product_link,,magentoerpconnect.magento1500,magentoerpconnect.model_product_link,,,,,,,,,17mag1500_product_link,,magentoerpconnect.magento1500,magentoerpconnect.model_product_link,,,,,,,,,
18=======
19"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"
20"magento_1500_website","magento1500","base_sale_multichannels.model_external_shop_group","ol_websites.list",,,,,"website_id"
21"magento_1500_storeview","magento1500","model_magerp_storeviews","ol_storeviews.list",,,,,"store_id"
22"magento_1500_store","magento1500","sale.model_sale_shop","ol_groups.list",,,,,"group_id"
23"magento_1500_order","magento1500","sale.model_sale_order","sales_order.list","sales_order.info",,,,"increment_id"
24"magento_1500_order_line","magento1500","sale.model_sale_order_line",,,,,,"item_id"
25"magento_1500_pro_cat","magento1500","product.model_product_category","category.list","category.info","catalog_category.update","catalog_category.create",,"category_id"
26"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"
27"magento_1500_attr_set","magento1500","model_magerp_product_attribute_set","ol_catalog_product_attributeset.list",,,,,"attribute_set_id"
28"magento_1500_attr","magento1500","model_magerp_product_attributes","ol_catalog_product_attribute.list",,,,,"attribute_id"
29"magento_1500_prd","magento1500","product.model_product_product","catalog_product.list","catalog_product.info","ol_catalog_product.update","ol_catalog_product.create",,"product_id"
30"magento_1500_cst_grp","magento1500","base.model_res_partner_category","ol_customer_groups.list",,,,,"customer_group_id"
31"magento_1500_prt_adr","magento1500","base.model_res_partner_address","ol_customer_address.list","ol_customer_address.info",,,,"entity_id"
32"magento_1500_prt","magento1500","base.model_res_partner","customer.list","customer.info","customer.update",,,"customer_id"
33>>>>>>> MERGE-SOURCE
1734
=== added file 'magentoerpconnect/settings/1.5.0.0/external.mappinglines.template.csv.OTHER'
--- magentoerpconnect/settings/1.5.0.0/external.mappinglines.template.csv.OTHER 1970-01-01 00:00:00 +0000
+++ magentoerpconnect/settings/1.5.0.0/external.mappinglines.template.csv.OTHER 2012-07-06 14:53:18 +0000
@@ -0,0 +1,330 @@
1id,type_id:id,model_id:id,external_field,field_id:id,type,evaluation_type,external_type,child_mapping_id:id,in_function,out_function
2mag_1500_erp_s_name,magento1500,base_sale_multichannels.model_external_shop_group,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
3mag_1500_erp_s_code,magento1500,base_sale_multichannels.model_external_shop_group,code,,in_out,function,unicode,,"result=[('code',ifield)]",
4mag_1500_erp_s_web,magento1500,base_sale_multichannels.model_external_shop_group,website_id,,in_out,function,int,,"result=[('website_id',ifield)]",
5mag_1500_erp_s_isa,magento1500,base_sale_multichannels.model_external_shop_group,is_default,,in_out,function,unicode,,"result=[('is_default',bool(eval(ifield)))]",
6mag_1500_erp_s_stord,magento1500,base_sale_multichannels.model_external_shop_group,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]",
7mag_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)]",
8mag_1500_erp_sv_name,magento1500,model_magerp_storeviews,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
9mag_1500_erp_sv_code,magento1500,model_magerp_storeviews,code,,in_out,function,unicode,,"result=[('code',ifield)]",
10mag_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))]",
11mag_1500_erp_sv_isa,magento1500,model_magerp_storeviews,is_active,,in_out,function,unicode,,"result=[('is_active',bool(eval(ifield)))]",
12mag_1500_erp_sv_stord,magento1500,model_magerp_storeviews,sort_order,,in_out,function,int,,"result=[('sort_order',ifield)]",
13mag_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))]",
14mag_1500_erp_st_name,magento1500,sale.model_sale_shop,name,,in_out,function,unicode,,"result=[('name',ifield)]","result=[('name',record['name'])]"
15mag_1500_erp_st_gpid,magento1500,sale.model_sale_shop,group_id,,in_out,function,int,,"result=[('group_id',ifield)]",
16mag_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))]",
17mag_1500_erp_st_default_st,magento1500,sale.model_sale_shop,default_store_id,,in_out,function,int,,"result=[('default_storeview_integer_id',ifield)]",
18mag_1500_erp_st_root_categ,magento1500,sale.model_sale_shop,root_category_id,,in_out,function,int,,"result=[('root_category_id',ifield)]",
19mag_1500_erp_so_name,magento1500,sale.model_sale_order,increment_id,,in_out,function,unicode,,"result=[('magento_incrementid',str(ifield)), ('name','mag_' + str(ifield))]",
20mag_1500_erp_so_total_amount,magento1500,sale.model_sale_order,grand_total,,in_out,function,float,,"result=[('ext_total_amount',str(ifield))]",
21mag_1500_erp_so_carrier_id,magento1500,sale.model_sale_order,shipping_method,,in_out,function,unicode,,"if ifield:
22 carrier_ids = self.pool.get('delivery.carrier').search(cr, uid, [('magento_code', '=', ifield)])
23 if carrier_ids:
24 result=[('carrier_id', carrier_ids[0])]
25 else:
26 fake_partner_id = self.pool.get('res.partner').search(cr, uid, [])[0]
27 model_data_obj = self.pool.get('ir.model.data')
28 model, product_id = model_data_obj.get_object_reference(cr, uid, 'base_sale_multichannels', 'product_product_shipping')
29 carrier_id = self.pool.get('delivery.carrier').create(cr, uid, {'partner_id' : fake_partner_id, 'product_id' : product_id, 'name' : ifield, 'magento_code' : ifield})
30 result=[('carrier_id', carrier_id)]",
31mag_1500_erp_so_pay,magento1500,sale.model_sale_order,payment,,in_out,function,unicode,,"
32payments_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'}
33ifield=eval(ifield)
34result=[('order_policy', ifield['method'] in payments_mapping and payments_mapping[ifield['method']] or 'prepaid'), ('ext_payment_method', ifield['method'])]",
35
36mag_1500_erp_so_item,magento1500,sale.model_sale_order,items,sale.field_sale_order_order_line,in,sub-mapping,dict,magento_1500_order_line,,
37"mag_1500_erp_soline_name","magento1500","sale.model_sale_order_line","name",,"in_out","function","unicode",,"result=[('name', ifield)]
38",
39"Mag_1500_erp_soline_note","magento1500","sale.model_sale_order_line","product_options",,"in","function","unicode",,"if ifield:
40 import re
41 options_label = []
42 clean = re.sub('\w:\w:|\w:\w+;', '', ifield)
43 for each in clean.split('{'):
44 if each.startswith('""label""'):
45 split_info = each.split(';')
46 options_label.append('%s: %s [%s]' % (split_info[1], split_info[3], data['sku']))
47
48 result=[('notes', """".join(options_label).replace('""""', '\n').replace('""', ''))]
49",
50mag_1500_erp_soline_pid,magento1500,sale.model_sale_order_line,product_id,,in_out,function,unicode,,"context['alternative_key'] = data['sku']
51result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, ifield, external_referential_id, context=context))]",
52mag_1500_erp_soline_uomqty,magento1500,sale.model_sale_order_line,qty_ordered,,in_out,function,unicode,,"result=[('product_uom_qty',ifield)]",
53mag_1500_erp_soline_uosqty,magento1500,sale.model_sale_order_line,qty_ordered,,in,function,unicode,,"result=[('product_uos_qty',ifield)]",
54mag_1500_erp_soline_price,magento1500,sale.model_sale_order_line,price,,in,function,unicode,,"if context.get('price_is_tax_included', False):
55 result=[('price_unit', (float(data['row_total']) + float(data['tax_amount']))/float(data['qty_ordered']))]
56else:
57 result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]",
58mag_1500_erp_soline_disc,magento1500,sale.model_sale_order_line,discount_amount,,in,function,float,,"if ifield:
59 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)]",
60mag_1500_erp_procat_2,magento1500,product.model_product_category,level,,in,function,int,,"result=[('sequence',ifield),('level',ifield)]",
61mag_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))])
62parent_id = False
63if record_id:
64 parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[])
65 parent_id=parent_rec.get('res_id',False)
66result=[('magento_parent_id',ifield),('parent_id',parent_id)]","magento_parent_id = False
67if record.get('parent_id',False):
68 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id)
69 if not magento_parent_id:
70 self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[external_referential_id],{},context=context)
71 magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id)
72if magento_parent_id:
73 result = [('parent_id',magento_parent_id)]"
74mag_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'])]"
75mag_1500_erp_procat_5,magento1500,product.model_product_category,description,,in_out,function,unicode,,"result=[('description',ifield)]","result=[('description',record['description'])]"
76mag_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'])]"
77mag_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'])]"
78mag_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'])]"
79mag_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) :
80 result=[('url_key',record['url_key'])]"
81mag_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'])]"
82mag_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'])]"
83mag_1500_erp_procat_12,magento1500,product.model_product_category,available_sort_by,,in_out,function,unicode,,"attr_ids = []
84cat_attr_obj = self.pool.get('magerp.product_category_attribute_options')
85if ifield:
86 for val in ifield:
87 attr_ids.append(cat_attr_obj.get_create_option_id(cr, uid, val,'sort_by', context=context))
88 result=[('available_sort_by', [(6, 0, attr_ids)]), ('use_default_available_sort_by', False)]
89else:
90 result=[('use_default_available_sort_by', True)]","if record['use_default_available_sort_by']:
91 res = u''
92else:
93 res = []
94 for cat_attr_option in self.pool.get('magerp.product_category_attribute_options').browse(cr, uid, record['available_sort_by'], context=context):
95 res.append(cat_attr_option.value)
96result=[('available_sort_by', res)]"
97mag_1500_erp_procat_13,magento1500,product.model_product_category,default_sort_by,,in_out,function,unicode,,"if ifield:
98 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'sort_by', context=context)
99else:
100 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','sort_by', context=context)
101result=[('default_sort_by',att_id)]","options_obj = self.pool.get('magerp.product_category_attribute_options')
102cat_attr_option_id = record['default_sort_by']
103if cat_attr_option_id:
104 cat_attr_option_id = cat_attr_option_id[0]
105else:
106 cat_attr_option_id = options_obj._get_default_option(cr, uid, 'sort_by', '', context=context)[0]
107
108cat_attr_option = options_obj.browse(cr, uid, cat_attr_option_id, context=context)
109result=[('default_sort_by', cat_attr_option.value)]"
110mag_1500_erp_procat_14,magento1500,product.model_product_category,updated_at,,in,function,unicode,,"result=[('magerp_stamp',ifield)]",
111mag_1500_erp_procat_15,magento1500,product.model_product_category,image,,in_out,function,unicode,,"image_binary = False
112if ifield and not ifield=='None':
113 try:
114 image_binary = conn.call('ol_catalog_category_media.info', [int(data['category_id'])])
115 except Exception, e:
116 print e
117 pass
118 if image_binary:
119 image_binary = base64.encodestring(base64.urlsafe_b64decode(image_binary[0]['image_data']))
120result=[('image_name',ifield),('image',image_binary)]","if record['image']:
121 img = base64.decodestring(record['image'])
122 img_bin_enc = base64.encodestring(img)
123 conn.call('ol_catalog_category_media.create', [record['image_name'], img_bin_enc])
124 result = [('image',record['image_name'])]
125else:
126 result=[]"
127mag_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'])]"
128mag_1500_erp_procat_17,magento1500,product.model_product_category,page_layout,,in_out,function,unicode,,"if ifield:
129 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, ifield,'page_layout', context=context)
130else:
131 att_id = self.pool.get('magerp.product_category_attribute_options').get_create_option_id(cr, uid, '','page_layout', context=context)
132result=[('page_layout',att_id)]","page_layout = record['page_layout'] and record['page_layout'][1] or ''
133result=[('page_layout', page_layout)]"
134mag_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'])]"
135mag_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'])]"
136mag_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'])]"
137mag_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'])]"
138mag_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'])]"
139mag_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'])]"
140mag_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'])]"
141mag_1500_erp_attr_1,magento1500,model_magerp_product_attributes,attribute_code,,in_out,function,unicode,,"result=[('attribute_code', ifield)]","result=[('code', record['attribute_code'])]"
142mag_1500_erp_attr_2,magento1500,model_magerp_product_attributes,attribute_id,,in_out,function,int,,"result=[('magento_id', ifield)]",
143mag_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'])]"
144mag_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'])]"
145mag_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'])]"
146mag_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'])]"
147mag_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'])]"
148mag_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'])]"
149mag_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'])]"
150mag_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'])]"
151mag_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'])]"
152mag_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'])]"
153mag_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'])]"
154mag_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'])]"
155mag_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'])]"
156mag_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'])]"
157mag_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'])]"
158mag_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'])]"
159mag_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'])]"
160mag_1500_erp_attr_20,magento1500,model_magerp_product_attributes,position,,in_out,function,int,,"result=[('position', ifield)]","result=[('position', record['position'])]"
161mag_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'])]"
162mag_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'])]"
163mag_1500_erp_attr_23,magento1500,model_magerp_product_attributes,note,,in_out,function,unicode,,"result=[('note', ifield)]","result=[('note', record['note'])]"
164mag_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'])]"
165mag_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']))]"
166mag_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) :
167 result=[('url_key',record['x_magerp_url_key'])]"
168mag_1500_erp_prd_2,magento1500,product.model_product_product,name,,in_out,function,unicode,,"result = [('name',ifield)]","result = [('name',record['name'])]"
169mag_1500_erp_prd_3,magento1500,product.model_product_product,description,,in_out,function,unicode,,"result = [('description',ifield)]",
170mag_1500_erp_prd_4,magento1500,product.model_product_product,short_description,,in_out,function,unicode,,"result = [('description_sale',ifield)]",
171mag_1500_erp_prd_5,magento1500,product.model_product_product,sku,,in_out,function,unicode,,"result = [('magento_sku',ifield), ('default_code',ifield)]",
172mag_1500_erp_prd_6,magento1500,product.model_product_product,weight,,in_out,function,float,,"result = [('weight',ifield)]","result = [('weight',record['weight'] or 0)]"
173mag_1500_erp_prd_7,magento1500,product.model_product_product,categories,,in_out,function,list,,"categ_ids =[]
174if ifield:
175 for category_id in ifield:
176 categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, category_id, external_referential_id, context=context))
177 main_categ_id = categ_ids.pop()
178else:
179 main_categ_id = self.pool.get('external.referential').browse(cr, uid, external_referential_id).default_pro_cat.id
180result = [('categ_id', main_categ_id), ('categ_ids',[(6, 0, categ_ids)])]","
181cat_obj = self.pool.get('product.category')
182product = self.browse(cr, uid, record['id'])
183categ_ids = [categ.id for categ in ([product.categ_id] + product.categ_ids) if categ.magento_exportable]
184mag_categ_ids = []
185for categ_id in categ_ids:
186 mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id)
187 if not mag_categ_id:
188 ctx = dict(context, force_export=True)
189 cat_obj.ext_export(cr, uid, [categ_id], [external_referential_id], context=ctx)
190 mag_categ_id = cat_obj.oeid_to_extid(cr, uid, categ_id, external_referential_id)
191 mag_categ_ids.append(mag_categ_id)
192result=[('category_ids', mag_categ_ids)]"
193mag_1500_erp_prd_8,magento1500,product.model_product_product,price,,in_out,function,float,,"result=[('list_price',ifield)]",result=[]#map later
194mag_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)]"
195mag_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))]",
196mag_1500_erp_prd_11,magento1500,product.model_product_product,special_price,,in_out,function,float,,"result = [('x_magerp_special_price',ifield)]",
197mag_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
198mag_1500_erp_prd_13,magento1500,product.model_product_product,minimal_price,,in_out,function,float,,"result = [('x_magerp_minimal_price',ifield)]","
199if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0:
200 result = [('minimal_price',record['x_magerp_minimal_price'])]
201else:
202 result = [('minimal_price',False)]"
203mag_1500_erp_prd_14,magento1500,product.model_product_product,type_id,,in_out,function,unicode,,"if ifield:
204 product_type_ids = self.pool.get('magerp.product_product_type').search(cr,uid,[('product_type','=',ifield)])
205 if product_type_ids:
206 result = [('product_type',ifield)]","if 'product_type' in record and record['product_type']:
207 result = [('type_id',record['product_type'])]
208else:
209 result = [('type_id','simple')]"
210mag_1500_erp_prd_15,magento1500,product.model_product_product,websites,,in_out,function,list,,"websites_ids = []
211for ext_id in ifield:
212 websites_ids.append(self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ext_id, external_referential_id, context=context))
213
214##### OPTION START, with this if the field websites of the product is empty the product is exported on every website
215all_oe_websites_ids = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)])
216if set(websites_ids) == set(all_oe_websites_ids):
217 websites_ids =[]
218##### OPTION END
219
220result=[('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
221if not record['websites_ids']:
222 record['websites_ids'] = self.pool.get('external.shop.group').search(cr,uid,[('referential_id', '=', external_referential_id)])
223##### OPTION END
224
225ext_websites_ids = []
226for oe_id in record['websites_ids']:
227 ext_websites_ids.append(self.pool.get('external.shop.group').oeid_to_extid(cr, uid, oe_id, external_referential_id))
228
229result=[('websites', ext_websites_ids)]"
230mag_1500_erp_prd_16,magento1500,product.model_product_product,has_options,,in,function,unicode,,"result =[('x_magerp_has_options',ifield)]",
231magento_1500_cst_grp_1,magento1500,base.model_res_partner_category,customer_group_code,,in,function,unicode,,"result=[('name',ifield)]",
232magento_1500_cst_grp_3,magento1500,base.model_res_partner_category,tax_class_id,,in,function,int,,"result=[('tax_class_id',ifield)]",
233magento_1500_prt_adr_2,magento1500,base.model_res_partner_address,city,,in_out,function,unicode,,"result=[('city',ifield)]",
234magento_1500_prt_adr_3,magento1500,base.model_res_partner_address,fax,,in_out,function,unicode,,"result=[('fax',ifield)]",
235magento_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])
236if data.get('company'):
237 name = ""%s ; %s"" % (data['company'], name)
238result = [('name', name), ('firstname', ifield), ('lastname', data['lastname'])]",
239magento_1500_prt_adr_6,magento1500,base.model_res_partner_address,is_active,,in_out,function,unicode,,"result=[('active',bool(eval(ifield)))]",
240magento_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)])
241if result and len(result)==1:
242 result=[('country_id',result[0])]
243else:
244 result=[]
245",
246magento_1500_prt_adr_8,magento1500,base.model_res_partner_address,street,,in_out,function,unicode,,"if ifield:
247 if len(ifield.split('\n')) ==2 :
248 result = [('street', ifield.split('\n')[0]) , ('street2', ifield.split('\n')[1])]
249 else :
250 result = [('street',ifield.replace('\\n',','))]
251else:
252 result = []",
253magento_1500_prt_adr_9,magento1500,base.model_res_partner_address,postcode,,in_out,function,unicode,,"result=[('zip',ifield)]",
254magento_1500_prt_adr_10,magento1500,base.model_res_partner_address,telephone,,in_out,function,unicode,,"result=[('phone',ifield)]",
255magento_1500_prt_adr_11,magento1500,base.model_res_partner_address,region,,in_out,function,unicode,,"if ifield:
256 result = self.pool.get('res.country.state').search(cr,uid,[('name','=ilike',ifield)])
257 if result and len(result)==1:
258 result = [('state_id',result[0])]
259 else:
260 result=[]
261else:
262 result=[]",
263magento_1500_prt_adr_13,magento1500,base.model_res_partner_address,customer_id,,in_out,function,int,,"
264if ifield:
265 result=self.pool.get('res.partner').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
266 if result:
267 result=[('partner_id', result)]
268 else:
269 result=[('partner_id', False)]",
270magento_1500_prt_adr_14,magento1500,base.model_res_partner_address,address_type,,in_out,function,unicode,,"if ifield=='billing':
271 result=[('type','invoice')]
272elif ifield=='shipping':
273 result=[('type','delivery')]
274else:
275 result=[]",
276magento_1500_prt_adr_15,magento1500,base.model_res_partner_address,email,,in_out,function,unicode,,"result = [('email', False)]
277if ifield:
278 result = [('email', ifield)]
279else:
280 if data.get('customer_id'):
281 partner_obj = self.pool.get('res.partner')
282 partner_id = partner_obj.extid_to_existing_oeid(cr, uid, data['customer_id'] ,external_referential_id)
283 if partner_id:
284 result = [('email', partner_obj.browse(cr, uid, partner_id).emailid)] ",
285magento_1500_prt_adr_16,magento1500,base.model_res_partner_address,prefix,,in_out,function,unicode,,"if ifield:
286 title_ids = self.pool.get('res.partner.title').search(cr, uid, [('domain', '=', 'contact'), ('shortcut', '=', ifield)])
287 if title_ids:
288 title_id = title_ids[0]
289 else:
290 title_id = self.pool.get('res.partner.title').create(cr, uid, {'domain': 'contact', 'shortcut': ifield, 'name' : ifield})
291 result=[('title', title_id)]",
292magento_1500_prt_adr_17,magento1500,base.model_res_partner_address,default_billing,,in_out,function,unicode,,"result = [('type', 'other')]
293if data.get('default_billing') and data.get('default_shipping'):
294 result = [('type', 'default')]
295elif data.get('default_billing'):
296 result = [('type', 'invoice')]
297elif data.get('default_shipping'):
298 result = [('type', 'delivery')]",
299magento_1500_prt_2,magento1500,base.model_res_partner,group_id,,in_out,function,int,,"if ifield:
300 result=self.pool.get('res.partner.category').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
301 if result:
302 result=[('group_id',result)]",
303magento_1500_prt_3,magento1500,base.model_res_partner,store_id,,in_out,function,int,,"if ifield:
304 result=self.pool.get('magerp.storeviews').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
305 if result:
306 store = self.pool.get('magerp.storeviews').browse(cr, uid, result)
307 lang = store.lang_id
308 result=[('store_id',result),('lang',lang and lang.code or False)]
309 if not data.get('website_id'):
310 result.append(('website_id', store.website_id.id))",
311magento_1500_prt_4,magento1500,base.model_res_partner,website_id,,in_out,function,int,,"if ifield:
312 result=self.pool.get('external.shop.group').extid_to_oeid(cr,uid,ifield,external_referential_id, context=context)
313 if result:
314 result=[('website_id',result)]",
315magento_1500_prt_5,magento1500,base.model_res_partner,created_in,,in_out,function,unicode,,"result=[('created_in',ifield)]",
316magento_1500_prt_6,magento1500,base.model_res_partner,created_at,,in_out,function,unicode,,"result=[('created_at',ifield)]",
317magento_1500_prt_7,magento1500,base.model_res_partner,updated_at,,in_out,function,unicode,,"result=[('updated_at',ifield)]",
318magento_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'])
319fn = add_id.address[0].firstname
320ln = add_id.address[0].lastname
321result=[('firstname', fn), ('lastname', ln)]"
322magento_1500_prt_10,magento1500,base.model_res_partner,email,,in_out,function,unicode,,"result=[('emailid',ifield)]",
323magento_1500_prt_11,magento1500,base.model_res_partner,taxvat,,in_out,function,unicode,,"if ifield:
324 result=[('mag_vat',ifield)]
325else:
326 result=[]",
327magento_1500_prt_12,magento1500,base.model_res_partner,dob,,in_out,function,unicode,,"if ifield:
328 result =[('mag_birthday',ifield[:10])]
329else:
330 result=[]",
0331
=== added directory 'magentoerpconnect/settings/update'
=== added file 'magentoerpconnect/settings/update/fix_product_categories.sql'
--- magentoerpconnect/settings/update/fix_product_categories.sql 1970-01-01 00:00:00 +0000
+++ magentoerpconnect/settings/update/fix_product_categories.sql 2012-07-06 14:53:18 +0000
@@ -0,0 +1,7 @@
1UPDATE product_category
2SET default_sort_by=(SELECT id FROM magerp_product_category_attribute_options WHERE value='' and attribute_name='sort_by')
3WHERE default_sort_by in (SELECT id FROM magerp_product_category_attribute_options WHERE value='None' and attribute_name='sort_by');
4
5UPDATE product_category
6SET page_layout=(SELECT id FROM magerp_product_category_attribute_options WHERE value='' and attribute_name='page_layout')
7WHERE page_layout in (SELECT id FROM magerp_product_category_attribute_options WHERE value='None' and attribute_name='page_layout');
08
=== added file 'magentoerpconnect/settings/update/magerp.product_category_attribute_options.xml'
--- magentoerpconnect/settings/update/magerp.product_category_attribute_options.xml 1970-01-01 00:00:00 +0000
+++ magentoerpconnect/settings/update/magerp.product_category_attribute_options.xml 2012-07-06 14:53:18 +0000
@@ -0,0 +1,16 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4 <record model='magerp.product_category_attribute_options' id='mag_product_category_attribute_1_1400'>
5 <field name="attribute_name">page_layout</field>
6 <field name="label">No layout updates</field>
7 <field name="value" eval='""' />
8 </record>
9
10 <record model='magerp.product_category_attribute_options' id='mag_product_category_attribute_7_1400'>
11 <field name="attribute_name">sort_by</field>
12 <field name="label">Use Config Settings</field>
13 <field name="value" eval='""' />
14 </record>
15 </data>
16</openerp>
017
=== modified file 'magentoerpconnect/stock.py'
--- magentoerpconnect/stock.py 2012-05-25 15:37:26 +0000
+++ magentoerpconnect/stock.py 2012-07-06 14:53:18 +0000
@@ -20,6 +20,10 @@
20#########################################################################20#########################################################################
2121
22import xmlrpclib22import xmlrpclib
23<<<<<<< TREE
24=======
25import logging
26>>>>>>> MERGE-SOURCE
2327
24from osv import fields,osv28from osv import fields,osv
25from tools.translate import _29from tools.translate import _
@@ -69,8 +73,13 @@
69 else:73 else:
70 item_qty.update({product_2_item[line['product_id']]: line['product_qty']})74 item_qty.update({product_2_item[line['product_id']]: line['product_qty']})
7175
76<<<<<<< TREE
72 ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, item_qty, _("Shipping Created"), mail_notification, True])77 ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, item_qty, _("Shipping Created"), mail_notification, True])
73 return ext_shipping_id78 return ext_shipping_id
79=======
80 ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, item_qty, _("Shipping Created"), mail_notification, True])
81 return ext_shipping_id
82>>>>>>> MERGE-SOURCE
7483
75 def create_ext_shipping(self, cr, uid, id, picking_type, external_referential_id, context=None):84 def create_ext_shipping(self, cr, uid, id, picking_type, external_referential_id, context=None):
76 """85 """
@@ -103,6 +112,8 @@
103 # in order to exclude it from the future exports112 # in order to exclude it from the future exports
104 if e.faultCode == 102:113 if e.faultCode == 102:
105 raise ExternalShippingCreateError(e)114 raise ExternalShippingCreateError(e)
115 else:
116 raise
106117
107 if ext_shipping_id and carrier_id:118 if ext_shipping_id and carrier_id:
108 self.add_ext_tracking_reference(cr, uid, id, carrier_id, ext_shipping_id, context)119 self.add_ext_tracking_reference(cr, uid, id, carrier_id, ext_shipping_id, context)
@@ -110,6 +121,10 @@
110121
111 def add_ext_tracking_reference(self, cr, uid, id, carrier_id, ext_shipping_id, context=None):122 def add_ext_tracking_reference(self, cr, uid, id, carrier_id, ext_shipping_id, context=None):
112 if context is None: context = {}123 if context is None: context = {}
124<<<<<<< TREE
125=======
126 logger = logging.getLogger('ext synchro')
127>>>>>>> MERGE-SOURCE
113 conn = context.get('conn_obj', False)128 conn = context.get('conn_obj', False)
114 carrier = self.pool.get('delivery.carrier').read(cr, uid, carrier_id, ['magento_carrier_code', 'magento_tracking_title'], context)129 carrier = self.pool.get('delivery.carrier').read(cr, uid, carrier_id, ['magento_carrier_code', 'magento_tracking_title'], context)
115130
@@ -120,7 +135,11 @@
120135
121 res = conn.call('sales_order_shipment.addTrack', [ext_shipping_id, carrier['magento_carrier_code'], carrier['magento_tracking_title'] or '', carrier_tracking_ref or ''])136 res = conn.call('sales_order_shipment.addTrack', [ext_shipping_id, carrier['magento_carrier_code'], carrier['magento_tracking_title'] or '', carrier_tracking_ref or ''])
122 if res:137 if res:
138<<<<<<< TREE
123 _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)139 _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)
140=======
141 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)
142>>>>>>> MERGE-SOURCE
124 return True143 return True
125144
126stock_picking()145stock_picking()
127146
=== modified file 'magentoerpconnect_payment/sale.py'
--- magentoerpconnect_payment/sale.py 2012-03-27 09:40:33 +0000
+++ magentoerpconnect_payment/sale.py 2012-07-06 14:53:18 +0000
@@ -101,6 +101,89 @@
101 self._magento_create_invoice(cr, uid, order, context=context)101 self._magento_create_invoice(cr, uid, order, context=context)
102 return True102 return True
103103
104 def _call_magento_invoice(self, cr, uid, order, order_external_data=None, context=None):
105 """Return the Magento data for all invoices
106 of an order
107
108 :param browse_record order: browsable record of sale order
109 :param dict order_external_data: magento data of the order, optional,
110 a call to magento will be done to get the data if None
111 :return: list of magento invoices as dict
112 """
113 if context is None:
114 context = {}
115
116 referential = order.shop_id.referential_id
117 connection = context.get('conn_obj') or \
118 referential.external_connection()
119
120 # Filter on order_increment_id does not work
121 # on magento.
122 # So we need first to get the order id
123 # and filter the invoice on this order id
124 if not order_external_data:
125 order_ext_id = self.oeid_to_extid(
126 cr, uid, order.id, referential.id, context=context)
127 order_external_data = connection.call(
128 'sales_order.info', [order_ext_id])
129
130 mag_order_id = order_external_data['order_id']
131 return connection.call(
132 'sales_order_invoice.list', [{'order_id': {'eq': mag_order_id}}])
133
134 def _get_missing_magento_invoice_number(self, cr, uid, order, external_data, context=None):
135 """Get the first invoice number for a magento order
136 and assign it to magento_ref fields
137 so we can later push it on the invoice
138
139 :param browse_record order: browsable record of sale order
140 :param dict external_data: magento data of the order
141 :return: invoice number of magento
142 """
143 invoice_number = False
144 mag_invoices = self._call_magento_invoice(
145 cr, uid, order, order_external_data=external_data, context=context)
146 if mag_invoices:
147 invoice_number = mag_invoices[0].get('increment_id')
148
149 if invoice_number:
150 self.write(
151 cr, uid, order.id,
152 {'magento_ref': invoice_number},
153 context=context)
154 # propagate on invoice if some exists
155 # don't care of multiplue invoice because we
156 # don't know which invoice would have
157 # which magento number, 1 invoice on magento
158 # and 1 invoice on openerp expected, otherwise
159 # it has to be manually filled
160 if order.invoice_ids:
161 inv_ids = [inv.id for inv in order.invoice_ids]
162 self.pool.get('account.invoice').write(
163 cr, uid, inv_ids,
164 {'magento_ref': invoice_number},
165 context=context)
166 return invoice_number
167
168 def create_payments(self, cr, uid, order_id, data_record, context=None):
169 """Inherited to get the magento invoice number.
170 With Magento, we are sure that when we have a payment,
171 we have an invoice, so we get its number to have it
172 on the openerp invoice
173 """
174 paid = super(sale_order, self).create_payments(
175 cr, uid, order_id, data_record, context=context)
176
177 if 'Magento' in context.get('external_referential_type', ''):
178 order = self.browse(cr, uid, order_id, context=context)
179
180 if paid and not order.magento_ref:
181 # get the invoice number
182 self._get_missing_magento_invoice_number(
183 cr, uid, order, data_record, context=context)
184
185 return paid
186
104 def _prepare_invoice(self, cr, uid, order, lines, context=None):187 def _prepare_invoice(self, cr, uid, order, lines, context=None):
105 """Prepare the dict of values to create the new invoice for a188 """Prepare the dict of values to create the new invoice for a
106 sale order. This method may be overridden to implement custom189 sale order. This method may be overridden to implement custom
@@ -123,4 +206,16 @@
123 vals['magento_ref'] = order.magento_ref206 vals['magento_ref'] = order.magento_ref
124 return vals207 return vals
125208
209 def _apply_payment_settings(self, cr, uid, order, paid, context=None):
210 """We should deactivate need_to_update to avoid to query magento
211 on each import of orders and not to mislead the users if they use
212 a filter on need_to_update.
213 """
214 res = super(sale_order, self)._apply_payment_settings(cr, uid, order,
215 paid, context=context)
216 payment_settings = order.base_payment_type_id
217 if payment_settings and payment_settings.allow_magento_manual_invoice:
218 self.write(cr, uid, order.id, {'need_to_update': False}, context=context)
219 return res
220
126sale_order()221sale_order()
127222
=== modified file 'magentoerpconnect_product_variant/product.py'
--- magentoerpconnect_product_variant/product.py 2012-04-26 21:59:20 +0000
+++ magentoerpconnect_product_variant/product.py 2012-07-06 14:53:18 +0000
@@ -86,6 +86,95 @@
86 else:86 else:
87 vals['product_type'] = 'simple'87 vals['product_type'] = 'simple'
88 return super(product_product, self).create(cr, uid, vals, context)88 return super(product_product, self).create(cr, uid, vals, context)
89<<<<<<< TREE
90=======
91
92 def action_before_exporting(self, cr, uid, id, product_type, external_referential_ids, defaults, context):
93 #When the export of a configurable product is forced we should check if all variant are already exported
94 if context.get('force_export', False) and product_type == 'configurable':
95 conn = context.get('conn_obj', False)
96 shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id'])
97 variant_ids = self.read(cr, uid, id, ['variant_ids'], context)['variant_ids']
98 variant_ids.remove(id)
99 for variant in self.browse(cr, uid, variant_ids, context=context):
100 if variant.magento_exportable:
101 if not self.oeid_to_extid(cr, uid, variant.id, shop.referential_id.id):
102 conn.logger.info("Force the export of the product %s as it was not exported before", id)
103 self.ext_export(cr, uid, [variant.id], external_referential_ids, defaults, context)
104 return True
105
106 def add_data_to_create_configurable_product(self, cr, uid, oe_id, data, context=None):
107 shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id'])
108 # check if not already created
109 products_data = {} # values of the attributes used on the element products
110 attributes_data = {} # params of the attributes to use on the configurable product
111
112 variant_ids = self.read(cr, uid, oe_id, ['variant_ids'], context=context)['variant_ids']
113 variant_ids.remove(oe_id)
114 if variant_ids:
115 associated_skus = []
116 # create a dict with all values used on the configurable products
117 for product in self.browse(cr, uid, variant_ids):
118 if product.magento_exportable:
119 associated_skus += [product.magento_sku]
120 attr_list = set()
121 # get values for each attribute of the product
122 mag_prod_id = str(self.oeid_to_extid(cr, uid, product.id, shop.referential_id.id))
123 products_data[mag_prod_id] = {}
124 index=0
125 for value in product.dimension_value_ids:
126 # get the option selected on the product
127 option = value.option_id.magento_attribut_option
128 attr = option.attribute_id
129 attr_list = attr_list.union(set([attr]))
130 prod_data = {
131 'attribute_id': attr.magento_id, # id of the attribute
132 'label': option.label, # label of the option
133 'value_index': int(option.value), # id of the option
134 'is_percent': 0, # modification of the price
135 'pricing_value': '', # modification of the price
136 }
137 #products_data[mag_prod_id][str(attribute_set.configurable_attributes.index(attr))] = prod_data
138 products_data[mag_prod_id][str(index)] = prod_data
139 index += 1
140
141 # create a dict with attributes used on the configurable product
142 index=-1
143 for attr in attr_list:
144 index += 1
145 attr_data = {
146 #'id': False,
147 'label': '',
148 #'position': False,
149 'values': [],
150 'attribute_id': attr.magento_id, # id of the attribute on magento
151 'attribute_code': attr.attribute_code, # code of the attribute on magento
152 'frontend_label': attr.frontend_label, # label of the attribute on magento
153 'html_id': "config_super_product__attribute_%s" % index, # must be config_super_product__attribute_ with an increment
154 }
155 attr_values = []
156 for prod_id in products_data:
157 [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]
158 attr_data.update({'values': attr_values})
159 attributes_data.update({str(index): attr_data})
160 data.update({'configurable_products_data': products_data, 'configurable_attributes_data': attributes_data, 'associated_skus':associated_skus})
161 return data
162
163
164 def ext_create(self, cr, uid, data, conn, method, oe_id, context):
165 if data.get('type_id', False) == 'configurable':
166 data = self.add_data_to_create_configurable_product(cr, uid, oe_id, data, context)
167 return super(product_product, self).ext_create(cr, uid, data, conn, method, oe_id, context)
168
169 def extdata_from_oevals(self, cr, uid, external_referential_id, data_record, mapping_lines, defaults, context=None):
170 #TODO maybe this mapping can be in the mapping template but the problem is that this mapping have to be apply at the end
171 #because they will overwrite other mapping result. Maybe adding a sequence on the mapping will be the solution
172 res = super(product_product, self).extdata_from_oevals(cr, uid, external_referential_id, data_record, mapping_lines, defaults, context)
173 if data_record.get('is_multi_variants', False):
174 for dim_value in self.pool.get('product.variant.dimension.value').browse(cr, uid, data_record['dimension_value_ids'], context=context):
175 res[dim_value.dimension_id.magento_attribut.attribute_code] = dim_value.option_id.magento_attribut_option.value
176 return res
177>>>>>>> MERGE-SOURCE
89 178
90 def _filter_fields_to_return(self, cr, uid, field_names, context):179 def _filter_fields_to_return(self, cr, uid, field_names, context):
91 #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 product180 #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

Subscribers

People subscribed via source and target branches