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

Proposed by Sharoon Thomas http://openlabs.co.in on 2010-05-08
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 on 2010-08-25
MagentoERPConnect core editors 2010-05-08 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.
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

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> on 2010-05-08

[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
1=== modified file 'partner.py'
2--- partner.py 2010-01-02 18:43:26 +0000
3+++ partner.py 2010-05-08 12:45:41 +0000
4@@ -41,6 +41,63 @@
5 _defaults = {
6 'is_magento_order_address': lambda * a:False,
7 }
8+
9+ def mage_to_oe_address(self, cr, uid ,magento_address, address_default):
10+ oe_address = {}
11+ oe_address['city'] = magento_address.get('city',False)
12+ if magento_address['address_type'] == 'billing':
13+ type = 'invoice'
14+ elif magento_address['address_type'] == 'shipping':
15+ type = 'delivery'
16+ oe_address['city']= magento_address.get('city',False)
17+ oe_address['zip']= magento_address.get('postcode',False)
18+ oe_address['fax']= magento_address.get('fax', False)
19+ oe_address['phone']= magento_address.get('telephone', False)
20+ if magento_address.get('street', False):
21+ street = magento_address['street'].split('\n')
22+ oe_address['street']= street[0]
23+ if len(street) ==2:
24+ oe_address['street2'] = street[1]
25+ mag_country_code = magento_address.get('country_id', '')
26+ mag_country_id = self.pool.get('res.country').search(cr, uid, [('code' , '=', mag_country_code)])[0]
27+ partner_name = ''
28+ if magento_address['firstname']:
29+ partner_name+= magento_address['firstname']
30+# if magento_address['middlename'] :
31+# partner_name+= ' ' + magento_address['middlename']
32+ if magento_address['lastname'] :
33+ partner_name+= ' ' + magento_address['lastname']
34+ oe_address['name'] = partner_name
35+ oe_address['type'] = type
36+ oe_address['partner_id'] = address_default['partner_id']
37+ oe_address['country_id'] = mag_country_id
38+ return oe_address
39+
40+ def find_or_create(self, cr, uid, magento_address, external_referential_id, address_default, context={}):
41+ logger = netsvc.Logger()
42+ create_ids = []
43+ write_ids = []
44+ oe_address = self.mage_to_oe_address(cr, uid, magento_address, address_default)
45+ args = [(key,'=',oe_address.get(key)) for key in oe_address.keys()]
46+ addr_id = self.search(cr,uid,args,context=context)
47+ if magento_address['is_active'] == 1:
48+ active = True
49+ else:
50+ active = False
51+ #oe_address['active'] = active # this should not be a basis of creating a new address.
52+ oe_address['email'] = address_default.get('email', False)
53+ if not addr_id :
54+ # create address
55+ crid= self.create(cr, uid, oe_address, context)
56+ create_ids.append(crid)
57+ 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))
58+ return {'create_ids': create_ids, 'write_ids': []}
59+ else:
60+ self.write(cr, uid, addr_id[0], oe_address, context)
61+ write_ids.append(addr_id[0])
62+ 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]))
63+ return {'write_ids': write_ids, 'create_ids': []}
64+
65 res_partner_address()
66
67 class res_partner(magerp_osv.magerp_osv):
68
69=== modified file 'sale.py'
70--- sale.py 2010-03-26 17:32:47 +0000
71+++ sale.py 2010-05-08 12:45:41 +0000
72@@ -251,13 +251,11 @@
73 shipping_default = {'partner_id': res.get('partner_id', False)}
74 billing_default = shipping_default.copy()
75 billing_default.update({'email' : data_record.get('customer_email', False)})
76-
77- inv_res = partner_address_obj.ext_import(cr, uid, [data_record['billing_address']], external_referential_id, billing_default, context)
78+ inv_res = partner_address_obj.find_or_create(cr, uid, data_record['billing_address'], external_referential_id, address_default, context)
79 if 'address_type' in data_record['shipping_address']:
80- ship_res = partner_address_obj.ext_import(cr, uid, [data_record['shipping_address']], external_referential_id, shipping_default, context)
81+ ship_res = partner_address_obj.find_or_create(cr, uid, data_record['shipping_address'], external_referential_id, address_default, context)
82 else:
83- ship_res = partner_address_obj.ext_import(cr, uid, [data_record['billing_address']], external_referential_id, shipping_default, context)
84-
85+ ship_res = partner_address_obj.find_or_create(cr, uid, data_record['billing_address'], external_referential_id, address_default, context)
86 res['partner_order_id'] = len(inv_res['create_ids']) > 0 and inv_res['create_ids'][0] or inv_res['write_ids'][0]
87 res['partner_invoice_id'] = res['partner_order_id']
88 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
89@@ -337,6 +335,28 @@
90 'tax_id': tax_id
91 }))
92 return res
93+
94+ def get_order_discount(self, cr, uid, res, data_record, context):
95+ if float(data_record['discount_amount']) == 0 :
96+ discount = 0.0
97+ else :
98+ discount = -float(data_record['discount_amount'])
99+ discount_product_id = self.pool.get('product.product').search(cr, uid, [('default_code', '=', 'DISCOUNT MAGENTO')])[0]
100+ discount_product = self.pool.get('product.product').browse(cr, uid, discount_product_id, context)
101+ coupon_code = data_record.get('coupon_code', False)
102+ if coupon_code:
103+ name = 'Discount[Coupon Code: %s]' % coupon_code
104+ else:
105+ name = 'Discount'
106+ res['order_line'].append((0, 0, {
107+ 'product_id': discount_product.id,
108+ 'name': discount_product.name,
109+ 'product_uom': discount_product.uom_id.id,
110+ 'product_uom_qty': 1,
111+ 'price_unit': discount,
112+ 'name': name
113+ }))
114+ return res
115
116 def oevals_from_extdata(self, cr, uid, external_referential_id, data_record, key_field, mapping_lines, defaults, context):
117 res = super(magerp_osv.magerp_osv, self).oevals_from_extdata(cr, uid, external_referential_id, data_record, key_field, mapping_lines, defaults, context)
118@@ -344,6 +364,7 @@
119 if not context.get('one_by_one', False):
120 if data_record.get('billing_address', False):
121 res = self.get_order_addresses(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context)
122+ res = self.get_order_discount(cr, uid, res, data_record, context)
123 if data_record.get('items', False):
124 try:
125 res = self.get_order_lines(cr, uid, res, external_referential_id, data_record, key_field, mapping_lines, defaults, context)
126
127=== modified file 'settings/external.mappinglines.template.csv'
128--- settings/external.mappinglines.template.csv 2010-03-16 13:59:26 +0000
129+++ settings/external.mappinglines.template.csv 2010-05-08 12:45:41 +0000
130@@ -32,7 +32,7 @@
131 "mag_erp_soline_uomqty","magento1324","sale.model_sale_order_line","qty_ordered","in_out","str","result=[('product_uom_qty',ifield)]",
132 "mag_erp_soline_uosqty","magento1324","sale.model_sale_order_line","qty_ordered","in","str","result=[('product_uos_qty',ifield)]",
133 "mag_erp_soline_price","magento1324","sale.model_sale_order_line","price","in","str","result=[('price_unit', float(data['row_total'])/float(data['qty_ordered']))]",
134-"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)]",
135+"mag_erp_soline_disc","magento1324","sale.model_sale_order_line","discount_amount","in","str","result=[('discount', 0.0)]",
136 "mag_erp_procat_2","magento1324","product.model_product_category","level","in","int","result=[('sequence',ifield),('level',ifield)]",
137 "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))])
138 parent_id = False
139@@ -132,7 +132,7 @@
140 "mag_erp_prd_8","magento1324","product.model_product_product","price","in_out","float","result=[('list_price',ifield)]","result=[]#map later"
141 "mag_erp_prd_9","magento1324","product.model_product_product","cost","in_out","float","result=[('standard_price',ifield)]","result = [('cost',record['standard_price'] or 0)]"
142 "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))]",
143-"mag_erp_prd_11","magento1324","product.model_product_product","special_price","in_out","float","result = [('x_magerp_special_price',ifield)]",""
144+"mag_erp_prd_11","magento1324","product.model_product_product","special_price","in_out","float","result = [('x_magerp_special_price',ifield)]",
145 "mag_erp_prd_12","magento1324","product.model_product_product","tier_price","in_out","str","result=[]#no mapping by default","result=[]#no mapping by default"
146 "mag_erp_prd_13","magento1324","product.model_product_product","minimal_price","in_out","float","result = [('x_magerp_minimal_price',ifield)]","
147 if record['x_magerp_minimal_price'] and record['x_magerp_minimal_price'] != 0:

Subscribers

People subscribed via source and target branches

to status/vote changes: