Example #1
0
 def buildOrderCoreFields(self):
     # ==================================================================== #
     # Order Final Customer
     FieldFactory.create(
         ObjectsHelper.encode("ThirdParty", const.__SPL_T_ID__),
         "partner_id", "Customer")
     FieldFactory.microData("http://schema.org/Organization", "ID")
     FieldFactory.group("General")
     FieldFactory.isRequired()
     # ==================================================================== #
     # Order Billing Address
     FieldFactory.create(
         ObjectsHelper.encode("Address", const.__SPL_T_ID__),
         "partner_invoice_id", "Invoice Address")
     FieldFactory.microData("http://schema.org/Order", "billingAddress")
     FieldFactory.group("General")
     FieldFactory.isRequired()
     # ==================================================================== #
     # Order Shipping Address
     FieldFactory.create(
         ObjectsHelper.encode("Address", const.__SPL_T_ID__),
         "partner_shipping_id", "Shipping Address")
     FieldFactory.microData("http://schema.org/Order", "orderDelivery")
     FieldFactory.group("General")
     FieldFactory.isRequired()
     # ==================================================================== #
     # Order Date
     FieldFactory.create(const.__SPL_T_DATE__, "date_order", "Order Date")
     FieldFactory.microData("http://schema.org/Order", "orderDate")
     FieldFactory.group("General")
     FieldFactory.isRequired()
Example #2
0
 def buildParentFields(self):
     FieldFactory.create(
         ObjectsHelper.encode("ThirdParty", const.__SPL_T_ID__),
         "parent_id", "Parent")
     FieldFactory.microData("http://schema.org/Organization", "ID")
     if self.name is "Address":
         FieldFactory.isRequired()
Example #3
0
    def complete_values(line_data):
        """
        Complete Order Line values with computed Information
        - Detect Product ID based on Line Name


        :param line_data: dict
        :rtype: dict
        """
        from odoo.addons.splashsync.helpers import M2OHelper

        # ====================================================================#
        # Detect Wrong or Empty Product ID
        # ====================================================================#
        try:
            if not M2OHelper.verify_id(
                    ObjectsHelper.id(line_data["product_id"]),
                    'product.product'):
                raise Exception("Invalid Product ID")
        except Exception:
            # ====================================================================#
            # Try detection based on Line Description
            try:
                product_id = M2OHelper.verify_name(line_data["name"],
                                                   'default_code',
                                                   'product.product')
                if int(product_id) > 0:
                    line_data["product_id"] = ObjectsHelper.encode(
                        "Product", str(product_id))
            except Exception:
                pass

        return line_data
Example #4
0
    def getVariantsFields(self, index, field_id):
        # ==================================================================== #
        # Check if this Variant Field...
        base_field_id = ListHelper.initOutput(self._out, "variants", field_id)
        if base_field_id is None:
            return
        # ==================================================================== #
        # Check if Product has Variants
        if not AttributesHelper.has_attr(self.object):
            self._in.__delitem__(index)
            return
        # ==================================================================== #
        # List Product Variants Ids
        for variant in self.object.with_context(
                active_test=False).product_variant_ids:
            # ==================================================================== #
            # Debug Mode => Filter Current Product From List
            if Framework.isDebugMode() and variant.id == self.object.id:
                continue
            # ==================================================================== #
            # Read Variant Data
            if base_field_id == "id":
                value = ObjectsHelper.encode("Product", str(variant.id))
            elif base_field_id == "sku":
                value = str(variant.code)
            ListHelper.insert(self._out, "variants", field_id,
                              "var-" + str(variant.id), value)

        self._in.__delitem__(index)
Example #5
0
    def buildVariantsFields(self):

        # ==================================================================== #
        # Product Variation Parent Link
        FieldFactory.create(const.__SPL_T_VARCHAR__, "variant_template",
                            "Template ID")
        FieldFactory.name("Template ID")
        FieldFactory.group("Meta")
        FieldFactory.microData("http://schema.org/Product", "isVariationOf")
        FieldFactory.isReadOnly()

        # ==================================================================== #
        # CHILD PRODUCTS INFORMATION
        # ==================================================================== #

        # ==================================================================== #
        # Product Variation List - Product Link
        FieldFactory.create(
            ObjectsHelper.encode("Product", const.__SPL_T_ID__), "id")
        FieldFactory.name("Variant ID")
        FieldFactory.inlist("variants")
        FieldFactory.microData("http://schema.org/Product", "Variants")
        FieldFactory.isNotTested()

        FieldFactory.create(const.__SPL_T_VARCHAR__, "sku")
        FieldFactory.name("Variant SKU")
        FieldFactory.inlist("variants")
        FieldFactory.isReadOnly()
