~camptocamp/magentoerpconnect/oerp6.1-oldstable-stock-config-1070726

« back to all changes in this revision

Viewing changes to magentoerpconnect_init_stock/product.py

[MRG] from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Author: Guewen Baconnier
 
5
#    Copyright 2012 Camptocamp SA
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
import logging
 
23
from osv import osv
 
24
 
 
25
_logger = logging.getLogger(__name__)
 
26
 
 
27
 
 
28
class product_product(osv.osv):
 
29
 
 
30
    _inherit = 'product.product'
 
31
 
 
32
    def _magento_init_stock(self, cr, uid, product_id,
 
33
                            magento_id, connection, context=None):
 
34
        # initialize the inventory options on the created product
 
35
        shop = self.pool.get('sale.shop').browse(
 
36
            cr, uid, context['shop_id'], context=context)
 
37
        stock = shop.warehouse_id.lot_stock_id
 
38
        product = self.browse(cr, uid, product_id, context=context)
 
39
        stock_vals = self._prepare_inventory_magento_vals(
 
40
            cr, uid, product, stock, shop, context=context)
 
41
 
 
42
        connection.call('product_stock.update', [magento_id, stock_vals])
 
43
        _logger.info("Successfully initialized inventory "
 
44
                     "options on product with SKU %s " %
 
45
                     (product.magento_sku,))
 
46
        return True
 
47
 
 
48
    def ext_create(self, cr, uid, data, conn, method, oe_id, context):
 
49
        magento_product_id = super(product_product, self).ext_create(
 
50
            cr, uid, data, conn, method, oe_id, context)
 
51
 
 
52
        self._magento_init_stock(cr, uid, oe_id, magento_product_id,
 
53
                                 conn, context=context)
 
54
        return magento_product_id
 
55
 
 
56
product_product()