Merge lp:~magentoerpconnect-core-editors/magentoerpconnect/improved_discount_n_address into lp:magentoerpconnect/oerp5.0-stable

Proposed by Sharoon Thomas http://openlabs.co.in
Status: Needs review
Proposed branch: lp:~magentoerpconnect-core-editors/magentoerpconnect/improved_discount_n_address
Merge into: lp:magentoerpconnect/oerp5.0-stable
Diff against target: 147 lines (+85/-7)
3 files modified
partner.py (+57/-0)
sale.py (+26/-5)
settings/external.mappinglines.template.csv (+2/-2)
To merge this branch: bzr merge lp:~magentoerpconnect-core-editors/magentoerpconnect/improved_discount_n_address
Reviewer Review Type Date Requested Status
Paul Todd (community) Needs Fixing
MagentoERPConnect core editors Pending
Review via email: mp+24941@code.launchpad.net

Description of the change

This contribution funded by C2C includes two major updates:

1. Better customer address handling: When the address is updated by customer on web store it is created as a new address in Open ERP.

2. Handling of discount from having a percentage in the line (Caused rounding issues) to a separate line. It also has the advantage that the coupon code is now shown.

Existing:
Both these are changes which will affect existing systems in terms of future behaviour.

Schema:
There are no Schema changes

We believe that the new behaviour is more desirable

To post a comment you must log in.
Revision history for this message
Paul Todd (paul-todd-solos) wrote :

Need to add
import netsvc to the partner.py file

and the following code throws an error.

[2010-08-25 13:24:35,773] ERROR:web-services:[36]: if magento_address['is_active'] == 1:
[2010-08-25 13:24:35,773] ERROR:web-services:[37]: KeyError: 'is_active'

review: Needs Fixing
Revision history for this message
Raphaƫl Valyi - http://www.akretion.com (rvalyi) wrote :

Hello what is the status of this branch? Should we still merge it? Is some extra work required?

Unmerged revisions

306. By Sharoon Thomas <sharoonthomas@sharoonthomas-laptop>

