Skip to content

Commit

Permalink
instership : END
Browse files Browse the repository at this point in the history
  • Loading branch information
timloic committed May 17, 2024
1 parent fef3f35 commit 8fae0bd
Show file tree
Hide file tree
Showing 38 changed files with 262 additions and 357 deletions.
29 changes: 16 additions & 13 deletions sale_channel/models/sale_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ class SaleChannel(models.Model):
def _scheduler_export(self):
for record in self:
for struct_key in record._get_struct_to_export():
for items in record._get_items_to_export(struct_key):
description = "Export {} from {} whose id is {}".format(
items,
for i, items in enumerate(record._get_items_to_export(struct_key)):
key = f"{i}_export_items_{struct_key}_for_channel_{record.id}"
description = "Export part {} from {}({}) whose id is {}".format(
i,
record.name,
struct_key,
record.id,
)
record.with_delay(description=description)._job_trigger_export(
struct_key, items
)
record.with_delay(
description=description, identity_key=key
)._job_trigger_export(struct_key, items)

def _job_trigger_export(self, struct_key, items):
"""
Expand All @@ -44,7 +46,7 @@ def _get_struct_to_export(self):
"""
Retrieves the item types to export
"""
NotImplementedError("Something is missing")
return []

def _map_items(self, struct_key, items):
"""
Expand All @@ -64,7 +66,7 @@ def _get_items_to_export(self, struct_key):
:return: A list of several lists of Odoo objects to export split
according to a predefined size
"""
raise NotImplementedError("Nothing found to export with %s" % struct_key)
return []

def _trigger_export(self, struct_key, mapped_items):
"""
Expand All @@ -79,19 +81,20 @@ def _trigger_export(self, struct_key, mapped_items):
@abstractmethod
def _scheduler_import(self):
for record in self:
for struct_key in record._get_struct_to_import():
for i, struct_key in enumerate(record._get_struct_to_import()):
key = f"{i}import_{struct_key}_for_channel{record.id}"
description = "Import {} from {} whose id is {}".format(
struct_key,
record.name,
record.id,
)
record.with_delay(description=description)._job_trigger_import(
struct_key
)
record.with_delay(
description=description, identity_key=key
)._job_trigger_import(struct_key)

def _get_struct_to_import(self):
"""Retrieves the item types to import"""
NotImplementedError("Something is missing")
return []

def _job_trigger_import(self, struct_key):
"""
Expand Down
4 changes: 4 additions & 0 deletions sale_channel/models/sale_channel_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ class SaleChannelRelation(models.AbstractModel):
sale_channel_sync_date = fields.Datetime(
help="Date of last import sync for the related record"
)

sale_channel_id = fields.Many2one(
comodel_name="sale.channel", string="sale channel", required=True
)
12 changes: 9 additions & 3 deletions sale_channel/models/sale_order_sale_channel_rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ class SaleOrderSaleChannelRel(models.Model):
_inherit = "sale.channel.relation"
_description = " sale order sale channel relation"

sale_channel_id = fields.Many2one(
comodel_name="sale.channel", string="sale channel"
sale_order_id = fields.Many2one(
comodel_name="sale.order", string="sale order", required=True
)

sale_order_id = fields.Many2one(comodel_name="sale.order", string="sale order")
_sql_constraints = [
(
"unique_sale_order_sale_channel",
"unique(sale_channel_id, sale_order_id)",
"The combination of Sale Channel and Sale Order must be unique",
)
]
3 changes: 0 additions & 3 deletions sale_channel_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
from . import account_fiscal_position
from . import account_analytic_account
from . import account_payment_mode
from . import sale_channel
9 changes: 0 additions & 9 deletions sale_channel_account/models/account_analytic_account.py

This file was deleted.

11 changes: 0 additions & 11 deletions sale_channel_account/models/account_fiscal_position.py

This file was deleted.

9 changes: 0 additions & 9 deletions sale_channel_account/models/account_payment_mode.py

This file was deleted.

2 changes: 0 additions & 2 deletions sale_channel_account/models/sale_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class SaleChannel(models.Model):
analytic_account_id = fields.Many2one(
comodel_name="account.analytic.account",
string="Analytic account",
help="If specified, this analytic account will be used to fill the "
"field on the sale order created by the connector.",
)

payment_mode_id = fields.Many2one(
Expand Down
19 changes: 0 additions & 19 deletions sale_channel_mirakl/mirakl_mapper/country_builder.py

This file was deleted.

4 changes: 4 additions & 0 deletions sale_channel_mirakl/mirakl_mapper/mirakl_billing_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
class MiraklBillingAddress(MiraklImportMapper, MiraklPartnerAddress):

customer_notification_email: str = ""

def build_country(self, sale_channel):
country = sale_channel.default_country_id
return country
6 changes: 0 additions & 6 deletions sale_channel_mirakl/mirakl_mapper/mirakl_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ class MiraklCatalog(MiraklExportMapper):

@classmethod
def map_item(cls, mirakl_channel, product):
"""
Build a mirakl record from an odoo record
:param mirakl_channel: Mirakl channel on which the product is attached
:param product: product to map
:return: a pydantic object corresponding to the form expected by mirakl
"""
cat = product.categ_id.display_name or ""
cat = cat.replace(
"/", ">"
Expand Down
18 changes: 4 additions & 14 deletions sale_channel_mirakl/mirakl_mapper/mirakl_customer.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from .country_builder import CountryBuilder
from typing import Optional

from .mirakl_billing_address import MiraklBillingAddress
from .mirakl_import_mapper import MiraklImportMapper
from .mirakl_shipping_address import MiraklShippingAddress
from .res_partner_builder import ResPartnerBuilder


class MiraklCustomer(MiraklImportMapper, ResPartnerBuilder, CountryBuilder):
class MiraklCustomer(MiraklImportMapper, ResPartnerBuilder):
_odoo_model = "res.partner"
_identity_key = "customer_id"

billing_address: MiraklBillingAddress
locale: str = ""
shipping_address: MiraklShippingAddress
shipping_zone_code: Optional[str] = None

def __init__(self, **kwargs):
"""
Expand All @@ -30,15 +32,3 @@ def __init__(self, **kwargs):
shipping_address["customer_id"] = kwargs.get("customer_id", "") + "_shipping"
kwargs["shipping_address"] = shipping_address
super().__init__(**kwargs)

def build_country(self, sale_channel):
country = super().build_country(sale_channel)
if self.shipping_zone_code:
country = (
sale_channel.env["res.country"].search(
[("code", "=", self.shipping_zone_code)],
limit=1,
)
or country
)
return country
11 changes: 11 additions & 0 deletions sale_channel_mirakl/mirakl_mapper/mirakl_export_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class MiraklExportMapper(BaseModel):
_identity_key = None

def get_key(self):
return getattr(self, self._identity_key, "")

Expand All @@ -14,6 +16,15 @@ def to_json(self):
as keys and the appropriate values to add to the export file
"""

@classmethod
def map_item(cls, mirakl_channel, product):
"""
Build a mirakl record from an odoo record
:param mirakl_channel: Mirakl channel on which the product is attached
:param product: product to map
:return: a pydantic object corresponding to the form expected by mirakl
"""

@classmethod
def get_file_header(cls):
"""
Expand Down
6 changes: 0 additions & 6 deletions sale_channel_mirakl/mirakl_mapper/mirakl_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ class MiraklOffer(MiraklExportMapper):

@classmethod
def map_item(cls, mirakl_channel, product):
"""
Build a mirakl record from an odoo record
:param mirakl_channel: Mirakl channel on which the product is attached
:param product: product to map
:return: a pydantic object corresponding to the form expected by mirakl
"""
relation_prod_channel = product.product_tmpl_id.prod_sale_channel_ids.filtered(
lambda r: r.sale_channel_id == mirakl_channel.channel_id
)
Expand Down
6 changes: 0 additions & 6 deletions sale_channel_mirakl/mirakl_mapper/mirakl_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ class MiraklProduct(MiraklExportMapper):

@classmethod
def map_item(cls, mirakl_channel, product):
"""
Build a mirakl record from an odoo record
:param mirakl_channel: Mirakl channel on which the product is attached
:param product: product to map
:return: a pydantic object corresponding to the form expected by mirakl
"""
cat = product.categ_id.display_name or ""
cat = cat.replace(
"/", ">"
Expand Down
10 changes: 4 additions & 6 deletions sale_channel_mirakl/mirakl_mapper/mirakl_sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ def get_pricelist(self, mirakl_channel):
return product_pricelist

def get_order_lines(self, mirakl_channel):
order_lines_values = []
for order_line in self.order_lines:
order_lines_values.append(
Command.create(order_line.odoo_model_dump(mirakl_channel))
)
return order_lines_values
return [
Command.create(order_line.odoo_model_dump(mirakl_channel))
for order_line in self.order_lines
]

def odoo_model_dump(self, mirakl_channel):
"""
Expand Down
15 changes: 1 addition & 14 deletions sale_channel_mirakl/mirakl_mapper/mirakl_shipping_address.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
from .country_builder import CountryBuilder
from .mirakl_import_mapper import MiraklImportMapper
from .mirakl_partner_address import MiraklPartnerAddress


class MiraklShippingAddress(MiraklImportMapper, MiraklPartnerAddress, CountryBuilder):
class MiraklShippingAddress(MiraklImportMapper, MiraklPartnerAddress):

additional_info: str
shipping_zone_code: str = ""

def build_country(self, sale_channel):
country = super().build_country(sale_channel)
if self.shipping_zone_code:
country = (
sale_channel.env["res.country"].search(
[("code", "=", self.shipping_zone_code)],
limit=1,
)
or country
)
return country
14 changes: 8 additions & 6 deletions sale_channel_mirakl/mirakl_mapper/res_partner_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ def build_name(self):
return name

def build_country(self, sale_channel):
if self.country_iso_code:
country = sale_channel.env["res.country"].search(
[("code", "=", self.country_iso_code)],
limit=1,
country = sale_channel.default_country_id
if self.shipping_zone_code:
country = (
sale_channel.env["res.country"].search(
[("code", "=", self.shipping_zone_code)],
limit=1,
)
or country
)
else:
country = sale_channel.default_country_id
return country

def odoo_model_dump(self, mirakl_channel):
Expand Down
4 changes: 0 additions & 4 deletions sale_channel_mirakl/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from . import mirakl_binding
from . import sale_channel_owner
from . import mirakl_importer
from . import mirakl_res_partner_importer
from . import mirakl_customer_importer
from . import mirakl_sale_order_importer
from . import product_template
from . import product_product
from . import res_partner_sale_channel_rel
from . import res_partner
from . import sale_channel
from . import sale_channel_mirakl
from . import mirakl_sale_order_line_importer
from . import sale_order
from . import product_pricelist
9 changes: 0 additions & 9 deletions sale_channel_mirakl/models/mirakl_binding.py

This file was deleted.

37 changes: 0 additions & 37 deletions sale_channel_mirakl/models/mirakl_customer_importer.py

This file was deleted.

Loading

0 comments on commit 8fae0bd

Please sign in to comment.