Merge lp:~albert-nan/magentoerpconnect/NaN into lp:~magentoerpconnect-core-editors/magentoerpconnect/magentoerpconnect_generic

Status: Needs review
Proposed branch: lp:~albert-nan/magentoerpconnect/NaN
Merge into: lp:~magentoerpconnect-core-editors/magentoerpconnect/magentoerpconnect_generic
Diff against target: 708 lines (+271/-75)
11 files modified
__init__.py (+3/-2)
__terp__.py (+2/-0)
country.py (+39/-0)
country_view.xml (+38/-0)
invoice.py (+10/-5)
magerp_core.py (+1/-1)
magerp_osv.py (+20/-3)
product.py (+17/-9)
sale.py (+89/-30)
sale_view.xml (+15/-2)
settings/external.mappinglines.template.csv (+37/-23)
To merge this branch: bzr merge lp:~albert-nan/magentoerpconnect/NaN
Reviewer Review Type Date Requested Status
MagentoERPConnect core editors Pending
Review via email: mp+22765@code.launchpad.net

Description of the change

Ensure 'None' is never used as it's not serializable with XML-RPC protocol.

To post a comment you must log in.
lp:~albert-nan/magentoerpconnect/NaN updated
298. By Albert Cervera i Areny - http://www.NaN-tic.com

[IMP] Several changes including:
- Added country to taxes.
- Added hability to import invoice numbers.

299. By Albert Cervera i Areny - http://www.NaN-tic.com

Removed 'mag_' prefix in sale.order

300. By Albert Cervera i Areny - http://www.NaN-tic.com

Ensure product.product -> export_inventory() function does not return 'None' but 'False'.

301. By Albert Cervera i Areny - http://www.NaN-tic.com

Mergeed latest trunk changes.

302. By Albert Cervera i Areny - http://www.NaN-tic.com

Added context to several calls.

Unmerged revisions

302. By Albert Cervera i Areny - http://www.NaN-tic.com

Added context to several calls.

301. By Albert Cervera i Areny - http://www.NaN-tic.com

Mergeed latest trunk changes.

300. By Albert Cervera i Areny - http://www.NaN-tic.com

Ensure product.product -> export_inventory() function does not return 'None' but 'False'.

299. By Albert Cervera i Areny - http://www.NaN-tic.com

Removed 'mag_' prefix in sale.order

298. By Albert Cervera i Areny - http://www.NaN-tic.com

[IMP] Several changes including:
- Added country to taxes.
- Added hability to import invoice numbers.

297. By Albert Cervera i Areny - http://www.NaN-tic.com

[FIX] Added context in all calls.

296. By Albert Cervera i Areny - http://www.NaN-tic.com