Example #6
0
    def buildLinesFields(self):
        """Build Order Lines Fields"""

        from odoo.addons.splashsync.helpers import SettingsManager, TaxHelper

        # ==================================================================== #
        # [CORE] Order Line Fields
        # ==================================================================== #

        # ==================================================================== #
        # Linked Product ID
        FieldFactory.create(
            ObjectsHelper.encode("Product", const.__SPL_T_ID__), "product_id",
            "Product ID")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/Product", "productID")
        FieldFactory.association("product_uom_qty@lines", "price_unit@lines")
        # ==================================================================== #
        # Description
        FieldFactory.create(const.__SPL_T_VARCHAR__, "name", "Product Desc.")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/partOfInvoice",
                               "description")
        FieldFactory.association("product_id@lines", "product_uom_qty@lines",
                                 "price_unit@lines")
        # ==================================================================== #
        # Qty Ordered
        FieldFactory.create(const.__SPL_T_INT__, "product_uom_qty",
                            "Ordered Qty")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/QuantitativeValue", "value")
        FieldFactory.association("product_id@lines", "product_uom_qty@lines",
                                 "price_unit@lines")
        # ==================================================================== #
        # Qty Shipped/Delivered
        FieldFactory.create(const.__SPL_T_INT__, "qty_delivered_manual",
                            "Delivered Qty")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/OrderItem", "orderDelivery")
        FieldFactory.association("product_id@lines", "product_uom_qty@lines",
                                 "price_unit@lines")

        FieldFactory.isReadOnly()

        # ==================================================================== #
        # Qty Invoiced
        FieldFactory.create(const.__SPL_T_INT__, "qty_invoiced",
                            "Invoiced Qty")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/OrderItem", "orderQuantity")
        FieldFactory.association("product_id@lines", "product_uom_qty@lines",
                                 "price_unit@lines")
        FieldFactory.isReadOnly()
        # ==================================================================== #
        # Line Unit Price (HT)
        FieldFactory.create(const.__SPL_T_PRICE__, "price_unit", "Unit Price")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/PriceSpecification", "price")
        FieldFactory.association("product_id@lines", "product_uom_qty@lines",
                                 "price_unit@lines")
        # ==================================================================== #
        # Line Unit Price Reduction (Percent)
        FieldFactory.create(const.__SPL_T_DOUBLE__, "discount", "Discount")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/Order", "discount")
        FieldFactory.association("product_id@lines", "product_uom_qty@lines",
                                 "price_unit@lines")
        # ==================================================================== #
        # Sales Taxes (One)
        FieldFactory.create(const.__SPL_T_VARCHAR__, "tax_name", "Tax Name")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/PriceSpecification",
                               "valueAddedTaxName")
        FieldFactory.addChoices(TaxHelper.get_name_values("sale"))
        FieldFactory.isReadOnly(not SettingsManager.is_sales_adv_taxes())
        FieldFactory.isNotTested()
        # ==================================================================== #
        # Sales Taxes (Multi)
        FieldFactory.create(const.__SPL_T_INLINE__, "tax_names", "Taxes")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/PriceSpecification",
                               "valueAddedTaxNames")
        FieldFactory.addChoices(TaxHelper.get_name_values("sale"))
        FieldFactory.isReadOnly(not SettingsManager.is_sales_adv_taxes())
        FieldFactory.isNotTested()

        # ==================================================================== #
        # [EXTRA] Order Line Fields
        # ==================================================================== #

        # ==================================================================== #
        # Product reference
        FieldFactory.create(const.__SPL_T_VARCHAR__, "product_ref",
                            "Product Ref.")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/Product", "ref")
        FieldFactory.isReadOnly().isNotTested()
        # ==================================================================== #
        # Delivery Lead Time
        FieldFactory.create(const.__SPL_T_DOUBLE__, "lead_time",
                            "Customer LeadTime")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/Offer", "deliveryLeadTime")
        FieldFactory.isNotTested()
        # ==================================================================== #
        # Line Status
        FieldFactory.create(const.__SPL_T_VARCHAR__, "state", "Line Status")
        FieldFactory.inlist("lines")
        FieldFactory.microData("http://schema.org/OrderItem", "LineStatus")
        FieldFactory.isReadOnly().isNotTested()
Example #7
0
    def __get_raw_values(line, field_id):
        """
        Line Single Value for given Field

        :param line: sale.order.line
        :param field_id: str
        :return: dict
        """

        from odoo.addons.splashsync.helpers import CurrencyHelper, TaxHelper, SettingsManager, M2MHelper

        # ==================================================================== #
        # [CORE] Order Line Fields
        # ==================================================================== #

        # ==================================================================== #
        # Linked Product ID
        if field_id == "product_id":
            try:
                return ObjectsHelper.encode("Product",
                                            str(line.product_id[0].id))
            except:
                return None
        # ==================================================================== #
        # Description
        # Qty Ordered | Qty Shipped/Delivered | Qty Invoiced
        # Delivery Lead Time | Line Status
        # Line Unit Price Reduction (Percent)
        if field_id in OrderLinesHelper.__generic_fields:
            if field_id in OrderLinesHelper.__qty_fields:
                return int(getattr(line, field_id))
            return getattr(line, field_id)
        # ==================================================================== #
        # Line Unit Price (HT)
        if field_id == "price_unit":
            return PricesHelper.encode(
                float(line.price_unit),
                TaxHelper.get_tax_rate(
                    line.tax_id if OrderLinesHelper.is_order_line(line) else
                    line.invoice_line_tax_ids, 'sale'), None,
                CurrencyHelper.get_main_currency_code())

        # ==================================================================== #
        # Sales Taxes
        if field_id == "tax_name":
            try:
                tax_ids = line.tax_id if OrderLinesHelper.is_order_line(
                    line) else line.invoice_line_tax_ids
                return tax_ids[0].name
            except:
                return None
        if field_id == "tax_names":
            return M2MHelper.get_names(
                line, "tax_id" if OrderLinesHelper.is_order_line(line) else
                "invoice_line_tax_ids")

        # ==================================================================== #
        # [EXTRA] Order Line Fields
        # ==================================================================== #

        # ==================================================================== #
        # Product reference
        if field_id == "product_ref":
            try:
                return str(line.product_id[0].default_code)
            except:
                return None

        return None