Source code for odoo.addons.connector_magento.models.magento_website.common

# -*- coding: utf-8 -*-
# © 2013-2017 Guewen Baconnier,Camptocamp SA,Akretion
# © 2016 Sodexis
# License AGPL-3.0 or later (

from datetime import datetime, timedelta
from odoo import models, fields, api
from odoo.addons.component.core import Component
from ..magento_backend.common import IMPORT_DELTA_BUFFER

[docs]class MagentoWebsite(models.Model): _name = '' _inherit = ['magento.binding', 'magento.config.specializer'] _description = 'Magento Website' _parent_name = 'backend_id' _order = 'sort_order ASC, id ASC' name = fields.Char(required=True, readonly=True) code = fields.Char(readonly=True) sort_order = fields.Integer(string='Sort Order', readonly=True) store_ids = fields.One2many( comodel_name='', inverse_name='website_id', string='Stores', readonly=True, ) import_partners_from_date = fields.Datetime( string='Import partners from date', ) product_binding_ids = fields.Many2many( comodel_name='magento.product.product', string='Magento Products', readonly=True, ) is_multi_company = fields.Boolean(related="backend_id.is_multi_company")
[docs] @api.multi def import_partners(self): import_start_time = for website in self: backend = website.backend_id if website.import_partners_from_date: from_string = fields.Datetime.from_string from_date = from_string(website.import_partners_from_date) else: from_date = None self.env['magento.res.partner'].with_delay().import_batch( backend, filters={'magento_website_id': website.external_id, 'from_date': from_date, 'to_date': import_start_time} ) # Records from Magento are imported based on their `created_at` # date. This date is set on Magento at the beginning of a # transaction, so if the import is run between the beginning and # the end of a transaction, the import of a record may be # missed. That's why we add a small buffer back in time where # the eventually missed records will be retrieved. This also # means that we'll have jobs that import twice the same records, # but this is not a big deal because they will be skipped when # the last `sync_date` is the same. next_time = import_start_time - timedelta(seconds=IMPORT_DELTA_BUFFER) next_time = fields.Datetime.to_string(next_time) self.write({'import_partners_from_date': next_time}) return True
[docs]class WebsiteAdapter(Component): _name = '' _inherit = 'magento.adapter' _apply_on = '' _magento_model = 'ol_websites' _admin_path = 'system_store/editWebsite/website_id/{id}'