~akretion-team/openerp-connector-ecommerce/openerp-connector-ecommerce-add-fiscal-position-support

« back to all changes in this revision

Viewing changes to base_sale_export_product/wizard/export_product.py

  • Committer: Guewen Baconnier
  • Date: 2014-01-14 09:26:01 UTC
  • Revision ID: guewen.baconnier@camptocamp.com-20140114092601-66t1v1o45931k3t2
[DEL] remove e-commerce-addons modules, just keep connector_ecommerce

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    Base sale export product module for OpenERP
5
 
#    Copyright (C) 2010-2012 Sébastien BEAU <sebastien.beau@akretion.com>
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
 
 
23
 
from openerp.osv.orm import TransientModel
24
 
from openerp.osv import fields
25
 
from openerp.osv.osv import except_osv
26
 
from openerp.tools.translate import _
27
 
from openerp.addons.connector.external_osv import ExternalSession
28
 
 
29
 
class product_export_wizard(TransientModel):
30
 
    _name = 'product.export.wizard'
31
 
    _description = 'product export wizard'
32
 
 
33
 
    _columns = {
34
 
        'shop': fields.many2many('sale.shop', 'shop_rel', 'shop_id', 'product_id', 'Shop', required=True),
35
 
        }
36
 
 
37
 
    def _export_one_product(self, cr, uid, external_session, product_id, options, context=None):
38
 
        product_obj = self.pool.get('product.product')
39
 
        if 'export_product' in options:
40
 
            product_obj._export_one_resource(cr, uid, external_session, product_id, context=context)
41
 
        if 'export_inventory' in options:
42
 
            product_obj.export_inventory(cr, uid, external_session, [product_id], context=context)
43
 
        if 'export_image' in options:
44
 
            product_obj.export_product_images(cr, uid, external_session, [product_id], context=context)
45
 
        return True
46
 
 
47
 
    def export(self, cr, uid, id, options, context=None):
48
 
        if context is None:
49
 
            context={}
50
 
        shop_ids = self.read(cr, uid, id, context=context)[0]['shop']
51
 
        sale_shop_obj = self.pool.get('sale.shop')
52
 
        product_obj = self.pool.get('product.product')
53
 
        product_ids = context['active_ids']
54
 
 
55
 
        for shop in sale_shop_obj.browse(cr, uid, shop_ids, context=context):
56
 
            if not shop.referential_id:
57
 
                raise except_osv(_("User Error"),
58
 
                                _("The shop '%s' doesn't have any external "
59
 
                                "referential are you sure that it's an external sale shop? "
60
 
                                "If yes syncronize it before exporting product")%(shop.name,))
61
 
            external_session = ExternalSession(shop.referential_id, shop)
62
 
            context = sale_shop_obj.init_context_before_exporting_resource(cr, uid, external_session, shop.id, 'product.product', context=context)
63
 
            none_exportable_product = set(product_ids) - set([product.id for product in shop.exportable_product_ids])
64
 
            if none_exportable_product:
65
 
                products = ', '.join([x['name'] for x in product_obj.read(cr, uid, list(none_exportable_product), fields = ['name'], context=context)])
66
 
                raise except_osv(_("User Error"),
67
 
                        _("The product '%s' can not be exported to the shop '%s'. \n"
68
 
                        "Please check : \n"
69
 
                        "    - if they are in the root category \n"
70
 
                        "    - if the website option is correctly configured. \n"
71
 
                        "    - if the check box to export the product to the shop is checked")%(products, shop.name))
72
 
            for product_id in product_ids:
73
 
                self._export_one_product(cr, uid, external_session, product_id, options, context=context)
74
 
        return {'type': 'ir.actions.act_window_close'}
75
 
 
76
 
    def export_product(self, cr, uid, id, context=None):
77
 
        return self.export(cr, uid, id, ['export_product'], context)
78
 
 
79
 
    def export_inventory(self, cr, uid, id, context=None):
80
 
        return self.export(
81
 
            cr, uid, id, ['export_inventory'], context)
82
 
 
83
 
    def export_image(self, cr, uid, id, context=None):
84
 
        return self.export(
85
 
            cr, uid, id, ['export_image'], context)
86
 
 
87
 
    def _get_all_options(self, cr, uid, context=None):
88
 
        return ['export_product', 'export_inventory', 'export_image']
89
 
 
90
 
    def export_all(self, cr, uid, id, context=None):
91
 
        return self.export(cr, uid, id, self._get_all_options(cr, uid, context=context), context)