示例#1
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
示例#2
0
    def create(product, vendor_name, vendor_price):
        """
        Create a Product Supplier Info Object
        :param product: Product
        :param vendor_name: str
        :param vendor_price: float
        :return: None, product.supplierinfo
        """
        from odoo.addons.splashsync.helpers import M2OHelper
        # ====================================================================#
        # Validate Supplier Partner
        vendor_id = M2OHelper.verify_name(vendor_name, "name",
                                          SupplierHelper.vendorDomain,
                                          SupplierHelper.filter)
        if vendor_id is None or vendor_id <= 0:
            return None
        try:
            # ====================================================================#
            # Create Supplier Info
            supplier = SupplierHelper.getModel().create({
                "name": vendor_id,
                "product_id": product.id,
                "min_qty": 1,
                "price": vendor_price,
            })
            # ====================================================================#
            # Connect Supplier Info
            product.seller_ids = [(4, supplier.id, 0)]

            return supplier
        except Exception:
            return None
示例#3
0
 def __set_supplier_values(self, field_id, field_data, supplier):
     """
     Set Product Supplier Fields
     :param field_id: str
     :param field_data: hash
     :param supplier: product.supplierinfo
     :return: None
     """
     # ====================================================================#
     # Set Value
     self._in.__delitem__(field_id)
     if field_id == "supplier_name":
         # ====================================================================#
         # Validate & Update Supplier Partner
         new_currency = M2OHelper.verify_name(field_data, "name",
                                              SupplierHelper.vendorDomain,
                                              SupplierHelper.filter)
         if new_currency is not None and new_currency > 0:
             M2OHelper.set_name(supplier,
                                "name",
                                field_data,
                                domain=SupplierHelper.vendorDomain,
                                filters=SupplierHelper.filter)
     elif field_id == "supplier_sku":
         supplier.product_code = field_data
     elif field_id == "supplier_min_qty":
         supplier.min_qty = field_data
     elif field_id == "supplier_price_dbl":
         supplier.price = field_data
     elif field_id == "supplier_price":
         try:
             supplier.price = float(PricesHelper.taxExcluded(field_data))
         except TypeError:
             supplier.price = 0
     elif field_id == "supplier_currency":
         # ====================================================================#
         # Validate & Update Supplier Partner
         new_currency = M2OHelper.verify_name(field_data, "name",
                                              "res.currency")
         if new_currency is not None and new_currency > 0:
             M2OHelper.set_name(supplier,
                                "currency_id",
                                field_data,
                                domain="res.currency")
示例#4
0
    def __detect_payment_type(mode='inbound'):
        """
        Search for Manual Payment Method Id

        :return: int|None
        """
        from odoo.addons.splashsync.helpers import M2OHelper
        try:
            payment_method_id = M2OHelper.verify_name(
                "manual", "name", "account.payment.method",
                [('payment_type', '=', mode)])
            return payment_method_id if isinstance(
                payment_method_id, int) and payment_method_id > 0 else None
        except:
            return None
示例#5
0
    def __detect_journal_id(journal_code):
        """
        Search for Journal using Payment method Code

        :param journal_code: str

        :return: int|None
        """
        from odoo.addons.splashsync.helpers import M2OHelper
        try:
            journal_id = M2OHelper.verify_name(
                journal_code, "name", "account.journal",
                InvoicePaymentsHelper.__sales_types_filter)
            if isinstance(journal_id, int) and journal_id > 0:
                return journal_id

            from odoo.addons.splashsync.helpers.settings import SettingsManager
            default_id = SettingsManager.get_sales_journal_id()

            return default_id if isinstance(default_id,
                                            int) and default_id > 0 else None
        except:
            return None