Merge lp:~camptocamp/magentoerpconnect/oerp6.1-oldstable-stock-config-1070726 into lp:magentoerpconnect/oerp6.1-oldstable

Proposed by Guewen Baconnier @ Camptocamp on 2012-10-24
Status: Merged
Merged at revision: 663
Proposed branch: lp:~camptocamp/magentoerpconnect/oerp6.1-oldstable-stock-config-1070726
Merge into: lp:magentoerpconnect/oerp6.1-oldstable
Diff against target: 70 lines (+19/-1)
3 files modified
magentoerpconnect/magerp_osv.py (+4/-1)
magentoerpconnect/product.py (+14/-0)
magentoerpconnect/product_view.xml (+1/-0)
To merge this branch: bzr merge lp:~camptocamp/magentoerpconnect/oerp6.1-oldstable-stock-config-1070726
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp code review, no test 2012-10-24 Approve on 2012-12-05
Review via email: mp+131178@code.launchpad.net

Description of the change

lp:1070726

Allows to choose if the product should:
 * have a stock
 * not have a stock
 * use the default configuration of magento

A sql query in the init of the module ensures that the values are initialized to "use_default" when we update the module.

That's basically a port of this feature from the the oerp6.1-stable branch.

To post a comment you must log in.
567. By Guewen Baconnier @ Camptocamp <email address hidden> on 2012-10-24

[FIX] debug? no!

I would be glad to have someone review my branch.

Thanks

LGTM

review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'magentoerpconnect/magerp_osv.py'
2--- magentoerpconnect/magerp_osv.py 2012-07-05 12:55:29 +0000
3+++ magentoerpconnect/magerp_osv.py 2012-10-24 13:13:21 +0000
4@@ -116,7 +116,10 @@
5 self.logger.error(_("Method: %s\nArguments:%s\nError:%s"), method, arguments, e, exc_info=True)
6 self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time)
7 time.sleep(sleep_time)
8- raise
9+ raise
10+ except xmlrpclib.Fault, exc:
11+ self.logger.error('call to %s%s failed: %s', method, tuple(arguments), exc)
12+ raise
13
14
15 def fetch_image(self, imgloc):
16
17=== modified file 'magentoerpconnect/product.py'
18--- magentoerpconnect/product.py 2012-08-23 13:28:10 +0000
19+++ magentoerpconnect/product.py 2012-10-24 13:13:21 +0000
20@@ -1161,17 +1161,29 @@
21 'tier_price':fields.one2many('product.tierprice', 'product', 'Tier Price'),
22 'product_type': fields.selection(_product_type_get, 'Magento Product Type'),
23 'magento_exported': fields.function(_is_magento_exported, type="boolean", method=True, string="Exists on Magento"), # used to set the sku readonly when already exported
24+ 'mag_manage_stock': fields.selection([
25+ ('use_default','Use Default Config'),
26+ ('no', 'Do Not Manage Stock'),
27+ ('yes','Manage Stock')],
28+ 'Manage Stock Level', required=True),
29 }
30
31 _defaults = {
32 'magento_exportable': True,
33 'product_type': 'simple',
34+ 'mag_manage_stock': 'use_default',
35 }
36
37 _sql_constraints = [
38 ('magento_sku_uniq', 'unique (magento_sku)', 'The Magento SKU should be uniq!'),
39 ]
40
41+ def init(self, cr):
42+ """Initialize the empty magento manage stock option to the use_default when we
43+ update the module"""
44+ cr.execute("UPDATE product_product SET mag_manage_stock = 'use_default' "
45+ "WHERE mag_manage_stock IS NULL")
46+
47 def write(self, cr, uid, ids, vals, context=None):
48 if vals.get('referential_id', False):
49 instance = vals['referential_id']
50@@ -1541,6 +1553,8 @@
51 'virtual_available')
52 stock_quantity = product[stock_field]
53 return {'qty': stock_quantity,
54+ 'manage_stock': int(product.mag_manage_stock == 'yes'),
55+ 'use_config_manage_stock': int(product.mag_manage_stock == 'use_default'),
56 # put the stock availability to "out of stock"
57 'is_in_stock': int(stock_quantity > 0)}
58
59
60=== modified file 'magentoerpconnect/product_view.xml'
61--- magentoerpconnect/product_view.xml 2012-03-28 09:58:18 +0000
62+++ magentoerpconnect/product_view.xml 2012-10-24 13:13:21 +0000
63@@ -280,6 +280,7 @@
64 <field name="set" select="2" attrs="{'required':[('magento_exportable','==',True)], 'readonly': [('magento_exported', '=', True)]}"/>
65 <field name="magento_sku" select="2" attrs="{'required':[('magento_exportable','==',True)]}"/>
66 <field name="product_type" select="2" attrs="{'required':[('magento_exportable','==',True)]}"/>
67+ <field name="mag_manage_stock" select="2" attrs="{'required':[('magento_exportable','==',True)]}"/>
68 <field name="magento_exportable"/>
69 <field name="magento_exported" invisible="1" />
70 </group>