[IMP]Better Address Change monitoring and updation in openerp|
Better handling of discount coupons as a separate line item
**Funded by Camp to Camp SA**

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'partner.py'
--- partner.py 2010-01-02 18:43:26 +0000
+++ partner.py 2010-05-08 12:45:41 +0000
@@ -41,6 +41,63 @@
41 _defaults = {41 _defaults = {
42 'is_magento_order_address': lambda * a:False,42 'is_magento_order_address': lambda * a:False,
43 }43 }
44
45 def mage_to_oe_address(self, cr, uid ,magento_address, address_default):
46 oe_address = {}
47 oe_address['city'] = magento_address.get('city',False)
48 if magento_address['address_type'] == 'billing':
49 type = 'invoice'
50 elif magento_address['address_type'] == 'shipping':
51 type = 'delivery'
52 oe_address['city']= magento_address.get('city',False)
53 oe_address['zip']= magento_address.get('postcode',False)
54 oe_address['fax']= magento_address.get('fax', False)
55 oe_address['phone']= magento_address.get('telephone', False)
56 if magento_address.get('street', False):
57 street = magento_address['street'].split('\n')
58 oe_address['street']= street[0]
59 if len(street) ==2:
60 oe_address['street2'] = street[1]
61 mag_country_code = magento_address.get('country_id', '')
62 mag_country_id = self.pool.get('res.country').search(cr, uid, [('code' , '=', mag_country_code)])[0]
63 partner_name = ''
64 if magento_address['firstname']:
65 partner_name+= magento_address['firstname']
66# if magento_address['middlename'] :
67# partner_name+= ' ' + magento_address['middlename']
68 if magento_address['lastname'] :
69 partner_name+= ' ' + magento_address['lastname']
70 oe_address['name'] = partner_name
71 oe_address['type'] = type
72 oe_address['partner_id'] = address_default['partner_id']
73 oe_address['country_id'] = mag_country_id
74 return oe_address
75
76 def find_or_create(self, cr, uid, magento_address, external_referential_id, address_default, context={}):
77 logger = netsvc.Logger()
78 create_ids = []
79 write_ids = []
80 oe_address = self.mage_to_oe_address(cr, uid, magento_address, address_default)
81 args = [(key,'=',oe_address.get(key)) for key in oe_address.keys()]
82 addr_id = self.search(cr,uid,args,context=context)
83 if magento_address['is_active'] == 1:
84 active = True
85 else:
86 active = False
87 #oe_address['active'] = active # this should not be a basis of creating a new address.
88 oe_address['email'] = address_default.get('email', False)
89 if not addr_id :
90 # create address
91 crid= self.create(cr, uid, oe_address, context)
92 create_ids.append(crid)
93 logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Created in OpenERP %s from External Ref with external_id %s and OpenERP id %s successfully" %('res.partner.address', external_referential_id, crid))
94 return {'create_ids': create_ids, 'write_ids': []}
95 else:
96 self.write(cr, uid, addr_id[0], oe_address, context)
97 write_ids.append(addr_id[0])
98 logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Updated in OpenERP %s from External Ref with external_id %s and OpenERP id %s successfully" %('res.partner.address', external_referential_id, addr_id[0]))
99 return {'write_ids': write_ids, 'create_ids': []}
100
44res_partner_address()101res_partner_address()
45102
46class res_partner(magerp_osv.magerp_osv):103class res_partner(magerp_osv.magerp_osv):
47104
=== modified file 'sale.py'
--- sale.py 2010-03-26 17:32:47 +0000
+++ sale.py 2010-05-08 12:45:41 +0000
@@ -251,13 +251,11 @@
251 shipping_default = {'partner_id': res.get('partner_id', False)}251 shipping_default = {'partner_id': res.get('partner_id', False)}
252 billing_default = shipping_default.copy()252 billing_default = shipping_default.copy()
253 billing_default.update({'email' : data_record.get('customer_email', False)})253 billing_default.update({'email' : data_record.get('customer_email', False)})
254254 inv_res = partner_address_obj.find_or_create(cr, uid, data_record['billing_address'], external_referential_id, address_default, context)
255 inv_res = partner_address_obj.ext_import(cr, uid, [data_record['billing_address']], external_referential_id, billing_default, context)
256 if 'address_type' in data_record['shipping_address']:255 if 'address_type' in data_record['shipping_address']:
257 ship_res = partner_address_obj.ext_import(cr, uid, [data_record['shipping_address']], external_referential_id, shipping_default, context)256 ship_res = partner_address_obj.find_or_create(cr, uid, data_record['shipping_address'], external_referential_id, address_default, context)
258 else:257 else:
259 ship_res = partner_address_obj.ext_import(cr, uid, [data_record['billing_address']], external_referential_id, shipping_default, context)258 ship_res = partner_address_obj.find_or_create(cr, uid, data_record['billing_address'], external_referential_id, address_default, context)
260
261 res['partner_order_id'] = len(inv_res['create_ids']) > 0 and inv_res['create_ids'][0] or inv_res['write_ids'][0]259 res['partner_order_id'] = len(inv_res['create_ids']) > 0 and inv_res['create_ids'][0] or inv_res['write_ids'][0]
262 res['partner_invoice_id'] = res['partner_order_id']260 res['partner_invoice_id'] = res['partner_order_id']
263 res['partner_shipping_id'] = (len(ship_res['create_ids']) > 0 and ship_res['create_ids'][0]) or (len(ship_res['write_ids']) > 0 and ship_res['write_ids'][0]) or res['partner_order_id'] #shipping might be the same as invoice address261 res['partner_shipping_id'] = (len(ship_res['create_ids']) > 0 and ship_res['create_ids'][0]) or (len(ship_res['write_ids']) > 0 and ship_res['write_ids'][0]) or res['partner_order_id'] #shipping might be the same as invoice address
@@ -337,6 +335,28 @@
337 'tax_id': tax_id335 'tax_id': tax_id
338 }))336 }))
339 return res337 return res
338
339 def get_order_discount(self, cr, uid, res, data_record, context):
340 if float(data_record['discount_amount']) == 0 :
341 discount = 0.0
342 else :
343 discount = -float(data_record['discount_amount'])
344 discount_product_id = self.pool.get('product.product').search(cr, uid, [('default_code', '=', 'DISCOUNT MAGENTO')])[0]
345 discount_product = self.pool.get('product.product').browse(cr, uid, discount_product_id, context)
346 coupon_code = data_record.get('coupon_code', False)
347 if coupon_code:
348 name = 'Discount[Coupon Code: %s]' % coupon_code
349 else:
350 name = 'Discount'
351 res['order_line'].append((0, 0, {
352 'product_id': discount_product.id,
353 'name': discount_product.name,
354 'product_uom': discount_product.uom_id.id,
355 'product_uom_qty': 1,
356 'price_unit': discount,
357 'name': name
358 }))
359 return res
340 360
341 def oevals_from_extdata(self, cr, uid, external_referential_id, data_record, key_field, mapping_lines, defaults, context):361 def oevals_from_extdata(self, cr, uid, external_referential_id, data_record, key_field, mapping_lines, defaults, context):
342 res = super(magerp_osv.magerp_osv, self).oevals_from_extdata(cr, uid, external_referential_id, data_record, key_field, mapping_lines, defaults, context)362 res = super(magerp_osv.magerp_osv, self).oevals_from_extdata(cr, uid, external_referential_id, data_record, key_field, mapping_lines, defaults, context)
@@ -344,6 +364,7 @@
344 if not context.get('one_by_one', False):364 if not context.get('one_by_one', False):
345 if data_record.get('billing_address', False):365 if data_record.get('billing_address', False):
346 res = self.get_order_addresses(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context)366 res = self.get_order_addresses(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context)
367 res = self.get_order_discount(cr, uid, res, data_record, context)
347 if data_record.get('items', False):368 if data_record.get('items', False):
348 try:369 try:
349 res = self.get_order_lines(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context)370 res = self.get_order_lines(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context)
350371
=== modified file 'settings/external.mappinglines.template.csv'
--- settings/external.mappinglines.template.csv 2010-03-16 13:59:26 +0000
+++ settings/external.mappinglines.template.csv 2010-05-08 12:45:41 +0000
@@ -32,7 +32,7 @@
32"mag_erp_soline_uomqty","magento1324","sale.model_sale_order_line","qty_ordered","in_out","str","result=[('product_uom_qty',ifield)]",32"mag_erp_soline_uomqty","magento1324","sale.model_sale_order_line","qty_ordered","in_out","str","result=[('product_uom_qty',ifield)]",
33"mag_erp_soline_uosqty","magento1324","sale.model_sale_order_line","qty_ordered","in","str","result=[('product_uos_qty',ifield)]",33"mag_erp_soline_uosqty","magento1324","sale.model_sale_order_line","qty_ordered","in","str","result=[('product_uos_qty',ifield)]",
34"mag_erp_soline_price","magento1324","sale.model_sale_order_line","price","in","str","result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]",34"mag_erp_soline_price","magento1324","sale.model_sale_order_line","price","in","str","result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]",
35"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)]",35"mag_erp_soline_disc","magento1324","sale.model_sale_order_line","discount_amount","in","str","result=[('discount', 0.0)]",
36"mag_erp_procat_2","magento1324","product.model_product_category","level","in","int","result=[('sequence',ifield),('level',ifield)]",36"mag_erp_procat_2","magento1324","product.model_product_category","level","in","int","result=[('sequence',ifield),('level',ifield)]",
37"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))])37"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))])
38parent_id = False38parent_id = False
@@ -132,7 +132,7 @@
132"mag_erp_prd_8","magento1324","product.model_product_product","price","in_out","float","result=[('list_price',ifield)]","result=[]#map later"132"mag_erp_prd_8","magento1324","product.model_product_product","price","in_out","float","result=[('list_price',ifield)]","result=[]#map later"
133"mag_erp_prd_9","magento1324","product.model_product_product","cost","in_out","float","result=[('standard_price',ifield)]","result = [('cost',record['standard_price'] or 0)]"133"mag_erp_prd_9","magento1324","product.model_product_product","cost","in_out","float","result=[('standard_price',ifield)]","result = [('cost',record['standard_price'] or 0)]"
134"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))]",134"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))]",
135"mag_erp_prd_11","magento1324","product.model_product_product","special_price","in_out","float","result = [('x_magerp_special_price',ifield)]",""135"mag_erp_prd_11","magento1324","product.model_product_product","special_price","in_out","float","result = [('x_magerp_special_price',ifield)]",
136"mag_erp_prd_12","magento1324","product.model_product_product","tier_price","in_out","str","result=[]#no mapping by default","result=[]#no mapping by default"136"mag_erp_prd_12","magento1324","product.model_product_product","tier_price","in_out","str","result=[]#no mapping by default","result=[]#no mapping by default"
137"mag_erp_prd_13","magento1324","product.model_product_product","minimal_price","in_out","float","result = [('x_magerp_minimal_price',ifield)]","137"mag_erp_prd_13","magento1324","product.model_product_product","minimal_price","in_out","float","result = [('x_magerp_minimal_price',ifield)]","
138if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0:138if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0:

Subscribers

People subscribed via source and target branches

to status/vote changes: