Merge lp:~gbaconnier-c2c/magentoerpconnect/magentoerpconnectv6-c2c into lp:magentoerpconnect/oerp6.0-stable
- magentoerpconnectv6-c2c
- Merge into magentoerpconnect-v6
Status: | Merged |
---|---|
Merge reported by: | Guewen Baconnier @ Camptocamp |
Merged at revision: | not available |
Proposed branch: | lp:~gbaconnier-c2c/magentoerpconnect/magentoerpconnectv6-c2c |
Merge into: | lp:magentoerpconnect/oerp6.0-stable |
Diff against target: |
412 lines (+180/-68) 6 files modified
magerp_data.xml (+22/-2) product.py (+54/-19) product_view.xml (+3/-0) sale.py (+75/-40) settings/external.mappinglines.template.csv (+9/-3) stock.py (+17/-4) |
To merge this branch: | bzr merge lp:~gbaconnier-c2c/magentoerpconnect/magentoerpconnectv6-c2c |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Raphaël Valyi - http://www.akretion.com | Pending | ||
Review via email: mp+55476@code.launchpad.net |
Commit message
Description of the change
Hi,
Here is some proposal for the connector.
Revno 396: (Rationalized import of extra sales orders lines like shipping, discount, cash on delivery,... into one single method instead of a method for each one.)
On the sale order's creation, there's a method to add shipping fees. A new method appears to add gift certificates, and there is still the case of the discount coupons and the cash on delivery fees (and maybe other fees/rebates).
The behavior is the same for each of them : get the amount in the magento's data, get a product, get a tax if a tax amount is found in the magento's data and add the line to the order.
That's why instead of having 4 methods doing nearly the same things, I propose you to use the same.
I couldn't test the gift certificate and cash on delivery because I have not them on Magento, but the shipping and discount coupons are ok. I'm also not sure with my methods definitions (I first started with one method with a loop on each type and a dict to define types, but I think the version I propose here let more space for overridings) so don't put your priority on this proposal if you have not a lot of time.
Revno 398: (include_in_menu and page_layout attributes on product categories)
Configure these 2 magento's attributes from OpenERP.
Revno 399: (hooks and small refactoring to allow management of configurable products from a module)
We are going to release our module to manage configurable products very soon (as soon as you approve the hooks in magentoerpconnect in fact).
I added a hook in the method ext_export to export configurable products, the reason is clear.
A little more explanation why I modified the method create_
When you order a configurable product in Magento, and do a "sales_order.info" on the API, it gives you 2 items : the configurable and the simple product. We put the configurable as a service, so it doesn't appear in the picking. But when you want to create the (partial) shipping on Magento, it expects the configurable and the simple product.
So I added the method "add_picking_line" which basically just add the line of the picking. But in our module, I do a super on that method and then I add a second line with the configurable product if so.
There is also a proposal on base_sale_
https:/
revno 5352 : (base_sale_
Apply a payment term on sales orders based on payment types.
I'm open to change things that bother you.
Thanks !
Guewen
- 400. By Guewen Baconnier @ CampToCamp <email address hidden>
-
[FIX] mapping for discount
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote : | # |
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
Last commit enable the translations of product categories on stores.
It correct also this bug :
- If your Magento Instance is configured with a default language of "French" and someone with an english account launch the export of catalog, or it is launched by the cron, translations are english translation instead of using the good one.
Preview Diff
1 | === modified file 'magerp_data.xml' | |||
2 | --- magerp_data.xml 2011-01-18 18:22:58 +0000 | |||
3 | +++ magerp_data.xml 2011-04-11 07:44:24 +0000 | |||
4 | @@ -14,7 +14,17 @@ | |||
5 | 14 | <field name="standard_price">0.0</field> | 14 | <field name="standard_price">0.0</field> |
6 | 15 | <field name="type">service</field> | 15 | <field name="type">service</field> |
7 | 16 | <field name="name">Shipping and Handling</field> | 16 | <field name="name">Shipping and Handling</field> |
9 | 17 | <field name="exportable" eval="False" /> | 17 | <field name="magento_exportable" eval="False" /> |
10 | 18 | <field name="categ_id" ref="mag0"/> | ||
11 | 19 | </record> | ||
12 | 20 | |||
13 | 21 | <record id="product_product_cash_on_delivery" model="product.product"> | ||
14 | 22 | <field name="default_code">CASH ON DELIVERY MAGENTO</field> | ||
15 | 23 | <field name="list_price">0.0</field> | ||
16 | 24 | <field name="standard_price">0.0</field> | ||
17 | 25 | <field name="type">service</field> | ||
18 | 26 | <field name="name">Cash on delivery</field> | ||
19 | 27 | <field name="magento_exportable" eval="False" /> | ||
20 | 18 | <field name="categ_id" ref="mag0"/> | 28 | <field name="categ_id" ref="mag0"/> |
21 | 19 | </record> | 29 | </record> |
22 | 20 | 30 | ||
23 | @@ -24,10 +34,20 @@ | |||
24 | 24 | <field name="standard_price">0.0</field> | 34 | <field name="standard_price">0.0</field> |
25 | 25 | <field name="type">service</field> | 35 | <field name="type">service</field> |
26 | 26 | <field name="name">Gift Certificate</field> | 36 | <field name="name">Gift Certificate</field> |
28 | 27 | <field name="exportable" eval="False" /> | 37 | <field name="magento_exportable" eval="False" /> |
29 | 28 | <field name="categ_id" ref="mag0"/> | 38 | <field name="categ_id" ref="mag0"/> |
30 | 29 | </record> | 39 | </record> |
31 | 30 | 40 | ||
32 | 41 | <record id="product_product_discount" model="product.product"> | ||
33 | 42 | <field name="default_code">DISCOUNT MAGENTO</field> | ||
34 | 43 | <field name="list_price">0.0</field> | ||
35 | 44 | <field name="standard_price">0.0</field> | ||
36 | 45 | <field name="type">service</field> | ||
37 | 46 | <field name="name">Discount coupon</field> | ||
38 | 47 | <field name="magento_exportable" eval="False" /> | ||
39 | 48 | <field name="categ_id" ref="mag0"/> | ||
40 | 49 | </record> | ||
41 | 50 | |||
42 | 31 | <record forcecreate="True" id="ir_cron_import_orders_scheduler_action" model="ir.cron"> | 51 | <record forcecreate="True" id="ir_cron_import_orders_scheduler_action" model="ir.cron"> |
43 | 32 | <field name="name">Magento Import Orders</field> | 52 | <field name="name">Magento Import Orders</field> |
44 | 33 | <field eval="False" name="active"/> | 53 | <field eval="False" name="active"/> |
45 | 34 | 54 | ||
46 | === modified file 'product.py' | |||
47 | --- product.py 2011-03-10 10:36:25 +0000 | |||
48 | +++ product.py 2011-04-11 07:44:24 +0000 | |||
49 | @@ -75,13 +75,24 @@ | |||
50 | 75 | ('name', 'Name'), | 75 | ('name', 'Name'), |
51 | 76 | ('price', 'Price') | 76 | ('price', 'Price') |
52 | 77 | ], 'Default Product Listing Sort (Sort By)'), | 77 | ], 'Default Product Listing Sort (Sort By)'), |
54 | 78 | 'magerp_stamp':fields.datetime('Magento stamp') | 78 | 'magerp_stamp':fields.datetime('Magento stamp'), |
55 | 79 | 'include_in_menu': fields.boolean('Include in Navigation Menu'), | ||
56 | 80 | 'page_layout': fields.selection([ | ||
57 | 81 | ('None', 'No layout updates'), | ||
58 | 82 | ('empty', 'Empty'), | ||
59 | 83 | ('one_column', '1 column'), | ||
60 | 84 | ('two_columns_left', '2 columns with left bar'), | ||
61 | 85 | ('two_columns_right', '2 columns with right bar'), | ||
62 | 86 | ('three_columns', '3 columns'), | ||
63 | 87 | ], 'Page Layout'), | ||
64 | 79 | } | 88 | } |
65 | 80 | _defaults = { | 89 | _defaults = { |
66 | 81 | 'display_mode':lambda * a:'PRODUCTS', | 90 | 'display_mode':lambda * a:'PRODUCTS', |
67 | 82 | 'available_sort_by':lambda * a:'None', | 91 | 'available_sort_by':lambda * a:'None', |
68 | 83 | 'default_sort_by':lambda * a:'None', | 92 | 'default_sort_by':lambda * a:'None', |
70 | 84 | 'level':lambda * a:1 | 93 | 'level':lambda * a:1, |
71 | 94 | 'include_in_menu': lambda * a:True, | ||
72 | 95 | 'page_layout': lambda * a:'None' | ||
73 | 85 | } | 96 | } |
74 | 86 | 97 | ||
75 | 87 | def write(self, cr, uid, ids, vals, context=None): | 98 | def write(self, cr, uid, ids, vals, context=None): |
76 | @@ -114,27 +125,45 @@ | |||
77 | 114 | ids = [id for id in ids if id in ids_exportable] #we need to kept the order of the categories | 125 | ids = [id for id in ids if id in ids_exportable] #we need to kept the order of the categories |
78 | 115 | 126 | ||
79 | 116 | shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id']) | 127 | shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id']) |
81 | 117 | 128 | ||
82 | 129 | context_dic = [context.copy()] | ||
83 | 130 | 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 | ||
84 | 131 | context_dic[0]['lang'] = shop.referential_id.default_lang_id.code | ||
85 | 132 | |||
86 | 133 | for storeview in shop.storeview_ids: | ||
87 | 134 | if storeview.lang_id and storeview.lang_id.code != shop.referential_id.default_lang_id.code: | ||
88 | 135 | context_dic += [context.copy()] | ||
89 | 136 | context_dic[len(context_dic)-1].update({'storeview_code': storeview.code, 'lang': storeview.lang_id.code}) | ||
90 | 137 | |||
91 | 118 | if shop.last_products_export_date: | 138 | if shop.last_products_export_date: |
92 | 119 | last_exported_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(shop.last_products_export_date, '%Y-%m-%d %H:%M:%S'))) | 139 | last_exported_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(shop.last_products_export_date, '%Y-%m-%d %H:%M:%S'))) |
93 | 120 | else: | 140 | else: |
94 | 121 | last_exported_time = False | 141 | last_exported_time = False |
109 | 122 | 142 | ||
110 | 123 | cr.execute("select write_date, create_date from product_category where id in %s", (tuple(ids),)) | 143 | if not last_exported_time: |
111 | 124 | read = cr.fetchall() | 144 | for ctx_storeview in context_dic: |
112 | 125 | for categ in read: | 145 | ctx_storeview['force'] = True |
113 | 126 | last_updated_categ = categ[0] and categ[0].split('.')[0] or categ[1] and categ[1].split('.')[0] or False | 146 | res = super(product_category, self).ext_export(cr, uid, ids, external_referential_ids, defaults, ctx_storeview) |
114 | 127 | last_updated_categ_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(last_updated_categ, '%Y-%m-%d %H:%M:%S'))) | 147 | else: |
115 | 128 | if last_updated_categ_time and last_exported_time: | 148 | cr.execute("select write_date, create_date from product_category where id in %s", (tuple(ids),)) |
116 | 129 | if last_exported_time - datetime.timedelta(seconds=1) < last_updated_categ_time: | 149 | read = cr.fetchall() |
117 | 130 | context['force'] = True | 150 | for categ in read: |
118 | 131 | res = super(product_category, self).ext_export(cr, uid, ids, external_referential_ids, defaults, context) | 151 | last_updated_categ = categ[0] and categ[0].split('.')[0] or categ[1] and categ[1].split('.')[0] or False |
119 | 132 | break | 152 | last_updated_categ_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(last_updated_categ, '%Y-%m-%d %H:%M:%S'))) |
120 | 133 | if not res: | 153 | if last_updated_categ_time and last_exported_time: |
121 | 134 | context['force'] = True | 154 | if last_exported_time - datetime.timedelta(seconds=1) < last_updated_categ_time: |
122 | 135 | res = super(product_category, self).ext_export(cr, uid, ids, external_referential_ids, defaults, context) | 155 | for ctx_storeview in context_dic: |
123 | 156 | ctx_storeview['force'] = True | ||
124 | 157 | res = super(product_category, self).ext_export(cr, uid, ids, external_referential_ids, defaults, ctx_storeview) | ||
125 | 158 | break | ||
126 | 136 | return res | 159 | return res |
128 | 137 | 160 | ||
129 | 161 | def try_ext_update(self, cr, uid, data, conn, method, oe_id, external_id, ir_model_data_id, create_method, context): | ||
130 | 162 | if context.get('storeview_code', False): | ||
131 | 163 | return conn.call(method, [external_id, data, context.get('storeview_code', False)]) | ||
132 | 164 | else: | ||
133 | 165 | return conn.call(method, [external_id, data]) | ||
134 | 166 | |||
135 | 138 | product_category() | 167 | product_category() |
136 | 139 | 168 | ||
137 | 140 | 169 | ||
138 | @@ -899,7 +928,10 @@ | |||
139 | 899 | res = super(magerp_osv.magerp_osv, self).ext_create(cr, uid, [product_type, attr_set_id, sku, data], conn, method, oe_id, context) | 928 | res = super(magerp_osv.magerp_osv, self).ext_create(cr, uid, [product_type, attr_set_id, sku, data], conn, method, oe_id, context) |
140 | 900 | self.write(cr, uid, oe_id, {'magento_sku': sku}) | 929 | self.write(cr, uid, oe_id, {'magento_sku': sku}) |
141 | 901 | return res | 930 | return res |
143 | 902 | 931 | ||
144 | 932 | def ext_export_configurable(self, cr, uid, id, external_referential_ids=None, defaults=None, context=None): | ||
145 | 933 | raise osv.except_osv(_("Not Implemented"), _("Configurable products are not implemented.")) | ||
146 | 934 | |||
147 | 903 | def ext_export(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None): | 935 | def ext_export(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None): |
148 | 904 | if context is None: | 936 | if context is None: |
149 | 905 | context = {} | 937 | context = {} |
150 | @@ -999,6 +1031,8 @@ | |||
151 | 999 | self.ext_export(cr, uid, child_ids, external_referential_ids, defaults, context) #so we export them | 1031 | self.ext_export(cr, uid, child_ids, external_referential_ids, defaults, context) #so we export them |
152 | 1000 | else: | 1032 | else: |
153 | 1001 | logger.notifyChannel('ext synchro', netsvc.LOG_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") | 1033 | logger.notifyChannel('ext synchro', netsvc.LOG_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") |
154 | 1034 | elif product_type == 'configurable': | ||
155 | 1035 | self.ext_export_configurable(cr, uid, id, external_referential_ids, defaults, context) | ||
156 | 1002 | for context_storeview in context_dic: | 1036 | for context_storeview in context_dic: |
157 | 1003 | temp_result = super(magerp_osv.magerp_osv, self).ext_export(cr, uid, [id], external_referential_ids, defaults, context_storeview) | 1037 | temp_result = super(magerp_osv.magerp_osv, self).ext_export(cr, uid, [id], external_referential_ids, defaults, context_storeview) |
158 | 1004 | if child_ids: | 1038 | if child_ids: |
159 | @@ -1030,6 +1064,7 @@ | |||
160 | 1030 | is_in_stock = int(virtual_available > 0) | 1064 | is_in_stock = int(virtual_available > 0) |
161 | 1031 | context['conn_obj'].call('product_stock.update', [product.magento_sku, {'qty': virtual_available, 'is_in_stock': is_in_stock}]) | 1065 | context['conn_obj'].call('product_stock.update', [product.magento_sku, {'qty': virtual_available, 'is_in_stock': is_in_stock}]) |
162 | 1032 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Successfully updated stock level at %s for product with SKU %s " %(virtual_available, product.magento_sku)) | 1066 | logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Successfully updated stock level at %s for product with SKU %s " %(virtual_available, product.magento_sku)) |
163 | 1067 | return True | ||
164 | 1033 | 1068 | ||
165 | 1034 | def ext_grouped_product_assign(self, cr, uid, parent_id, child_ids, quantities, context): | 1069 | def ext_grouped_product_assign(self, cr, uid, parent_id, child_ids, quantities, context): |
166 | 1035 | logger = netsvc.Logger() | 1070 | logger = netsvc.Logger() |
167 | 1036 | 1071 | ||
168 | === modified file 'product_view.xml' | |||
169 | --- product_view.xml 2011-03-18 16:31:46 +0000 | |||
170 | +++ product_view.xml 2011-04-11 07:44:24 +0000 | |||
171 | @@ -22,6 +22,7 @@ | |||
172 | 22 | <field name="meta_description" colspan="2" /> | 22 | <field name="meta_description" colspan="2" /> |
173 | 23 | <field name="url_key" colspan="2" /> | 23 | <field name="url_key" colspan="2" /> |
174 | 24 | <field name="level" colspan="2" /> | 24 | <field name="level" colspan="2" /> |
175 | 25 | <field name="include_in_menu" colspan="2" /> | ||
176 | 25 | </group> | 26 | </group> |
177 | 26 | <group col="1" colspan="1"> | 27 | <group col="1" colspan="1"> |
178 | 27 | <separator string="Category Image" /> | 28 | <separator string="Category Image" /> |
179 | @@ -51,6 +52,8 @@ | |||
180 | 51 | <separator string="Sorting method" colspan="4" /> | 52 | <separator string="Sorting method" colspan="4" /> |
181 | 52 | <field name="available_sort_by" /> | 53 | <field name="available_sort_by" /> |
182 | 53 | <field name="default_sort_by" /> | 54 | <field name="default_sort_by" /> |
183 | 55 | <separator string="Page Layout" colspan="4" /> | ||
184 | 56 | <field name="page_layout" nolabel="1" /> | ||
185 | 54 | </page> | 57 | </page> |
186 | 55 | </notebook> | 58 | </notebook> |
187 | 56 | </group> | 59 | </group> |
188 | 57 | 60 | ||
189 | === modified file 'sale.py' | |||
190 | --- sale.py 2011-04-02 14:58:57 +0000 | |||
191 | +++ sale.py 2011-04-11 07:44:24 +0000 | |||
192 | @@ -384,49 +384,83 @@ | |||
193 | 384 | res['order_line'] = lines_vals | 384 | res['order_line'] = lines_vals |
194 | 385 | return res | 385 | return res |
195 | 386 | 386 | ||
224 | 387 | def add_gift_certificates(self, cursor, user, order_values, | 387 | def add_order_extra_line(self, cr, uid, res, data_record, ext_field, product_code, context): |
225 | 388 | magento_order_data, context): | 388 | """ Add or substract amount on order as a separate line item with single quantity for each type of amounts like : |
226 | 389 | '''Add gift certificate as a separate line item with single quantity | 389 | shipping, cash on delivery, discount, gift certificates... |
227 | 390 | and negative amount. Known to work with Unigry gift certificates also | 390 | Arguments : |
228 | 391 | ''' | 391 | ext_field: name of the field in data_record where the amount is stored |
229 | 392 | product_obj = self.pool.get('product.product') | 392 | product_code: code of the product to use in the sale order line |
230 | 393 | if ('giftcert_amount' in magento_order_data) and \ | 393 | Optional arguments in kwargs: |
231 | 394 | (float(magento_order_data.get('giftcert_amount', 0)) > 0): | 394 | sign: multiply the amount with the sign to add or substract it from the sale order |
232 | 395 | gift_product_ids = product_obj.search(cursor, user, | 395 | ext_tax_field: name of the field in data_record where the tax amount is stored |
233 | 396 | [('default_code', '=', 'GIFT CERTIFICATE')], context=context) | 396 | 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 |
234 | 397 | if gift_product_ids: | 397 | """ |
235 | 398 | gift_product = product_obj.browse( | 398 | sign = 'sign' in context and context['sign'] or 1 |
236 | 399 | cursor, user, gift_product_ids[0], context) | 399 | ext_tax_field = 'ext_tax_field' in context and context['ext_tax_field'] or None |
237 | 400 | gift_cert_code = magento_order_data['giftcert_code'] | 400 | ext_code_field = 'ext_code_field' in context and context['ext_code_field'] or None |
238 | 401 | order_values['order_line'].append((0, 0, { | 401 | |
239 | 402 | 'product_id': gift_product.id, | 402 | product_id = self.pool.get('product.product').search(cr, uid, [('default_code', '=', product_code)])[0] |
240 | 403 | 'name': 'Gift Certificate %s' % gift_cert_code, | 403 | product = self.pool.get('product.product').browse(cr, uid, product_id, context) |
241 | 404 | 'product_uom': gift_product.uom_id.id, | 404 | amount = float(data_record[ext_field]) * sign |
242 | 405 | 'product_uom_qty': 1, | 405 | |
215 | 406 | 'price_unit': -float(magento_order_data['giftcert_amount']), | ||
216 | 407 | })) | ||
217 | 408 | return order_values | ||
218 | 409 | |||
219 | 410 | def get_order_shipping(self, cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context): | ||
220 | 411 | ship_product_id = self.pool.get('product.product').search(cr, uid, [('default_code', '=', 'SHIP MAGENTO')])[0] | ||
221 | 412 | ship_product = self.pool.get('product.product').browse(cr, uid, ship_product_id, context) | ||
222 | 413 | |||
223 | 414 | #simple VAT tax on shipping (else override method): | ||
243 | 415 | tax_id = [] | 406 | tax_id = [] |
249 | 416 | if data_record['shipping_tax_amount'] and float(data_record['shipping_tax_amount']) != 0: | 407 | if ext_tax_field: |
250 | 417 | ship_tax_vat = float(data_record['shipping_tax_amount'])/float(data_record['shipping_amount']) | 408 | if data_record[ext_tax_field] and float(data_record[ext_tax_field]) != 0: |
251 | 418 | ship_tax_ids = self.pool.get('account.tax').search(cr, uid, [('type_tax_use', '=', 'sale'), ('amount', '>=', ship_tax_vat - 0.001), ('amount', '<=', ship_tax_vat + 0.001)]) | 409 | tax_vat = abs(float(data_record[ext_tax_field]) / amount) |
252 | 419 | if ship_tax_ids and len(ship_tax_ids) > 0: | 410 | tax_ids = self.pool.get('account.tax').search(cr, uid, [('type_tax_use', '=', 'sale'), ('amount', '>=', tax_vat - 0.001), ('amount', '<=', tax_vat + 0.001)]) |
253 | 420 | tax_id = [(6, 0, [ship_tax_ids[0]])] | 411 | if tax_ids and len(tax_ids) > 0: |
254 | 412 | tax_id = [(6, 0, [tax_ids[0]])] | ||
255 | 413 | |||
256 | 414 | name = product.name | ||
257 | 415 | if ext_code_field and data_record.get(ext_code_field, False): | ||
258 | 416 | name = "%s [%s]" % (name, data_record[ext_code_field]) | ||
259 | 417 | |||
260 | 421 | res['order_line'].append((0, 0, { | 418 | res['order_line'].append((0, 0, { |
264 | 422 | 'product_id': ship_product.id, | 419 | 'product_id': product.id, |
265 | 423 | 'name': ship_product.name, | 420 | 'name': name, |
266 | 424 | 'product_uom': ship_product.uom_id.id, | 421 | 'product_uom': product.uom_id.id, |
267 | 425 | 'product_uom_qty': 1, | 422 | 'product_uom_qty': 1, |
269 | 426 | 'price_unit': float(data_record['shipping_amount']), | 423 | 'price_unit': amount, |
270 | 427 | 'tax_id': tax_id | 424 | 'tax_id': tax_id |
271 | 428 | })) | 425 | })) |
272 | 429 | return res | 426 | return res |
273 | 427 | |||
274 | 428 | def add_order_shipping(self, cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context): | ||
275 | 429 | if data_record.get('shipping_amount', False) and float(data_record.get('shipping_amount', False)) > 0: | ||
276 | 430 | ctx = context.copy() | ||
277 | 431 | ctx.update({ | ||
278 | 432 | 'ext_tax_field': 'shipping_tax_amount', | ||
279 | 433 | }) | ||
280 | 434 | res = self.add_order_extra_line(cr, uid, res, data_record, 'shipping_amount', 'SHIP MAGENTO', ctx) | ||
281 | 435 | return res | ||
282 | 436 | |||
283 | 437 | def add_gift_certificates(self, cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context): | ||
284 | 438 | if data_record.get('giftcert_amount', False) and float(data_record.get('giftcert_amount', False)) > 0: | ||
285 | 439 | ctx = context.copy() | ||
286 | 440 | ctx.update({ | ||
287 | 441 | 'ext_code_field': 'giftcert_code', | ||
288 | 442 | 'sign': -1, | ||
289 | 443 | }) | ||
290 | 444 | res = self.add_order_extra_line(cr, uid, res, data_record, 'giftcert_amount', 'GIFT CERTIFICATE', ctx) | ||
291 | 445 | return res | ||
292 | 446 | |||
293 | 447 | def add_discount(self, cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context): | ||
294 | 448 | if data_record.get('discount_amount', False) and float(data_record.get('discount_amount', False)) < 0: | ||
295 | 449 | ctx = context.copy() | ||
296 | 450 | ctx.update({ | ||
297 | 451 | 'ext_code_field': 'coupon_code', | ||
298 | 452 | }) | ||
299 | 453 | res = self.add_order_extra_line(cr, uid, res, data_record, 'discount_amount', 'DISCOUNT MAGENTO', ctx) | ||
300 | 454 | return res | ||
301 | 455 | |||
302 | 456 | def add_cash_on_delivery(self, cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context): | ||
303 | 457 | if data_record.get('cod_fee', False) and float(data_record.get('cod_fee', False)) > 0: | ||
304 | 458 | ctx = context.copy() | ||
305 | 459 | ctx.update({ | ||
306 | 460 | 'ext_tax_field': 'cod_tax_amount', | ||
307 | 461 | }) | ||
308 | 462 | res = self.add_order_extra_line(cr, uid, res, data_record, 'cod_fee', 'CASH ON DELIVERY MAGENTO', ctx) | ||
309 | 463 | return res | ||
310 | 430 | 464 | ||
311 | 431 | def oevals_from_extdata(self, cr, uid, external_referential_id, data_record, key_field, mapping_lines, defaults, context): | 465 | def oevals_from_extdata(self, cr, uid, external_referential_id, data_record, key_field, mapping_lines, defaults, context): |
312 | 432 | if not context.get('one_by_one', False): | 466 | if not context.get('one_by_one', False): |
313 | @@ -439,9 +473,10 @@ | |||
314 | 439 | if data_record.get('items', False): | 473 | if data_record.get('items', False): |
315 | 440 | try: | 474 | try: |
316 | 441 | res = self.get_order_lines(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context) | 475 | res = self.get_order_lines(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context) |
320 | 442 | if data_record.get('shipping_amount', False) and float(data_record.get('shipping_amount', False)) > 0: | 476 | res = self.add_order_shipping(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context) |
321 | 443 | res = self.get_order_shipping(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context) | 477 | res = self.add_gift_certificates(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context) |
322 | 444 | res = self.add_gift_certificates(cr, uid, res, data_record, context) | 478 | res = self.add_discount(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context) |
323 | 479 | res = self.add_cash_on_delivery(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context) | ||
324 | 445 | except Exception, e: | 480 | except Exception, e: |
325 | 446 | print "order has errors with items lines, data are: ", data_record | 481 | print "order has errors with items lines, data are: ", data_record |
326 | 447 | print e | 482 | print e |
327 | 448 | 483 | ||
328 | === modified file 'settings/external.mappinglines.template.csv' | |||
329 | --- settings/external.mappinglines.template.csv 2010-12-14 21:01:23 +0000 | |||
330 | +++ settings/external.mappinglines.template.csv 2011-04-11 07:44:24 +0000 | |||
331 | @@ -35,7 +35,7 @@ | |||
332 | 35 | "mag_erp_soline_uomqty","magento1324","sale.model_sale_order_line","qty_ordered","in_out","str","result=[('product_uom_qty',ifield)]", | 35 | "mag_erp_soline_uomqty","magento1324","sale.model_sale_order_line","qty_ordered","in_out","str","result=[('product_uom_qty',ifield)]", |
333 | 36 | "mag_erp_soline_uosqty","magento1324","sale.model_sale_order_line","qty_ordered","in","str","result=[('product_uos_qty',ifield)]", | 36 | "mag_erp_soline_uosqty","magento1324","sale.model_sale_order_line","qty_ordered","in","str","result=[('product_uos_qty',ifield)]", |
334 | 37 | "mag_erp_soline_price","magento1324","sale.model_sale_order_line","price","in","str","result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]", | 37 | "mag_erp_soline_price","magento1324","sale.model_sale_order_line","price","in","str","result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]", |
336 | 38 | "mag_erp_soline_disc","magento1324","sale.model_sale_order_line","discount_amount","in","str","result=[('discount', float(data['price']) != 0 and float(data['qty_ordered']) != 0 and float(100*float(ifield))/(float(data['price'])*float(data['qty_ordered'])) or 0)]", | 38 | "mag_erp_soline_disc","magento1324","sale.model_sale_order_line","discount_amount","in","str","result=[('discount', 0.0)]", |
337 | 39 | "mag_erp_procat_2","magento1324","product.model_product_category","level","in","int","result=[('sequence',ifield),('level',ifield)]", | 39 | "mag_erp_procat_2","magento1324","product.model_product_category","level","in","int","result=[('sequence',ifield),('level',ifield)]", |
338 | 40 | "mag_erp_procat_3","magento1324","product.model_product_category","parent_id","in_out","int","record_id = self.pool.get('ir.model.data').search(cr, uid, [('model', '=', self._name), ('name', '=', self.prefixed_id(ifield))]) | 40 | "mag_erp_procat_3","magento1324","product.model_product_category","parent_id","in_out","int","record_id = self.pool.get('ir.model.data').search(cr, uid, [('model', '=', self._name), ('name', '=', self.prefixed_id(ifield))]) |
339 | 41 | parent_id = False | 41 | parent_id = False |
340 | @@ -46,7 +46,7 @@ | |||
341 | 46 | if record.get('parent_id',False): | 46 | if record.get('parent_id',False): |
342 | 47 | magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) | 47 | magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) |
343 | 48 | if not magento_parent_id: | 48 | if not magento_parent_id: |
345 | 49 | self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[external_referential_id],{},{'conn_obj':conn}) | 49 | self.ext_export(cr,uid,[record.get('parent_id',[False])[0]],[external_referential_id],{},context=context) |
346 | 50 | magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) | 50 | magento_parent_id = self.oeid_to_extid(cr, uid, record.get('parent_id')[0], external_referential_id) |
347 | 51 | if magento_parent_id: | 51 | if magento_parent_id: |
348 | 52 | result = [('parent_id',magento_parent_id)]" | 52 | result = [('parent_id',magento_parent_id)]" |
349 | @@ -55,7 +55,8 @@ | |||
350 | 55 | "mag_erp_procat_6","magento1324","product.model_product_category","meta_title","in_out","str","result=[('meta_title',ifield)]","result=[('meta_title',record['meta_title'])]" | 55 | "mag_erp_procat_6","magento1324","product.model_product_category","meta_title","in_out","str","result=[('meta_title',ifield)]","result=[('meta_title',record['meta_title'])]" |
351 | 56 | "mag_erp_procat_7","magento1324","product.model_product_category","meta_keywords","in_out","str","result=[('meta_keywords',ifield)]","result=[('meta_keywords',record['meta_keywords'])]" | 56 | "mag_erp_procat_7","magento1324","product.model_product_category","meta_keywords","in_out","str","result=[('meta_keywords',ifield)]","result=[('meta_keywords',record['meta_keywords'])]" |
352 | 57 | "mag_erp_procat_8","magento1324","product.model_product_category","meta_description","in_out","str","result=[('meta_description',ifield)]","result=[('meta_description',record['meta_description'])]" | 57 | "mag_erp_procat_8","magento1324","product.model_product_category","meta_description","in_out","str","result=[('meta_description',ifield)]","result=[('meta_description',record['meta_description'])]" |
354 | 58 | "mag_erp_procat_9","magento1324","product.model_product_category","url_key","in_out","str","result=[('url_key',ifield)]","result=[('url_key',record['url_key'])]" | 58 | "mag_erp_procat_9","magento1324","product.model_product_category","url_key","in_out","str","result=[('url_key',ifield)]","if context.get('export_url', False) : |
355 | 59 | result=[('url_key',record['url_key'])]" | ||
356 | 59 | "mag_erp_procat_10","magento1324","product.model_product_category","name","in_out","str","result=[('name',ifield or 'UNDEFINED'),('magento_exportable',True)]","result=[('name',record['name'])]" | 60 | "mag_erp_procat_10","magento1324","product.model_product_category","name","in_out","str","result=[('name',ifield or 'UNDEFINED'),('magento_exportable',True)]","result=[('name',record['name'])]" |
357 | 60 | "mag_erp_procat_11","magento1324","product.model_product_category","is_anchor","in_out","str","result=[('is_anchor',ifield and bool(eval(ifield)) or False)]","result=[('is_anchor',record['is_anchor'])]" | 61 | "mag_erp_procat_11","magento1324","product.model_product_category","is_anchor","in_out","str","result=[('is_anchor',ifield and bool(eval(ifield)) or False)]","result=[('is_anchor',record['is_anchor'])]" |
358 | 61 | "mag_erp_procat_12","magento1324","product.model_product_category","available_sort_by","in_out","str","result=[('available_sort_by',ifield)]","result=[('available_sort_by',record['available_sort_by'] or 'name')]" | 62 | "mag_erp_procat_12","magento1324","product.model_product_category","available_sort_by","in_out","str","result=[('available_sort_by',ifield)]","result=[('available_sort_by',record['available_sort_by'] or 'name')]" |
359 | @@ -77,6 +78,11 @@ | |||
360 | 77 | result = [('image',record['image_name'])] | 78 | result = [('image',record['image_name'])] |
361 | 78 | else: | 79 | else: |
362 | 79 | result=[]" | 80 | result=[]" |
363 | 81 | "mag_erp_procat_16","magento1324","product.model_product_category","include_in_menu","in_out","str","result=[('include_in_menu', ifield and (eval(ifield)) or False)]","result=[('include_in_menu',record['include_in_menu'])]" | ||
364 | 82 | "mag_erp_procat_17","magento1324","product.model_product_category","page_layout","in_out","str","if ifield: | ||
365 | 83 | result=[('page_layout',ifield)] | ||
366 | 84 | else: | ||
367 | 85 | result=[('page_layout','None')]","result=[('page_layout', record['page_layout'] or '')]" | ||
368 | 80 | "mag_erp_attrgrp_2","magento1324","model_magerp_product_attribute_groups","attribute_set_id","in_out","int","result=[('attribute_set_id', ifield)]","result=[('attribute_set_id', record['attribute_set_id'])]" | 86 | "mag_erp_attrgrp_2","magento1324","model_magerp_product_attribute_groups","attribute_set_id","in_out","int","result=[('attribute_set_id', ifield)]","result=[('attribute_set_id', record['attribute_set_id'])]" |
369 | 81 | "mag_erp_attrgrp_3","magento1324","model_magerp_product_attribute_groups","attribute_group_name","in_out","str","result=[('attribute_group_name', ifield)]","result=[('attribute_group_name', record['attribute_group_name'])]" | 87 | "mag_erp_attrgrp_3","magento1324","model_magerp_product_attribute_groups","attribute_group_name","in_out","str","result=[('attribute_group_name', ifield)]","result=[('attribute_group_name', record['attribute_group_name'])]" |
370 | 82 | "mag_erp_attrgrp_4","magento1324","model_magerp_product_attribute_groups","sort_order","in_out","int","result=[('sort_order', ifield)]","result=[('sort_order', record['sort_order'])]" | 88 | "mag_erp_attrgrp_4","magento1324","model_magerp_product_attribute_groups","sort_order","in_out","int","result=[('sort_order', ifield)]","result=[('sort_order', record['sort_order'])]" |
371 | 83 | 89 | ||
372 | === modified file 'stock.py' | |||
373 | --- stock.py 2010-11-15 20:46:10 +0000 | |||
374 | +++ stock.py 2011-04-11 07:44:24 +0000 | |||
375 | @@ -35,8 +35,15 @@ | |||
376 | 35 | ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, {}, _("Shipping Created"), True, True]) | 35 | ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, {}, _("Shipping Created"), True, True]) |
377 | 36 | except Exception, e: | 36 | except Exception, e: |
378 | 37 | logger.notifyChannel(_("Magento Call"), netsvc.LOG_ERROR, _("The picking from the order %s can't be created on Magento, please attach it manually, %s") % (magento_incrementid, e)) | 37 | logger.notifyChannel(_("Magento Call"), netsvc.LOG_ERROR, _("The picking from the order %s can't be created on Magento, please attach it manually, %s") % (magento_incrementid, e)) |
380 | 38 | return ext_shipping_id | 38 | return ext_shipping_id |
381 | 39 | 39 | ||
382 | 40 | def add_picking_line(self, cr, uid, lines, picking_line, context): | ||
383 | 41 | """ A line to add in the shipping is a dict with : product_id and product_qty keys.""" | ||
384 | 42 | line_info = {'product_id': picking_line.product_id.id, | ||
385 | 43 | 'product_qty': picking_line.product_qty, | ||
386 | 44 | } | ||
387 | 45 | lines.append(line_info) | ||
388 | 46 | return lines | ||
389 | 40 | 47 | ||
390 | 41 | def create_ext_partial_shipping(self, cr, uid, id, external_referential_id, magento_incrementid, context): | 48 | def create_ext_partial_shipping(self, cr, uid, id, external_referential_id, magento_incrementid, context): |
391 | 42 | logger = netsvc.Logger() | 49 | logger = netsvc.Logger() |
392 | @@ -48,11 +55,17 @@ | |||
393 | 48 | product_2_item.update({self.pool.get('product.product').extid_to_oeid(cr, uid, item['product_id'], external_referential_id, context={}): item['item_id']}) | 55 | product_2_item.update({self.pool.get('product.product').extid_to_oeid(cr, uid, item['product_id'], external_referential_id, context={}): item['item_id']}) |
394 | 49 | picking = self.pool.get('stock.picking').browse(cr, uid, id, context) | 56 | picking = self.pool.get('stock.picking').browse(cr, uid, id, context) |
395 | 50 | item_qty = {} | 57 | item_qty = {} |
396 | 58 | |||
397 | 59 | lines = [] | ||
398 | 60 | # get product and quantities to ship from the picking | ||
399 | 51 | for line in picking.move_lines: | 61 | for line in picking.move_lines: |
402 | 52 | if item_qty.get(product_2_item[line.product_id.id], False): | 62 | lines = self.add_picking_line(cr, uid, lines, line, context) |
403 | 53 | item_qty[product_2_item[line.product_id.id]] += line.product_qty | 63 | |
404 | 64 | for line in lines: | ||
405 | 65 | if item_qty.get(product_2_item[line['product_id']], False): | ||
406 | 66 | item_qty[product_2_item[line['product_id']]] += line['product_qty'] | ||
407 | 54 | else: | 67 | else: |
409 | 55 | item_qty.update({product_2_item[line.product_id.id]:line.product_qty}) | 68 | item_qty.update({product_2_item[line['product_id']]: line['product_qty']}) |
410 | 56 | try: | 69 | try: |
411 | 57 | ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, item_qty, _("Shipping Created"), True, True]) | 70 | ext_shipping_id = conn.call('sales_order_shipment.create', [magento_incrementid, item_qty, _("Shipping Created"), True, True]) |
412 | 58 | except Exception, e: | 71 | except Exception, e: |
Seems Good Guewen! multichannels thing and we will merge the other part as soon as we can. Thank you very much, always a pleasure to get all those improvements from CampToCamp.
Sebastien already merged the base_sale_