Esempio n. 1
0
 def _update_state_in_prestashop(self, cr, uid, sale_id, state, context=None):
     sale = self.browse(cr, uid, sale_id, context=context)
     external_session = ExternalSession(sale.shop_id.referential_id)
     ext_id = self.get_extid(cr, uid, sale_id, external_session.referential_id.id, context=context)
     if PRESTASHOP_MAP_STATE.get(state):
         external_session.connection.add('order_histories', {'order_history':{
             'id_order': ext_id,
             'id_order_state' : PRESTASHOP_MAP_STATE[state]
             }})
     return True
 def edit_prestashop_order(self, cr, uid, ids, context=None):
     for sale_order in self.browse(cr, uid, ids, context=context):
         external_session = ExternalSession(sale_order.referential_id, sale_order)
         ext_id = sale_order.get_extid(external_session.referential_id.id, context=context)
         prestashop_order = external_session.connection.get('orders', ext_id)
         oe_line_ids = [l.ext_ref_line for l in sale_order.order_line if l.ext_ref_line]
         presta_lines = prestashop_order['order']['associations']['order_rows']['order_row']
         if isinstance(presta_lines, dict): presta_lines = [presta_lines]
         for presta_line in presta_lines:
             if not presta_line['id'] in oe_line_ids:
                 del_line = external_session.connection.delete('order_details', presta_line['id'])
     return True
    def export(self, cr, uid, id, options, context=None):
        if context is None:
            context = {}
        shop_ids = self.read(cr, uid, id, context=context)[0]['shop']
        sale_shop_obj = self.pool.get('sale.shop')
        product_obj = self.pool.get('product.product')
        product_ids = context['active_ids']

        for shop in sale_shop_obj.browse(cr, uid, shop_ids, context=context):
            if not shop.referential_id:
                raise except_osv(
                    _("User Error"),
                    _("The shop '%s' doesn't have any external "
                      "referential are you sure that it's an external sale shop? "
                      "If yes syncronize it before exporting product") %
                    (shop.name, ))
            external_session = ExternalSession(shop.referential_id, shop)
            context = sale_shop_obj.init_context_before_exporting_resource(
                cr,
                uid,
                external_session,
                shop.id,
                'product.product',
                context=context)
            none_exportable_product = set(product_ids) - set(
                [product.id for product in shop.exportable_product_ids])
            if none_exportable_product:
                products = ', '.join([
                    x['name']
                    for x in product_obj.read(cr,
                                              uid,
                                              list(none_exportable_product),
                                              fields=['name'],
                                              context=context)
                ])
                raise except_osv(
                    _("User Error"),
                    _("The product '%s' can not be exported to the shop '%s'. \n"
                      "Please check : \n"
                      "    - if they are in the root category \n"
                      "    - if the website option is correctly configured. \n"
                      "    - if the check box to export the product to the shop is checked"
                      ) % (products, shop.name))
            for product_id in product_ids:
                self._export_one_product(cr,
                                         uid,
                                         external_session,
                                         product_id,
                                         options,
                                         context=context)
        return {'type': 'ir.actions.act_window_close'}
Esempio n. 4
0
 def pay_and_update_rpc(self,
                        cr,
                        uid,
                        shop_id,
                        order_id,
                        resource,
                        context=None):
     shop = self.pool.get('sale.shop').browse(cr, uid, shop_id)
     referential = shop.referential_id
     external_session = ExternalSession(referential, shop)
     order = self.browse(cr, uid, order_id)
     resource = {'payment': {'amount_paid': order.amount_total}}
     return self.paid_and_update(cr, uid, external_session, order_id,
                                 resource, context)