[FIX] Ensure 'None' is never returned as it's not serializable in XML-RPC protocol. Use False instead.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2010-02-04 13:09:52 +0000
3+++ __init__.py 2010-04-12 10:56:33 +0000
4@@ -18,8 +18,9 @@
5 import magerp_core
6 import product
7 import partner
8+import invoice
9 import sale
10-import invoice
11 import product_images
12+import country
13+
14 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
15-
16
17=== modified file '__terp__.py'
18--- __terp__.py 2010-02-26 21:03:53 +0000
19+++ __terp__.py 2010-04-12 10:56:33 +0000
20@@ -24,6 +24,7 @@
21 "base_sale_multichannels",
22 "product_images_olbs",
23 "account_payment",
24+ 'nan_external_prices',
25 ],
26 "author" : "Sharoon Thomas, Raphael Valyi",
27 "description": """Magento E-commerce management
28@@ -41,6 +42,7 @@
29 'sale_view.xml',
30 'product_images_view.xml',
31 'magerp_menu.xml',
32+ 'country_view.xml',
33 'settings/external.mapping.template.csv',
34 'settings/external.mappinglines.template.csv',
35 'settings/magerp_product_product_type.xml',
36
37=== added file 'country.py'
38--- country.py 1970-01-01 00:00:00 +0000
39+++ country.py 2010-04-12 10:56:33 +0000
40@@ -0,0 +1,39 @@
41+# -*- encoding: utf-8 -*-
42+#########################################################################
43+# #
44+# Copyright (C) 2010 NaN Projectes de Programari Lliure, S.L. #
45+# http://www.NaN-tic.com #
46+# #
47+# This program is free software: you can redistribute it and/or modify #
48+# it under the terms of the GNU General Public License as published by #
49+# the Free Software Foundation, either version 3 of the License, or #
50+# (at your option) any later version. #
51+# #
52+# This program is distributed in the hope that it will be useful, #
53+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
54+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
55+# GNU General Public License for more details. #
56+# #
57+# You should have received a copy of the GNU General Public License #
58+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
59+# #
60+#########################################################################
61+
62+from osv import osv, fields
63+
64+class res_country(osv.osv):
65+ _inherit = 'res.country'
66+
67+ _columns = {
68+ 'fiscal_position_id': fields.many2one('account.fiscal.position', 'Fiscal Position', help='Fiscal position that will be used for partners in this country if partner has no fiscal position set. Note that this will only be used in orders and invoices imported from Magento.'),
69+ }
70+res_country()
71+
72+class account_tax(osv.osv):
73+ _inherit = 'account.tax'
74+ _columns = {
75+ 'country_id': fields.many2one('res.country', 'Country'),
76+ }
77+account_tax()
78+
79+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
80
81=== added file 'country_view.xml'
82--- country_view.xml 1970-01-01 00:00:00 +0000
83+++ country_view.xml 2010-04-12 10:56:33 +0000
84@@ -0,0 +1,38 @@
85+<?xml version="1.0" encoding="utf-8"?>
86+<openerp>
87+<data>
88+ <record model="ir.ui.view" id="view_country_form_fiscal_position">
89+ <field name="name">res.country.form.fiscal_position</field>
90+ <field name="model">res.country</field>
91+ <field name="inherit_id" ref="base.view_country_form" />
92+ <field name="type">form</field>
93+ <field name="arch" type="xml">
94+ <field name="code" position="after">
95+ <field name="fiscal_position_id"/>
96+ </field>
97+ </field>
98+ </record>
99+ <record model="ir.ui.view" id="view_country_tree_fiscal_position">
100+ <field name="name">res.country.tree.fiscal_position</field>
101+ <field name="model">res.country</field>
102+ <field name="inherit_id" ref="base.view_country_tree" />
103+ <field name="type">tree</field>
104+ <field name="arch" type="xml">
105+ <field name="code" position="after">
106+ <field name="fiscal_position_id"/>
107+ </field>
108+ </field>
109+ </record>
110+ <record model="ir.ui.view" id="view_tax_form_country_id">
111+ <field name="name">account.tax.form.country_id</field>
112+ <field name="model">account.tax</field>
113+ <field name="inherit_id" ref="account.view_tax_form" />
114+ <field name="type">form</field>
115+ <field name="arch" type="xml">
116+ <field name="type_tax_use" position="after">
117+ <field name="country_id"/>
118+ </field>
119+ </field>
120+ </record>
121+</data>
122+</openerp>
123
124=== modified file 'invoice.py'
125--- invoice.py 2009-11-25 12:32:15 +0000
126+++ invoice.py 2010-04-12 10:56:33 +0000
127@@ -20,12 +20,17 @@
128 #along with this program. If not, see <http://www.gnu.org/licenses/>. #
129 #########################################################################
130
131-from osv import osv, fields
132+from osv import osv
133+from osv import fields
134
135 class account_invoice(osv.osv):
136- _inherit = "account.invoice"
137+ _inherit = 'account.invoice'
138
139 _columns = {
140- 'magento_ref':fields.char('Magento REF', size=32),
141- }
142-account_invoice()
143\ No newline at end of file
144+ 'magento_ref':fields.char('Magento REF', size=32),
145+ }
146+
147+
148+account_invoice()
149+
150+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
151
152=== modified file 'magerp_core.py'
153--- magerp_core.py 2010-04-08 13:33:20 +0000
154+++ magerp_core.py 2010-04-12 10:56:33 +0000
155@@ -55,7 +55,7 @@
156 core_imp_conn = self.external_connection(cr, uid, inst, DEBUG)
157 if core_imp_conn:
158 self.pool.get('external.shop.group').mage_import_base(cr, uid,core_imp_conn, inst.id, defaults={'referential_id':inst.id})
159- self.pool.get('sale.shop').mage_import_base(cr, uid, core_imp_conn, inst.id, defaults={'magento_shop':True})
160+ self.pool.get('sale.shop').mage_import_base(cr, uid, core_imp_conn, inst.id, defaults={})
161 self.pool.get('magerp.storeviews').mage_import_base(cr,uid,core_imp_conn, inst.id, defaults={})
162 else:
163 osv.except_osv(_("Connection Error"), _("Could not connect to server\nCheck location, username & password."))
164
165=== modified file 'magerp_osv.py'
166--- magerp_osv.py 2010-01-02 18:43:26 +0000
167+++ magerp_osv.py 2010-04-12 10:56:33 +0000
168@@ -22,6 +22,9 @@
169 self.logger = netsvc.Logger()
170
171 def try_connect(self):
172+ #import traceback
173+ #traceback.print_stack()
174+ print "TRYING CONNECT..."
175 self.session = self.ser.login(self.username, self.password)
176 if self.debug:
177 self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_INFO, _("Login Successful"))
178@@ -69,7 +72,12 @@
179 else:
180 arguments = []
181 try:
182- return self.try_call(method, arguments)
183+ import time
184+ print "TRYING CALL: ", method, arguments
185+ start = time.time()
186+ result = self.try_call(method, arguments)
187+ print "CALL ELAPSED: ", time.time() - start
188+ return result
189 except Exception, e:
190 self.logger.notifyChannel(_("Magento Call"), netsvc.LOG_WARNING, _("Webservice Failure, sleeping 1 second before next attempt"))
191 time.sleep(1)
192@@ -227,7 +235,12 @@
193 subject[key] = True
194 return subject
195
196- def mage_import_base(self,cr,uid,conn, external_referential_id, defaults={}, context={}):
197+ def mage_import_base(self,cr,uid,conn, external_referential_id, defaults=None, context=None):
198+ if defaults is None:
199+ defaults = {}
200+ if context is None:
201+ context = {}
202+
203 if not 'ids_or_filter' in context.keys():
204 context['ids_or_filter'] = []
205 result = {'create_ids': [], 'write_ids': []}
206@@ -247,7 +260,10 @@
207
208 #it may happen that list method doesn't provide enough information, forcing us to use get_method on each record (case for sale orders)
209 if context.get('one_by_one', False):
210- del(context['one_by_one'])
211+ # Copy the context before removing items so we do not affect
212+ # successive calls
213+ context = context.copy()
214+ del( context['one_by_one'] )
215 for record in data:
216 id = record[self.pool.get('external.mapping').read(cr, uid, mapping_id[0],['external_key_name'])['external_key_name']]
217 get_method = self.pool.get('external.mapping').read(cr,uid,mapping_id[0],['external_get_method']).get('external_get_method',False)
218@@ -288,3 +304,4 @@
219 mageids.append(each[self._MAGE_FIELD])
220 return mageids
221
222+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
223
224=== modified file 'product.py'
225--- product.py 2010-04-05 19:00:41 +0000
226+++ product.py 2010-04-12 10:56:33 +0000
227@@ -810,12 +810,17 @@
228 self.write(cr, uid, oe_id, {'magento_sku': sku})
229 return res
230
231- def ext_export(self, cr, uid, ids, external_referential_ids=[], defaults={}, context={}):
232- ids = self.search(cr, uid, [('id', 'in', ids), ('magento_exportable', '=', True)]) #restrict export to only exportable products
233+ def ext_export(self, cr, uid, ids, external_referential_ids=[], defaults=None, context=None):
234+ if defaults is None:
235+ defaults = {}
236+ if context is None:
237+ context = {}
238+
239+ ids = self.search(cr, uid, [('id', 'in', ids), ('magento_exportable', '=', True)], context=context) #restrict export to only exportable products
240 dates_2_ids = []
241 ids_2_dates = {}
242
243- shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id'])
244+ shop = self.pool.get('sale.shop').browse(cr, uid, context['shop_id'], context)
245
246 if shop.last_products_export_date:
247 last_exported_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(shop.last_products_export_date, '%Y-%m-%d %H:%M:%S')))
248@@ -885,19 +890,22 @@
249 sku = self.product_to_sku(cr, uid, product)
250 return super(magerp_osv.magerp_osv, self).ext_update(cr, uid, data, conn, method, oe_id, sku, ir_model_data_id, create_method, ctx)
251
252- def export_inventory(self, cr, uid, ids, shop, ctx):
253+ def export_inventory(self, cr, uid, ids, shop, context):
254 logger = netsvc.Logger()
255- stock_id = self.pool.get('sale.shop').browse(cr, uid, ctx['shop_id']).warehouse_id.lot_stock_id.id
256- for product in self.browse(cr, uid, ids):
257+ stock_id = self.pool.get('sale.shop').browse(cr, uid, context['shop_id'], context).warehouse_id.lot_stock_id.id
258+ for product in self.browse(cr, uid, ids, context):
259 if product.magento_sku and product.type != 'service':
260- virtual_available = self.read(cr, uid, product.id, ['virtual_available'], {'location': stock_id})['virtual_available']
261- # Changing Stock Availability to "Out of Stock" in Magento
262+ virtual_available = self.read(cr, uid, product.id, ['virtual_available'], {'location': stock_id}, context)['virtual_available']
263+ # Changing Stock Availability to "Out of Stock" in Magento
264 # if a product has qty lt or equal to 0.
265 if virtual_available <= 0 :
266 is_in_stock = 0
267 else :
268 is_in_stock = 1
269- ctx['conn_obj'].call('product_stock.update', [product.magento_sku, {'qty': virtual_available, 'is_in_stock': is_in_stock}])
270+ context['conn_obj'].call('product_stock.update', [product.magento_sku, {'qty': virtual_available, 'is_in_stock': is_in_stock}])
271 logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Successfully updated stock level at %s for product with SKU %s " %(virtual_available, product.magento_sku))
272+ return False
273
274 product_product()
275+
276+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
277
278=== modified file 'sale.py'
279--- sale.py 2010-03-26 17:32:47 +0000
280+++ sale.py 2010-04-12 10:56:33 +0000
281@@ -23,11 +23,13 @@
282 import magerp_osv
283 import netsvc
284 from tools.translate import _
285+from tools import config
286 import string
287 #from datetime import datetime
288 import time
289 DEBUG = True
290
291+
292 #TODO, may be move that on out CSV mapping, but not sure we can easily
293 #see OpenERP sale/sale.py and Magento app/code/core/Mage/Sales/Model/Order.php for details
294 ORDER_STATUS_MAPPING = {'draft': 'processing', 'progress': 'processing', 'shipping_except': 'complete', 'invoice_except': 'complete', 'done': 'closed', 'cancel': 'canceled', 'waiting_date': 'holded'}
295@@ -55,22 +57,26 @@
296 res[shop.id] = False
297 return res
298
299- def export_images(self, cr, uid, ids, ctx):
300- for shop in self.browse(cr, uid, ids):
301+ def export_images(self, cr, uid, ids, context):
302+ if context is None:
303+ context = {}
304+ for shop in self.browse(cr, uid, ids, context):
305+ ctx = context.copy()
306 ctx['shop_id'] = shop.id
307 ctx['conn_obj'] = self.external_connection(cr, uid, shop.referential_id)
308 recent_changed_images = self.pool.get('product.images').get_changed_ids(cr, uid, shop.last_images_export_date)
309 if recent_changed_images:
310 res = self.pool.get('product.images').update_remote_images(cr, uid, recent_changed_images, ctx)
311 res = True
312- self.write(cr,uid,ctx['shop_id'],{'last_images_export_date':time.strftime('%Y-%m-%d %H:%M:%S')})
313-
314+ self.write(cr,uid,ctx['shop_id'],{
315+ 'last_images_export_date':time.strftime('%Y-%m-%d %H:%M:%S')
316+ }, context)
317
318 def _get_rootcategory(self, cr, uid, ids, prop, unknow_none, context):
319 res = {}
320 for shop in self.browse(cr, uid, ids, context):
321 if shop.root_category_id:
322- rid = self.pool.get('product.category').extid_to_oeid(cr, uid, shop.root_category_id, shop.referential_id.id)
323+ rid = self.pool.get('product.category').extid_to_oeid(cr, uid, shop.root_category_id, shop.referential_id.id, context)
324 res[shop.id] = rid
325 else:
326 res[shop.id] = False
327@@ -94,29 +100,62 @@
328 'exportable_product_ids': fields.function(_get_exportable_product_ids, method=True, type='one2many', relation="product.product", string='Exportable Products'),
329 'magento_shop': fields.boolean('Magento Shop', readonly=True),
330 'auto_import': fields.boolean('Automatic Import'),
331+ 'import_invoices': fields.boolean('Import Invoices', help='If marked, invoices will be imported when orders are imported.'),
332 }
333
334- def import_shop_orders(self, cr, uid, shop, defaults, ctx):
335+ def import_shop_orders(self, cr, uid, shop, defaults, context):
336+ if context is None:
337+ context = {}
338 result = []
339 for storeview in shop.storeview_ids:
340- magento_storeview_id = self.pool.get('magerp.storeviews').oeid_to_extid(cr, uid, storeview.id, shop.referential_id.id, context={})
341+ magento_storeview_id = self.pool.get('magerp.storeviews').oeid_to_extid(cr, uid, storeview.id, shop.referential_id.id, context)
342 ids_or_filter = [{'store_id': {'eq': magento_storeview_id}}]
343
344- #get last imported order:
345- last_external_id = self.get_last_imported_external_id(cr, 'sale.order', shop.referential_id.id, "sale_order.shop_id=%s and magento_storeview_id=%s" % (shop.id, storeview.id))[1]
346+ # get last imported order:
347+ last_external_id = self.get_last_imported_external_id(cr, uid, 'sale.order', shop.referential_id.id, [
348+ ('shop_id','=',shop.id),
349+ ('magento_storeview_id','=',storeview.id)
350+ ], context)[1]
351 if last_external_id:
352 ids_or_filter[0]['increment_id'] = {'gt': last_external_id}
353 defaults['magento_storeview_id'] = storeview.id
354- result.append(self.pool.get('sale.order').mage_import_base(cr, uid, ctx.get('conn_obj', False), shop.referential_id.id,
355+ ctx = context.copy()
356+ ctx.update({
357+ 'one_by_one': True,
358+ 'ids_or_filter': ids_or_filter,
359+ })
360+ data = self.pool.get('sale.order').mage_import_base(cr, uid, context.get('conn_obj'), shop.referential_id.id,
361 defaults=defaults,
362- context={
363- 'one_by_one': True,
364- 'ids_or_filter':ids_or_filter
365- }))
366+ context=ctx)
367+ result.append( data )
368+
369+ # Import Invoices
370+ if shop.import_invoices:
371+ # Get last imported invoice
372+ ids = self.pool.get('sale.order').search(cr, uid, [('use_external_prices','=',True),('magento_invoice','=',False)], order='create_date ASC', limit=1, context=context)
373+ if ids:
374+ external_id = self.pool.get('sale.order').oeid_to_extid(cr, uid, ids[0], shop.referential_id.id, context)
375+ filter = [ {'store_id': {'eq': magento_storeview_id}, 'order_increment_id': {'gt': external_id}} ]
376+ conn = context.get('conn_obj')
377+ data = conn.call( 'sales_order_invoice.list', filter )
378+ for record in data:
379+ order_id = self.pool.get('sale.order').extid_to_oeid(cr, uid, record['order_increment_id'], shop.referential_id.id, context)
380+ self.pool.get('sale.order').write(cr, uid, [order_id], {
381+ 'magento_invoice': record['increment_id'],
382+ }, context)
383+ workflow = netsvc.LocalService('workflow')
384+ order = self.pool.get('sale.order').browse(cr, uid, order_id, context)
385+ if order.order_policy == 'manual':
386+ workflow.trg_validate(uid, 'sale.order', order_id, 'order_confirm', cr)
387+ if order.shop_id.invoice_generation_policy != 'none':
388+ workflow.trg_validate(uid, 'sale.order', order_id, 'manual_invoice', cr)
389+ elif order.order_policy == 'picking':
390+ workflow.trg_validate(uid, 'sale.order', order_id, 'order_confirm', cr)
391+
392 return result
393
394- def update_shop_orders(self, cr, uid, order, ext_id, ctx):
395- conn = ctx.get('conn_obj', False)
396+ def update_shop_orders(self, cr, uid, order, ext_id, context):
397+ conn = context.get('conn_obj', False)
398 status = ORDER_STATUS_MAPPING.get(order.state, False)
399 result = {}
400
401@@ -128,11 +167,16 @@
402 cr.execute("select account_invoice.id from account_invoice inner join sale_order_invoice_rel on invoice_id = account_invoice.id where order_id = %s" % order.id)
403 resultset = cr.fetchone()
404 if resultset and len(resultset) == 1:
405- invoice = self.pool.get("account.invoice").browse(cr, uid, resultset[0])
406+ invoice = self.pool.get("account.invoice").browse(cr, uid, resultset[0], context)
407+ if invoice.amount_total != order.amount_total:
408+ raise osv.except_osv( _('Error'), _('Invoice total != order total in invoice id %d') % resultset[0] )
409 if invoice.amount_total == order.amount_total and not invoice.magento_ref:
410 try:
411 result['magento_invoice_ref'] = conn.call('sales_order_invoice.create', [order.magento_incrementid, [], _("Invoice Created"), True, True])
412- self.pool.get("account.invoice").write(cr, uid, invoice.id, {'magento_ref': result['magento_invoice_ref'], 'origin': result['magento_invoice_ref']})
413+ self.pool.get("account.invoice").write(cr, uid, invoice.id, {
414+ 'magento_ref': result['magento_invoice_ref'],
415+ 'origin': result['magento_invoice_ref']
416+ }, context)
417 except Exception, e:
418 pass #TODO make sure that's because Magento invoice already exists and then re-attach it!
419
420@@ -140,14 +184,12 @@
421
422 # Schedules functions ============ #
423 def run_import_orders_scheduler(self, cr, uid, context=None):
424- if context == None:
425- context = {}
426 sale_obj = self.pool.get('sale.shop')
427 search_params = [
428 ('magento_shop', '=', True),
429 ('auto_import', '=', True),
430 ]
431- shops_ids = sale_obj.search(cr, uid, search_params)
432+ shops_ids = sale_obj.search(cr, uid, search_params, context=context)
433 if shops_ids:
434 self.import_orders(cr, uid, shops_ids, context)
435 if DEBUG:
436@@ -219,12 +261,20 @@
437 'magento_incrementid': fields.char('Magento Increment ID', size=32),
438 'magento_payment_method': fields.char('Magento Payment Method', size=32),
439 'magento_storeview_id': fields.many2one('magerp.storeviews', 'Magento Store View'),
440+ 'magento_invoice': fields.char('Magento Invoice', size=256, readonly=True, help='Magento invoice number.'),
441 }
442
443 def _auto_init(self, cr, context={}):
444 cr.execute("ALTER TABLE sale_order_line ALTER COLUMN discount TYPE numeric(16,6);")
445 cr.execute("ALTER TABLE account_invoice_line ALTER COLUMN discount TYPE numeric(16,6);")
446 super(sale_order, self)._auto_init(cr, context)
447+
448+ def _inv_get(self, cr, uid, order, context={}):
449+ # If 'magento_invoice' was provided use it as invoice number when invoice is created
450+ result = super(sale_order, self)._inv_get(cr, uid, order, context)
451+ if order.magento_invoice:
452+ result['number'] = order.magento_invoice
453+ return result
454
455 def get_mage_customer_address_id(self, address_data):
456 if address_data.get('customer_address_id', False):
457@@ -310,7 +360,8 @@
458 #simple VAT tax on order line (else override method):
459 line_tax_vat = float(line_data['tax_percent']) / 100.0
460 if line_tax_vat > 0:
461- line_tax_ids = self.pool.get('account.tax').search(cr, uid, [('type_tax_use', '=', 'sale'), ('amount', '>=', line_tax_vat - 0.001), ('amount', '<=', line_tax_vat + 0.001)])
462+ country = data_record['billing_address']['country_id']
463+ line_tax_ids = self.pool.get('account.tax').search(cr, uid, [('type_tax_use', '=', 'sale'), ('amount', '>=', line_tax_vat - 0.001), ('amount', '<=', line_tax_vat + 0.001), '|', ('country_id','=',country), ('country_id','=',False) ], context=context)
464 if line_tax_ids and len(line_tax_ids) > 0:
465 defaults_line['tax_id'] = [(6, 0, [line_tax_ids[0]])]
466 lines_vals.append((0, 0, self.oevals_from_extdata(cr, uid, external_referential_id, line_data, 'item_id', mapping_lines, defaults_line, context)))
467@@ -344,6 +395,12 @@
468 if not context.get('one_by_one', False):
469 if data_record.get('billing_address', False):
470 res = self.get_order_addresses(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context)
471+ if 'partner_order_id' in res:
472+ address = self.pool.get('res.partner.address').browse(cr, uid, res['partner_order_id'], context)
473+ position = address.country_id and address.country_id.fiscal_position_id or False
474+ if position:
475+ res['fiscal_position'] = position.id
476+
477 if data_record.get('items', False):
478 try:
479 res = self.get_order_lines(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context)
480@@ -370,7 +427,7 @@
481 if payment.get('amount_paid', False):
482 self.generate_payment_with_pay_code(cr, uid, payment['method'], res['partner_id'], payment['amount_paid'], "mag_" + payment['payment_id'], "mag_" + data_record['increment_id'], res['date_order'], True, context)
483 elif payment.get('amount_ordered', False):
484- self.generate_payment_with_pay_code(cr, uid, payment['method'], res['partner_id'], payment['amount_ordered'], "mag_" + payment['payment_id'], "mag_" + data_record['increment_id'], res['date_order'], False, context)
485+ self.generate_payment_with_pay_code(cr, uid, payment['method'], res['partner_id'], payment['amount_ordered'], "mag_" + payment['payment_id'], "mag_" + data_record['increment_id'], res['date_order'], False, context)
486 return res
487
488 def oe_update(self,cr, uid, existing_rec_id, vals, data, external_referential_id, defaults, context):
489@@ -390,16 +447,16 @@
490 wf_service.trg_validate(uid, 'sale.order', order_id, 'cancel', cr)
491 else:
492 order = self.browse(cr, uid, order_id, context)
493- if order.order_policy == 'manual' and order.shop_id.picking_generation_policy != 'none':
494- wf_service.trg_validate(uid, 'sale.order', order.id, 'order_confirm', cr)
495- if order.shop_id.invoice_generation_policy != 'none':
496- wf_service.trg_validate(uid, 'sale.order', order.id, 'manual_invoice', cr)
497- elif order.order_policy == 'picking' and order.shop_id.picking_generation_policy != 'none':
498- wf_service.trg_validate(uid, 'sale.order', order.id, 'order_confirm', cr)
499+ if order.shop_id.picking_generation_policy != 'none':
500+ if order.order_policy == 'manual':
501+ wf_service.trg_validate(uid, 'sale.order', order.id, 'order_confirm', cr)
502+ if order.shop_id.invoice_generation_policy != 'none':
503+ wf_service.trg_validate(uid, 'sale.order', order.id, 'manual_invoice', cr)
504+ elif order.order_policy == 'picking':
505+ wf_service.trg_validate(uid, 'sale.order', order.id, 'order_confirm', cr)
506
507 sale_order()
508
509-
510 class magerp_sale_shop_payment_type(magerp_osv.magerp_osv):
511 _name = "magerp.sale.shop.payment.type"
512 _description = "Magento Sale Shop Payment Type"
513@@ -419,3 +476,5 @@
514 }
515
516 magerp_sale_shop_payment_type()
517+
518+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
519
520=== modified file 'sale_view.xml'
521--- sale_view.xml 2010-03-26 17:32:47 +0000
522+++ sale_view.xml 2010-04-12 10:56:33 +0000
523@@ -54,6 +54,7 @@
524 <field name="arch" type="xml">
525 <field name="fiscal_position" position="after">
526 <field name="magento_payment_method" />
527+ <field name="magento_invoice" select="2"/>
528 </field>
529 </field>
530 </record>
531@@ -89,13 +90,25 @@
532 </field>
533 </record>
534
535+ <record id="view_shop_form_import_invoices" model="ir.ui.view">
536+ <field name="name">sale.shop.form.import_invoices</field>
537+ <field name="model">sale.shop</field>
538+ <field name="type">form</field>
539+ <field name="inherit_id" ref="magerp_view_shop_auto_import_form"/>
540+ <field name="arch" type="xml">
541+ <field name="picking_generation_policy" position="after">
542+ <field name="import_invoices"/>
543+ </field>
544+ </field>
545+ </record>
546+
547 <record id="magerp_view_shop_payment_type_form" model="ir.ui.view">
548 <field name="name">magerp_view_shop_payment_type_form</field>
549 <field name="model">sale.shop</field>
550 <field name="type">form</field>
551- <field name="inherit_id" ref="base_sale_multichannels.base_sale_multichannels_view_shop_form"/>
552+ <field name="inherit_id" ref="view_shop_form_import_invoices"/>
553 <field name="arch" type="xml">
554- <field name="picking_generation_policy" position="after">
555+ <field name="import_invoices" position="after">
556 <group col="4" colspan="4">
557 <field name="payment_types" nolabel="1"/>
558 </group>
559
560=== modified file 'settings/external.mappinglines.template.csv'
561--- settings/external.mappinglines.template.csv 2010-03-16 13:59:26 +0000
562+++ settings/external.mappinglines.template.csv 2010-04-12 10:56:33 +0000
563@@ -7,37 +7,51 @@
564 "mag_erp_s_gpid","magento1324","base_sale_multichannels.model_external_shop_group","default_group_id","in_out","int","result=[('default_shop_integer_id',ifield)]",
565 "mag_erp_sv_name","magento1324","model_magerp_storeviews","name","in_out","str","result=[('name',ifield)]","result=[('name',record['name'])]"
566 "mag_erp_sv_code","magento1324","model_magerp_storeviews","code","in_out","str","result=[('code',ifield)]",
567-"mag_erp_sv_sg","magento1324","model_magerp_storeviews","website_id","in_out","int","result=[('website_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id))]",
568+"mag_erp_sv_sg","magento1324","model_magerp_storeviews","website_id","in_out","int","result=[('website_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id, context))]",
569 "mag_erp_sv_isa","magento1324","model_magerp_storeviews","is_active","in_out","str","result=[('is_active',bool(eval(ifield)))]",
570 "mag_erp_sv_stord","magento1324","model_magerp_storeviews","sort_order","in_out","int","result=[('sort_order',ifield)]",
571-"mag_erp_sv_gpid","magento1324","model_magerp_storeviews","group_id","in_out","int","result=[('shop_id',self.pool.get('sale.shop').extid_to_oeid(cr, uid, ifield, external_referential_id))]",
572-"mag_erp_st_name","magento1324","sale.model_sale_shop","name","in_out","str","result=[('name',ifield)]","result=[('name',record['name'])]"
573+"mag_erp_sv_gpid","magento1324","model_magerp_storeviews","group_id","in_out","int","result=[('shop_id',self.pool.get('sale.shop').extid_to_oeid(cr, uid, ifield, external_referential_id, context))]",
574+"mag_erp_st_name","magento1324","sale.model_sale_shop","name","in_out","str","
575+name = ifield
576+website_id = self.pool.get('external.shop.group').extid_to_oeid(cr, uid, data['website_id'], external_referential_id, context)
577+if website_id:
578+ name += ' - ' + self.pool.get('external.shop.group').browse(cr, uid, website_id, context).name
579+result = [('name',name)]
580+","
581+name = record['name']
582+if name:
583+ name = name.split(' - ')[0]
584+result=[('name', name)]"
585 "mag_erp_st_gpid","magento1324","sale.model_sale_shop","group_id","in_out","int","result=[('group_id',ifield)]",
586-"mag_erp_st_grp","magento1324","sale.model_sale_shop","website_id","in_out","int","result=[('shop_group_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id))]",
587+"mag_erp_st_grp","magento1324","sale.model_sale_shop","website_id","in_out","int","result=[('shop_group_id',self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id, context))]",
588 "mag_erp_st_default_st","magento1324","sale.model_sale_shop","default_store_id","in_out","int","result=[('default_storeview_integer_id',ifield)]",
589 "mag_erp_st_root_categ","magento1324","sale.model_sale_shop","root_category_id","in_out","int","result=[('root_category_id',ifield)]",
590-"mag_erp_so_name","magento1324","sale.model_sale_order","increment_id","in_out","str","result=[('magento_incrementid',str(ifield)), ('name','mag_' + str(ifield))]",
591-"mag_erp_so_custo","magento1324","sale.model_sale_order","customer_id","in_out","int","result=[('partner_id',self.pool.get('res.partner').extid_to_oeid(cr, uid, ifield, external_referential_id))]",
592+"mag_erp_so_name","magento1324","sale.model_sale_order","increment_id","in_out","str","result=[('magento_incrementid',str(ifield)), ('name',str(ifield)), ('use_external_prices', True)]",
593+"mag_erp_so_custo","magento1324","sale.model_sale_order","customer_id","in_out","int","result=[('partner_id',self.pool.get('res.partner').extid_to_oeid(cr, uid, ifield, external_referential_id, context))]",
594 "mag_erp_so_pay","magento1324","sale.model_sale_order","payment","in_out","str","
595 payments_mapping = {'checkmo': 'manual', 'ccsave': 'prepaid', 'free':'prepaid','googlecheckout':'prepaid','paypayl_express':'prepaid', 'paybox_system': 'prepaid', 'paypal_standard': 'prepaid', 'cashondelivery': 'manual', 'servired_standard': 'prepaid', 'bbva': 'prepaid', 'cofidis': 'prepaid'}
596 ifield=eval(ifield)
597 payment_type = False
598 cr.execute('select * from ir_module_module where name=%s and state=%s', ('sale_payment','installed'))
599 if cr.fetchone():
600- payment_type = self.pool.get('payment.type').search(cr, uid, [('code', '=', ifield['method'])])
601+ payment_type = self.pool.get('payment.type').search(cr, uid, [('code', '=', ifield['method'])], context=context)
602 payment_type = payment_type and payment_type[0]
603 result=[('order_policy', ifield['method'] in payments_mapping and payments_mapping[ifield['method']] or 'prepaid'), ('magento_payment_method', ifield['method']), ('payment_type', payment_type)]",
604 "mag_erp_soline_name","magento1324","sale.model_sale_order_line","name","in_out","str","result=[('name',ifield)]",
605-"mag_erp_soline_pid","magento1324","sale.model_sale_order_line","product_id","in_out","str","result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, ifield, external_referential_id))]",
606+"mag_erp_soline_pid","magento1324","sale.model_sale_order_line","product_id","in_out","str","result=[('product_id',self.pool.get('product.product').extid_to_oeid(cr, uid, ifield, external_referential_id, context))]",
607 "mag_erp_soline_uomqty","magento1324","sale.model_sale_order_line","qty_ordered","in_out","str","result=[('product_uom_qty',ifield)]",
608 "mag_erp_soline_uosqty","magento1324","sale.model_sale_order_line","qty_ordered","in","str","result=[('product_uos_qty',ifield)]",
609 "mag_erp_soline_price","magento1324","sale.model_sale_order_line","price","in","str","result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]",
610+"mag_erp_soline_tax_percent","magento1324","sale.model_sale_order_line","tax_percent","in","str","result=[('external_tax_percent', float(data['tax_percent']))]",
611+"mag_erp_soline_tax_amount","magento1324","sale.model_sale_order_line","tax_invoiced","in","str","result=[('external_tax_amount', float(data['tax_amount']))]",
612+"mag_erp_soline_base_amount","magento1324","sale.model_sale_order_line","base_row_total","in","str","result=[('external_base_amount', float(data['base_row_total']))]",
613+"mag_erp_soline_base_tax_amount","magento1324","sale.model_sale_order_line","base_tax_amount","in","str","result=[('external_base_tax_amount', float(data['base_tax_amount']))]",
614 "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)]",
615 "mag_erp_procat_2","magento1324","product.model_product_category","level","in","int","result=[('sequence',ifield),('level',ifield)]",
616-"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))])
617+"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))], context=context)
618 parent_id = False
619 if record_id:
620- parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[])
621+ parent_rec = self.pool.get('ir.model.data').read(cr,uid,record_id[0],[], context)
622 parent_id=parent_rec.get('res_id',False)
623 result=[('magento_parent_id',ifield),('parent_id',parent_id)]","magento_parent_id = False
624 if record.get('parent_id',False):
625@@ -116,22 +130,22 @@
626 "mag_erp_prd_7","magento1324","product.model_product_product","category_ids","in_out","str","categ_ids =[]
627 if len(eval(ifield)) > 0:
628 for category_ids in eval(ifield):
629- categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, category_ids, external_referential_id))
630+ categ_ids.append(self.pool.get('product.category').extid_to_oeid(cr, uid, category_ids, external_referential_id, context))
631 categ_id = categ_ids.pop()
632 else:
633- categ_id = self.pool.get('external.referential').browse(cr, uid, external_referential_id).default_pro_cat.id
634+ categ_id = self.pool.get('external.referential').browse(cr, uid, external_referential_id, context).default_pro_cat.id
635 result = [('categ_id', categ_id), ('categ_ids',[(6, 0, categ_ids)])]","
636 product = self.browse(cr, uid, record['id'])
637-main_categ_id = self.pool.get('product.category').oeid_to_extid(cr, uid, product.categ_id.id, external_referential_id)
638+main_categ_id = self.pool.get('product.category').oeid_to_extid(cr, uid, product.categ_id.id, external_referential_id, context)
639 categ_ids = [main_categ_id]
640 for categ in product.categ_ids: #deal with extra m2m categories
641- categ_id = self.pool.get('product.category').oeid_to_extid(cr, uid, categ.id, external_referential_id)
642+ categ_id = self.pool.get('product.category').oeid_to_extid(cr, uid, categ.id, external_referential_id, context)
643 if categ_id:
644 categ_ids.append(categ_id)
645 result=[('category_ids', categ_ids)]"
646 "mag_erp_prd_8","magento1324","product.model_product_product","price","in_out","float","result=[('list_price',ifield)]","result=[]#map later"
647 "mag_erp_prd_9","magento1324","product.model_product_product","cost","in_out","float","result=[('standard_price',ifield)]","result = [('cost',record['standard_price'] or 0)]"
648-"mag_erp_prd_10","magento1324","product.model_product_product","set","in_out","str","result=[('set',self.pool.get('magerp.product_attribute_set').extid_to_oeid(cr, uid, ifield, external_referential_id))]",
649+"mag_erp_prd_10","magento1324","product.model_product_product","set","in_out","str","result=[('set',self.pool.get('magerp.product_attribute_set').extid_to_oeid(cr, uid, ifield, external_referential_id, context))]",
650 "mag_erp_prd_11","magento1324","product.model_product_product","special_price","in_out","float","result = [('x_magerp_special_price',ifield)]",""
651 "mag_erp_prd_12","magento1324","product.model_product_product","tier_price","in_out","str","result=[]#no mapping by default","result=[]#no mapping by default"
652 "mag_erp_prd_13","magento1324","product.model_product_product","minimal_price","in_out","float","result = [('x_magerp_minimal_price',ifield)]","
653@@ -140,7 +154,7 @@
654 else:
655 result = [('minimal_price',False)]"
656 "mag_erp_prd_14","magento1324","product.model_product_product","type_id","in_out","str","if ifield:
657- product_type_ids = self.pool.get('magerp.product_product_type').search(cr,uid,[('product_type','=',ifield)])
658+ product_type_ids = self.pool.get('magerp.product_product_type').search(cr,uid,[('product_type','=',ifield)], context=context)
659 if product_type_ids:
660 result = [('product_type',ifield)]","if 'product_type' in record and record['product_type']:
661 result = [('type_id',record['product_type'])]
662@@ -152,7 +166,7 @@
663 "magento_prt_adr_3","magento1324","base.model_res_partner_address","fax","in_out","str","result=[('fax',ifield)]",
664 "magento_prt_adr_4","magento1324","base.model_res_partner_address","firstname","in_out","str","result = [('name', (data.get('company', False) and (data['company'] + ' ; ') or '') + ifield + ' ' + data['lastname'])]",
665 "magento_prt_adr_6","magento1324","base.model_res_partner_address","is_active","in_out","str","result=[('active',bool(eval(ifield)))]",
666-"magento_prt_adr_7","magento1324","base.model_res_partner_address","country_id","in_out","str","result = self.pool.get('res.country').search(cr,uid,[('code','=',ifield)])
667+"magento_prt_adr_7","magento1324","base.model_res_partner_address","country_id","in_out","str","result = self.pool.get('res.country').search(cr,uid,[('code','=',ifield)], context=context)
668 if result and len(result)==1:
669 result=[('country_id',result[0])]
670 else:
671@@ -168,14 +182,14 @@
672 "magento_prt_adr_9","magento1324","base.model_res_partner_address","postcode","in_out","str","result=[('zip',ifield)]",
673 "magento_prt_adr_10","magento1324","base.model_res_partner_address","telephone","in_out","str","result=[('phone',ifield)]",
674 "magento_prt_adr_11","magento1324","base.model_res_partner_address","region","in_out","str","if ifield:
675- result = self.pool.get('res.country.state').search(cr,uid,[('name','ilike',ifield)])
676+ result = self.pool.get('res.country.state').search(cr,uid,[('name','ilike',ifield)], context=context)
677 if result and len(result)==1:
678 result = [('state_id',result[0])]
679 else:
680 result=[]
681 else:
682 result=[]",
683-"magento_prt_adr_13","magento1324","base.model_res_partner_address","customer_id","in_out","int","result=self.pool.get('res.partner').extid_to_oeid(cr,uid,ifield,external_referential_id)
684+"magento_prt_adr_13","magento1324","base.model_res_partner_address","customer_id","in_out","int","result=self.pool.get('res.partner').extid_to_oeid(cr, uid, ifield, external_referential_id, context)
685 if result:
686 result=[('partner_id',result)]
687 else:
688@@ -187,16 +201,16 @@
689 else:
690 result=[]",
691 "magento_prt_2","magento1324","base.model_res_partner","group_id","in_out","int","if ifield:
692- result=self.pool.get('res.partner.category').extid_to_oeid(cr,uid,ifield,external_referential_id)
693+ result=self.pool.get('res.partner.category').extid_to_oeid(cr, uid, ifield, external_referential_id, context)
694 if result:
695 result=[('group_id',result)]",
696 "magento_prt_3","magento1324","base.model_res_partner","store_id","in_out","int","if ifield:
697- result=self.pool.get('magerp.storeviews').extid_to_oeid(cr,uid,ifield,external_referential_id)
698+ result=self.pool.get('magerp.storeviews').extid_to_oeid(cr, uid, ifield, external_referential_id, context)
699 if result:
700- lang = self.pool.get('magerp.storeviews').browse(cr, uid, result).lang_id
701+ lang = self.pool.get('magerp.storeviews').browse(cr, uid, result, context).lang_id
702 result=[('store_id',result),('lang',lang and lang.code or False)]",
703 "magento_prt_4","magento1324","base.model_res_partner","website_id","in_out","int","if ifield:
704- result=self.pool.get('external.shop.group').extid_to_oeid(cr,uid,ifield,external_referential_id)
705+ result=self.pool.get('external.shop.group').extid_to_oeid(cr, uid, ifield, external_referential_id, context)
706 if result:
707 result=[('website_id',result)]",
708 "magento_prt_5","magento1324","base.model_res_partner","created_in","in_out","str","result=[('created_in',ifield)]",