~openerp-community/prestashoperpconnect/7.0-pass-vals-to-events

« back to all changes in this revision

Viewing changes to prestashoperpconnect/prestashop_model.py

  • Committer: Arthur Vuillard
  • Date: 2013-10-08 14:32:58 UTC
  • Revision ID: arthur.vuillard@akretion.com-20131008143258-10bf2krszqw98hmg
Add the crons for prestashoperpconnect

Show diffs side-by-side

added added

removed removed

Lines of Context:
171
171
                                                context=context)
172
172
        return True
173
173
 
174
 
    def _prestashop_backend(self, cr, uid, callback, domain=None,
175
 
                            context=None):
 
174
    def import_sale_orders(self, cr, uid, ids, context=None):
 
175
        if not hasattr(ids, '__iter__'):
 
176
            ids = [ids]
 
177
        session = ConnectorSession(cr, uid, context=context)
 
178
        for backend_record in self.browse(cr, uid, ids, context=context):
 
179
            since_date = None
 
180
            if backend_record.import_orders_since:
 
181
                since_date = datetime.strptime(
 
182
                    backend_record.import_orders_since,
 
183
                    DEFAULT_SERVER_DATETIME_FORMAT
 
184
                )
 
185
            import_orders_since.delay(
 
186
                session,
 
187
                backend_record.id,
 
188
                since_date
 
189
            )
 
190
        return True
 
191
 
 
192
    def _scheduler_launch(self, cr, uid, callback, domain=None,
 
193
                          context=None):
176
194
        if domain is None:
177
195
            domain = []
178
196
        ids = self.search(cr, uid, domain, context=context)
181
199
 
182
200
    def _scheduler_update_product_stock_qty(self, cr, uid, domain=None,
183
201
                                            context=None):
184
 
        self._prestashop_backend(cr, uid, self.update_product_stock_qty,
185
 
                                 domain=domain, context=context)
186
 
 
187
 
    def import_sale_orders(self, cr, uid, ids, context=None):
188
 
        if not hasattr(ids, '__iter__'):
189
 
            ids = [ids]
190
 
        session = ConnectorSession(cr, uid, context=context)
191
 
        for backend_record in self.browse(cr, uid, ids, context=context):
192
 
            since_date = None
193
 
            if backend_record.import_orders_since:
194
 
                since_date = datetime.strptime(
195
 
                    backend_record.import_orders_since,
196
 
                    DEFAULT_SERVER_DATETIME_FORMAT
197
 
                )
198
 
            import_orders_since.delay(
199
 
                session,
200
 
                backend_record.id,
201
 
                since_date
202
 
            )
203
 
        return True
204
 
 
205
 
    def update_sale_order(self, cr, uid, ids, context=None):
206
 
        ""
207
 
        if not hasattr(ids, '__iter__'):
208
 
            ids = [ids]
209
 
        ps_product_obj = self.pool['prestashop.product.product']
210
 
        product_ids = ps_product_obj.search(cr, uid,
211
 
                                            [('backend_id', 'in', ids)],
212
 
                                            context=context)
213
 
        ps_product_obj.recompute_magento_qty(cr, uid, product_ids,
214
 
                                             context=context)
215
 
        return True
 
202
        self._scheduler_launch(cr, uid, self.update_product_stock_qty,
 
203
                               domain=domain, context=context)
 
204
 
 
205
    def _scheduler_import_sale_orders(self, cr, uid, domain=None, context=None):
 
206
        self._scheduler_launch(cr, uid, self.import_sale_orders, domain=domain,
 
207
                               context=context)
 
208
 
 
209
    def _scheduler_import_customers(self, cr, uid, domain=None, context=None):
 
210
        self._scheduler_launch(cr, uid, self.import_custmers_since,
 
211
                               domain=domain, context=context)
 
212
 
 
213
    def _scheduler_import_products(self, cr, uid, domain=None, context=None):
 
214
        self._scheduler_launch(cr, uid, self.import_products, domain=domain,
 
215
                               context=context)
 
216
 
 
217
    def _scheduler_import_carriers(self, cr, uid, domain=None, context=None):
 
218
        self._scheduler_launch(cr, uid, self.import_carriers, domain=domain,
 
219
                               context=context)
216
220
 
217
221
 
218
222
class prestashop_binding(orm.AbstractModel):