Esempio n. 5
0
    def export_partner(self, cr, uid, id, context=None):
        if context is None:
            context = {}
        shop_ids = self.read(cr, uid, id, context=context)[0]['shop']
        sale_shop_obj = self.pool.get('sale.shop')
        partner_obj = self.pool.get('res.partner')
        addr_obj = self.pool.get('res.partner.address')
        partner_ids = context.get('active_ids')
        if not partner_ids:
            # This should never happen
            raise osv.except_osv(_('User Error'), 'No partner selected!')

        for shop in sale_shop_obj.browse(cr, uid, shop_ids, context=context):
            if not shop.referential_id:
                raise except_osv(
                    _("User Error"),
                    _("The shop '%s' doesn't have any external referential. Are you sure that it's an external sale shop? If yes, synchronize it before exporting partners."
                      % shop.name))
            external_session = ExternalSession(shop.referential_id, shop)
            context = self.pool.get(
                'sale.shop').init_context_before_exporting_resource(
                    cr,
                    uid,
                    external_session,
                    shop.id,
                    'res.partner',
                    context=context)
            for partner in partner_obj.read(cr,
                                            uid,
                                            partner_ids, ['address'],
                                            context=context):
                partner_obj._export_one_resource(cr,
                                                 uid,
                                                 external_session,
                                                 partner['id'],
                                                 context=context)
                partner_obj.write(cr,
                                  uid,
                                  partner['id'], {
                                      'shop_ids': [(4, shop.id)],
                                  },
                                  context=context)
                for address_id in partner['address']:
                    addr_obj._export_one_resource(cr,
                                                  uid,
                                                  external_session,
                                                  address_id,
                                                  context=context)
        return {'type': 'ir.actions.act_window_close'}
 def import_order(self, cr, uid, ids, context=None):
     if context is None:
         context = {}
     shop = self.pool.get('sale.shop').browse(cr,
                                              uid,
                                              context['active_id'],
                                              context=context)
     external_session = ExternalSession(shop.referential_id, shop)
     wizard = self.browse(cr, uid, ids[0], context=context)
     self.pool.get('sale.order')._import_one_resource(cr,
                                                      uid,
                                                      external_session,
                                                      wizard.order_number,
                                                      context=context)
     return {'type': 'ir.actions.act_window_close'}
    def import_product_stocks(self, cr, uid, ids, context=None):
        if context is None:
            context = {}

        product_pool = self.pool.get('product.product')
        inventory_pool = self.pool.get('stock.inventory')
        inventory_line_pool = self.pool.get('stock.inventory.line')
        location_pool = self.pool.get('stock.location')

        wiz = self.browse(cr, uid, ids[0], context=context)
        shop = self.pool.get('sale.shop').browse(cr,
                                                 uid,
                                                 context.get('active_id'),
                                                 context=context)
        external_session = ExternalSession(shop.referential_id, shop)

        inv_id = inventory_pool.create(cr, uid, {'name': 'Shopify Inventory'})

        for product in wiz.product_ids:
            prod_extid = product_pool.get_extid(
                cr,
                uid,
                product.id,
                external_session.referential_id.id,
                context=context)
            if not prod_extid:
                continue
            product_data = product_pool._get_external_resources(
                cr,
                uid,
                external_session,
                prod_extid,
                resource_filter={'fields': 'inventory_quantity'},
                context=context)

            if product_data.get('inventory_quantity'):
                line_val = {
                    'product_id': product.id,
                    'location_id': shop.warehouse_id.lot_stock_id.id,
                    'company_id': shop.company_id.id,
                    'product_qty': float(product_data['inventory_quantity']),
                    'product_uom': product.uom_id.id,
                    'inventory_id': inv_id
                }
                inventory_line_pool.create(cr, uid, line_val, context=context)
        return {'type': 'ir.actions.act_window_close'}
    def import_base_objects(self, cr, uid, ids, context=None):
        cur_referential = self.browse(cr, uid, ids[0], context=context)
        external_session = ExternalSession(cur_referential, cur_referential)

        self.import_resources(cr,
                              uid,
                              ids,
                              'account.tax.group',
                              context=context)

        self._bidirectional_synchro(cr,
                                    uid,
                                    external_session,
                                    obj_readable_name='LANG',
                                    oe_obj=self.pool.get('res.lang'),
                                    ps_field='language_code',
                                    ps_readable_field='name',
                                    compare_function=self._compare_languages,
                                    context=context)

        self._bidirectional_synchro(cr,
                                    uid,
                                    external_session,
                                    obj_readable_name='COUNTRY',
                                    oe_obj=self.pool.get('res.country'),
                                    ps_field='iso_code',
                                    ps_readable_field='name',
                                    compare_function=self._compare_countries,
                                    context=context)

        self._bidirectional_synchro(cr,
                                    uid,
                                    external_session,
                                    obj_readable_name='STATES',
                                    oe_obj=self.pool.get('res.country.state'),
                                    ps_field='iso_code',
                                    ps_readable_field='name',
                                    compare_function=self._compare_states,
                                    context=context)

        self._bidirectional_synchro(cr,
                                    uid,
                                    external_session,
                                    obj_readable_name='CURRENCY',
                                    oe_obj=self.pool.get('res.currency'),
                                    ps_field='iso_code',
                                    ps_readable_field='name',
                                    compare_function=self._compare_currencies,
                                    context=context)

        self._bidirectional_synchro(cr,
                                    uid,
                                    external_session,
                                    obj_readable_name='TAXES',
                                    oe_obj=self.pool.get('account.tax'),
                                    ps_field='rate',
                                    ps_readable_field='name',
                                    compare_function=self._compare_taxes,
                                    context=context)

        return True