class RancherStackExportMapper(Component): _name = 'rancher.export.mapper.stack' _inherit = 'rancher.export.mapper' _apply_on = 'rancher.stack' direct = [('name', 'name'), ('description', 'description'), ('state', 'state'), ('answers', 'environment'), ('docker_compose', 'dockerCompose'), ('rancher_compose', 'rancherCompose'), ('start_on_create', 'startOnCreate'), (m2o_to_external('environment_id', 'rancher.environment'), 'accountId'), (m2o_to_external('application_version_id', 'rancher.application.version'), 'externalId'), ]
class MyMapper(Component): _name = 'my.mapper' _inherit = 'base.import.mapper' _apply_on = 'res.partner' direct = [(m2o_to_external('country_id'), 'country')]
class MyMapper(Component): _name = "my.mapper" _inherit = "base.import.mapper" _apply_on = "res.partner" direct = [(m2o_to_external("country_id"), "country")]
class ProductTemplateExportMapper(Component): _name = 'prestashop.product.template.export.mapper' _inherit = 'translation.prestashop.export.mapper' _apply_on = 'prestashop.product.template' direct = [ ('available_for_order', 'available_for_order'), ('show_price', 'show_price'), ('online_only', 'online_only'), ('standard_price', 'wholesale_price'), (m2o_to_external('default_shop_id'), 'id_shop_default'), ('always_available', 'active'), ('barcode', 'barcode'), ('additional_shipping_cost', 'additional_shipping_cost'), ('minimal_quantity', 'minimal_quantity'), ('on_sale', 'on_sale'), ('date_add', 'date_add'), ('barcode', 'ean13'), (m2o_to_external( 'prestashop_default_category_id', binding='prestashop.product.category'), 'id_category_default'), ('state', 'state'), ] # handled by base mapping `translatable_fields` _translatable_fields = [ ('name', 'name'), ('link_rewrite', 'link_rewrite'), ('meta_title', 'meta_title'), ('meta_description', 'meta_description'), ('meta_keywords', 'meta_keywords'), ('tags', 'tags'), ('available_now', 'available_now'), ('available_later', 'available_later'), ('description_short_html', 'description_short'), ('description_html', 'description'), ] def _get_factor_tax(self, tax): return (1 + tax.amount / 100) if tax.price_include else 1.0 @changed_by('taxes_id', 'list_price', 'lst_price') @mapping def list_price(self, record): tax = record.taxes_id if tax.price_include and tax.amount_type == 'percent': # 6 is the rounding precision used by PrestaShop for the # tax excluded price. we can get back a 2 digits tax included # price from the 6 digits rounded value return { 'price': str( round(record.lst_price / self._get_factor_tax(tax), 6)) } else: return {'price': str(round(record.lst_price, 6))} @changed_by('default_code', 'reference') @mapping def reference(self, record): return {'reference': record.reference or record.default_code or ''} def _get_product_category(self, record): ext_categ_ids = [] binder = self.binder_for('prestashop.product.category') for category in record.categ_ids: ext_categ_ids.append( {'id': binder.to_external(category, wrap=True)}) return ext_categ_ids # To extend in connector_prestashop_feature module. In this way we # dependencies on other modules like product_custom_info # see class FeaturesProductImportMapper # def _get_template_feature(self, record): # template_feature = [] # attribute_binder = self.binder_for( # 'prestashop.product.combination.option') # option_binder = self.binder_for( # 'prestashop.product.combination.option.value') # for line in record.attribute_line_ids: # feature_dict = {} # attribute_ext_id = attribute_binder.to_external( # line.attribute_id.id, wrap=True) # if not attribute_ext_id: # continue # feature_dict = {'id': attribute_ext_id, 'custom': ''} # values_ids = [] # for value in line.value_ids: # value_ext_id = option_binder.to_external(value.id, # wrap=True) # if not value_ext_id: # continue # values_ids.append(value_ext_id) # res = {'id_feature_value': values_ids} # feature_dict.update(res) # template_feature.append(feature_dict) # return template_feature @changed_by( 'attribute_line_ids', 'categ_ids', 'categ_id' ) @mapping def associations(self, record): return { 'associations': { 'categories': { 'category_id': self._get_product_category(record)}, # 'product_features': { # 'product_feature': self._get_template_feature(record)}, } } # TOREVIEW: Tax rules group is not the same that odoo tax groups # @changed_by('taxes_id') # @mapping # def tax_ids(self, record): # if not record.taxes_id: # return # binder = self.binder_for('prestashop.account.tax.group') # ext_id = binder.to_external( # record.taxes_id[:1].tax_group_id, wrap=True) # return {'id_tax_rules_group': ext_id} @changed_by('available_date') @mapping def available_date(self, record): if record.available_date: return {'available_date': record.available_date} return {} @changed_by('weight') @mapping def weight(self, record): return {'weight': round(record.weight, 3)}