def buildSalesRelationFields(self): # ==================================================================== # # Sale Person Name if "user_id" in self.getModel().fields_get(): FieldFactory.create(const.__SPL_T_VARCHAR__, "user_id", "Salesperson Name") FieldFactory.microData("http://schema.org/Author", "name") FieldFactory.addChoices(M2OHelper.get_name_values("res.users")) FieldFactory.group("General") # ==================================================================== # # Sale Person Email if "user_id" in self.getModel().fields_get(): FieldFactory.create(const.__SPL_T_VARCHAR__, "user_email", "Salesperson Email") FieldFactory.microData("http://schema.org/Author", "email") FieldFactory.group("General") FieldFactory.isNotTested() # ==================================================================== # # Sale Team Name if "team_id" in self.getModel().fields_get(): FieldFactory.create(const.__SPL_T_VARCHAR__, "team_id", "Sales team Name") FieldFactory.microData("http://schema.org/Author", "memberOf") FieldFactory.addChoices(M2OHelper.get_name_values("crm.team")) FieldFactory.group("General") FieldFactory.isNotTested()
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
def __get_raw_values(payment, field_id): """ Line Single Value for given Field :param payment: account.payment :param field_id: str :return: dict """ from odoo.addons.splashsync.helpers import M2OHelper # ==================================================================== # # Generic Fields if field_id in InvoicePaymentsHelper.__generic_fields: return getattr(payment, field_id) # ==================================================================== # # Payment Method if field_id == "journal_code": return M2OHelper.get_name(payment, "journal_id", "name") if field_id == "journal_type": return M2OHelper.get_name(payment, "journal_id", "type") if field_id == "journal_name": return M2OHelper.get_name(payment, "journal_id") # ==================================================================== # # Payment Date if field_id == "payment_date": if isinstance(payment.payment_date, date): return payment.payment_date.strftime(const.__SPL_T_DATECAST__) else: return # ==================================================================== # # Payment Amount if field_id == "amount": return float(getattr(payment, field_id))
def setCarrierFields(self, field_id, field_data): # ====================================================================# # Delivery Carrier Name if field_id == "carrier_id": M2OHelper.set_name(self.object, field_id, field_data, domain="delivery.carrier") self._in.__delitem__(field_id)
def getAddressFields(self, index, field_id): # ====================================================================# # Shipping Address Field Requested if field_id.find("__shipping__") < 0: return self._in.__delitem__(index) # ====================================================================# # Remove Pattern from Field Id real_field_id = field_id.replace("__shipping__", "") # ====================================================================# # Detect Shipping Address try: if self.object.partner_shipping_id.id > 0: self.Address = self.object.partner_shipping_id[0] elif self.object.partner_id.id > 0: self.Address = self.object.partner_id[0] else: self._out[field_id] = None return except MissingError: self._out[field_id] = None return # ==================================================================== # # Non Generic Data if real_field_id == "name" and len(self.Address.parent_id) > 0: self._out[field_id] = getattr(self.Address.parent_id, real_field_id) elif real_field_id == "contact": self._out[field_id] = getattr( self.Address, "name") if len(self.Address.parent_id) > 0 else "" elif real_field_id == "country_code": self._out[field_id] = M2OHelper.get_name(self.Address, "country_id", index="code") elif real_field_id == "country_name": self._out[field_id] = M2OHelper.get_name(self.Address, "country_id") elif real_field_id == "state_id": self._out[field_id] = M2OHelper.get_name(self.Address, "state_id", index="code") elif real_field_id == "state_name": self._out[field_id] = M2OHelper.get_name(self.Address, "state_id") # ====================================================================# # Parse generic Fields else: self._out[field_id] = getattr(self.Address, real_field_id)
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
def get_name_values(type_tax_use='sale'): """ Get a Relation Possible Values Dict :param type_tax_use: str :rtype: dict """ from odoo.addons.splashsync.helpers import M2OHelper\ return M2OHelper.get_name_values(TaxHelper.tax_domain, [("type_tax_use", "=", type_tax_use)])
def getSalesRelationFields(self, index, field_id): # Check if Relation Field... if not self.isSalesRelationFields(field_id): return # ==================================================================== # # Sale Person Name if field_id == "user_id": self._out[field_id] = M2OHelper.get_name(self.object, "user_id") self._in.__delitem__(index) # ==================================================================== # # Sale Person Email if field_id == "user_email": self._out[field_id] = M2OHelper.get_name(self.object, "user_id", "email") self._in.__delitem__(index) # ==================================================================== # # Sale Team Name if field_id == "team_id": self._out[field_id] = M2OHelper.get_name(self.object, "team_id") self._in.__delitem__(index)
def getCarrierFields(self, index, field_id): # ====================================================================# # Delivery Carrier Name if field_id == "carrier_id": self._out[field_id] = M2OHelper.get_name(self.object, field_id) self._in.__delitem__(index) # ====================================================================# # Delivery Carrier Description if field_id == "carrier_desc": self._out[ field_id] = self.object.carrier_id.name if self.object.carrier_id.id else None self._in.__delitem__(index)
def setSalesRelationFields(self, field_id, field_data): # Check if Relation Field... if not self.isSalesRelationFields(field_id): return # ==================================================================== # # Sale Person Name if field_id == "user_id": M2OHelper.set_name(self.object, "user_id", field_data, domain="res.users") self._in.__delitem__(field_id) # ==================================================================== # # Sale Person Email if field_id == "user_email": M2OHelper.set_name(self.object, "user_id", field_data, 'email', domain="res.users") self._in.__delitem__(field_id) # ==================================================================== # # Sale Team Name if field_id == "team_id": M2OHelper.set_name(self.object, "team_id", field_data, domain="crm.team") self._in.__delitem__(field_id)
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
def buildSupplierFields(self): # ==================================================================== # # Safety Check if "seller_ids" not in self.getModel().fields_get(): return # ====================================================================# # First Supplier Name FieldFactory.create(const.__SPL_T_VARCHAR__, "supplier_name", "Supplier Name") FieldFactory.microData("http://schema.org/Product", "supplierName") FieldFactory.addChoices( M2OHelper.get_name_values(SupplierHelper.vendorDomain, SupplierHelper.filter)) FieldFactory.isNotTested() # ====================================================================# # First Supplier Price as Double FieldFactory.create(const.__SPL_T_DOUBLE__, "supplier_price_dbl", "Supplier Price (Float)") FieldFactory.microData("http://schema.org/Product", "supplierPriceDbl") FieldFactory.association("supplier_name") # ==================================================================== # # First Supplier Price FieldFactory.create(const.__SPL_T_PRICE__, "supplier_price", "Supplier Price") FieldFactory.microData("http://schema.org/Product", "supplierPrice") FieldFactory.isWriteOnly(Framework.isDebugMode()) FieldFactory.isNotTested() # ====================================================================# # First Supplier SKU FieldFactory.create(const.__SPL_T_VARCHAR__, "supplier_sku", "Supplier SKU") FieldFactory.microData("http://schema.org/Product", "mpn") FieldFactory.association("supplier_name", "supplier_price_dbl") # ====================================================================# # First Supplier MOQ FieldFactory.create(const.__SPL_T_INT__, "supplier_min_qty", "Supplier MOQ") FieldFactory.microData("http://schema.org/Product", "supplierMinQty") FieldFactory.association("supplier_name", "supplier_price_dbl") # ====================================================================# # First Supplier Currency FieldFactory.create(const.__SPL_T_CURRENCY__, "supplier_currency", "Supplier Currency") FieldFactory.microData("http://schema.org/Product", "supplierCurrency") FieldFactory.isNotTested()
def buildCarrierFields(self): if "carrier_id" not in self.getModel().fields_get(): return # ====================================================================# # Delivery Carrier Name FieldFactory.create(const.__SPL_T_VARCHAR__, "carrier_id", "Carrier Name") FieldFactory.microData("http://schema.org/ParcelDelivery", "identifier") FieldFactory.addChoices(M2OHelper.get_name_values("delivery.carrier")) FieldFactory.group("General") # ====================================================================# # Delivery Carrier Description FieldFactory.create(const.__SPL_T_VARCHAR__, "carrier_desc", "Carrier Description") FieldFactory.microData("http://schema.org/ParcelDelivery", "provider") FieldFactory.group("General") FieldFactory.isReadOnly()
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
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")
def setProductsRelationsFields(self, field_id, field_data): # Check if Relation Field... if not self.isProductRelationFields(field_id): return # ==================================================================== # # Category if field_id == "categ_id": M2OHelper.set_id(self.object, "categ_id", field_data, domain="product.category", nullable=False) self._in.__delitem__(field_id) if field_id == "categ": M2OHelper.set_name(self.object, "categ_id", field_data, domain="product.category", nullable=False) self._in.__delitem__(field_id) # ==================================================================== # # Routes if field_id == "route_ids": M2MHelper.set_ids(self.object, "route_ids", field_data, domain="stock.location.route") self._in.__delitem__(field_id) if field_id == "routes": M2MHelper.set_names(self.object, "route_ids", field_data, domain="stock.location.route") self._in.__delitem__(field_id) # ==================================================================== # # Public Categories if field_id == "public_categ_ids": M2MHelper.set_ids(self.object, "public_categ_ids", field_data, domain="product.public.category") self._in.__delitem__(field_id) if field_id == "public_categ": M2MHelper.set_names(self.object, "public_categ_ids", field_data, domain="product.public.category") self._in.__delitem__(field_id) # ==================================================================== # # Website Alternate Products if field_id == "alternative_products": M2MHelper.set_names(self.object, "alternative_product_ids", field_data, domain="product.template") self._in.__delitem__(field_id) # ==================================================================== # # Website Alternate Products if field_id == "accessory_products": M2MHelper.set_names(self.object, "accessory_product_ids", field_data, domain="product.product") self._in.__delitem__(field_id) # ==================================================================== # # Allowed Companies if field_id == "company_ids": M2MHelper.set_ids(self.object, "ons_allowed_company_ids", field_data, domain="res.company") self._in.__delitem__(field_id) if field_id == "company_names": M2MHelper.set_names(self.object, "ons_allowed_company_ids", field_data, domain="res.company") self._in.__delitem__(field_id) # ==================================================================== # # Product Brand if field_id == "product_brand_id": M2OHelper.set_id(self.object, "product_brand_id", field_data, domain="product.brand") self._in.__delitem__(field_id) if field_id == "product_brand": M2OHelper.set_name(self.object, "product_brand_id", field_data, domain="product.brand") self._in.__delitem__(field_id) # ==================================================================== # # [Point of Sale] POS Category if field_id == "pos_categ_id": M2OHelper.set_id(self.object, "pos_categ_id", field_data, domain="pos.category") self._in.__delitem__(field_id) if field_id == "pos_categ": M2OHelper.set_name(self.object, "pos_categ_id", field_data, domain="pos.category") self._in.__delitem__(field_id) # ==================================================================== # # [MY LED] Product Tags if field_id == "tag_id": M2MHelper.set_names(self.object, "tag_ids", '["' + field_data + '"]' if isinstance(field_data, str) else None, domain="product.tag") self._in.__delitem__(field_id) if field_id == "tag_ids": M2MHelper.set_names(self.object, "tag_ids", field_data, domain="product.tag") self._in.__delitem__(field_id)
def buildRelationFields(self): # ==================================================================== # # Product Main category FieldFactory.create(const.__SPL_T_VARCHAR__, "categ_id", "Categorie Id") FieldFactory.microData("http://schema.org/Product", "classificationId") FieldFactory.isReadOnly() FieldFactory.create(const.__SPL_T_VARCHAR__, "categ", "Categorie") FieldFactory.microData("http://schema.org/Product", "classification") FieldFactory.addChoices(M2OHelper.get_name_values("product.category")) FieldFactory.isNotTested() # ==================================================================== # # Product Routes FieldFactory.create(const.__SPL_T_VARCHAR__, "route_ids", "Routes Ids") FieldFactory.microData("http://schema.org/Product", "routesId") FieldFactory.isReadOnly() FieldFactory.create(const.__SPL_T_VARCHAR__, "routes", "Routes") FieldFactory.microData("http://schema.org/Product", "routes") FieldFactory.isNotTested() # ==================================================================== # # Website category if "public_categ_ids" in self.getModel().fields_get(): FieldFactory.create(const.__SPL_T_VARCHAR__, "public_categ_ids", "Categorie Id") FieldFactory.microData("http://schema.org/Product", "publicCategoryId") FieldFactory.isReadOnly() FieldFactory.create(const.__SPL_T_INLINE__, "public_categ", "Public Categorie") FieldFactory.microData("http://schema.org/Product", "publicCategory") FieldFactory.addChoices( M2OHelper.get_name_values("product.public.category")) FieldFactory.isNotTested() # ==================================================================== # # Website Alternate Products if "alternative_product_ids" in self.getModel().fields_get(): FieldFactory.create(const.__SPL_T_VARCHAR__, "alternative_products", "Alternate Products Names") FieldFactory.microData("http://schema.org/Product", "alternateModels") FieldFactory.isNotTested() # ==================================================================== # # Website Accessory Products if "accessory_product_ids" in self.getModel().fields_get(): FieldFactory.create(const.__SPL_T_VARCHAR__, "accessory_products", "Accessory Products Names") FieldFactory.microData("http://schema.org/Product", "crossellModels") FieldFactory.isNotTested() # ==================================================================== # # Allowed Companies if "ons_allowed_company_ids" in self.getModel().fields_get(): FieldFactory.create(const.__SPL_T_VARCHAR__, "company_ids", "Companies IDs") FieldFactory.microData("http://schema.org/Product", "allowedCompanies") FieldFactory.isNotTested() FieldFactory.create(const.__SPL_T_VARCHAR__, "company_names", "Companies Names") FieldFactory.microData("http://schema.org/Product", "allowedCompaniesNames") FieldFactory.isNotTested() # ==================================================================== # # Product Brand if "product_brand_id" in self.getModel().fields_get(): FieldFactory.create(const.__SPL_T_VARCHAR__, "product_brand_id", "Brand Id") FieldFactory.microData("http://schema.org/Product", "brandId") FieldFactory.isReadOnly() FieldFactory.create(const.__SPL_T_VARCHAR__, "product_brand", "Brand") FieldFactory.microData("http://schema.org/Product", "brand") FieldFactory.addChoices(M2OHelper.get_name_values("product.brand")) FieldFactory.isNotTested()
def setRelationFields(self, field_id, field_data): # Check if Relation Field... if not self.isRelationFields(field_id): return # ==================================================================== # # Categorie if field_id == "categ_id": M2OHelper.set_id(self.object, "categ_id", field_data, domain="product.category") self._in.__delitem__(field_id) if field_id == "categ": M2OHelper.set_name(self.object, "categ_id", field_data, domain="product.category") self._in.__delitem__(field_id) # ==================================================================== # # Routes if field_id == "route_ids": M2MHelper.set_ids(self.object, "route_ids", field_data, domain="stock.location.route") self._in.__delitem__(field_id) if field_id == "routes": M2MHelper.set_names(self.object, "route_ids", field_data, domain="stock.location.route") self._in.__delitem__(field_id) # ==================================================================== # # Public Categories if field_id == "public_categ_ids": M2MHelper.set_ids(self.object, "public_categ_ids", field_data, domain="product.public.category") self._in.__delitem__(field_id) if field_id == "public_categ": M2MHelper.set_names(self.object, "public_categ_ids", field_data, domain="product.public.category") self._in.__delitem__(field_id) # ==================================================================== # # Website Alternate Products if field_id == "alternative_products": M2MHelper.set_names(self.object, "alternative_product_ids", field_data, domain="product.template") self._in.__delitem__(field_id) # ==================================================================== # # Website Alternate Products if field_id == "accessory_products": M2MHelper.set_names(self.object, "accessory_product_ids", field_data, domain="product.product") self._in.__delitem__(field_id) # ==================================================================== # # Allowed Companies if field_id == "company_ids": M2MHelper.set_ids(self.object, "ons_allowed_company_ids", field_data, domain="res.company") self._in.__delitem__(field_id) if field_id == "company_names": M2MHelper.set_names(self.object, "ons_allowed_company_ids", field_data, domain="res.company") self._in.__delitem__(field_id) # ==================================================================== # # Product Brand if field_id == "product_brand_id": M2OHelper.set_id(self.object, "product_brand_id", field_data, domain="product.brand") self._in.__delitem__(field_id) if field_id == "product_brand": M2OHelper.set_name(self.object, "product_brand_id", field_data, domain="product.brand") self._in.__delitem__(field_id)
def getRelationFields(self, index, field_id): # Check if Relation Field... if not self.isRelationFields(field_id): return # ==================================================================== # # Categorie if field_id == "categ_id": self._out[field_id] = M2OHelper.get_id(self.object, "categ_id") self._in.__delitem__(index) if field_id == "categ": self._out[field_id] = M2OHelper.get_name(self.object, "categ_id") self._in.__delitem__(index) # ==================================================================== # # Routes if field_id == "route_ids": self._out[field_id] = M2MHelper.get_ids(self.object, "route_ids") self._in.__delitem__(index) if field_id == "routes": self._out[field_id] = M2MHelper.get_names(self.object, "route_ids") self._in.__delitem__(index) # ==================================================================== # # Public Categories if field_id == "public_categ_ids": self._out[field_id] = M2MHelper.get_ids(self.object, "public_categ_ids") self._in.__delitem__(index) if field_id == "public_categ": self._out[field_id] = M2MHelper.get_names(self.object, "public_categ_ids") self._in.__delitem__(index) # ==================================================================== # # Website Alternate Products if field_id == "alternative_products": self._out[field_id] = M2MHelper.get_names( self.object, "alternative_product_ids") self._in.__delitem__(index) # ==================================================================== # # Website Accessory Products if field_id == "accessory_products": self._out[field_id] = M2MHelper.get_names(self.object, "accessory_product_ids") self._in.__delitem__(index) # ==================================================================== # # Allowed Companies if field_id == "company_ids": self._out[field_id] = M2MHelper.get_ids(self.object, "ons_allowed_company_ids") self._in.__delitem__(index) if field_id == "company_names": self._out[field_id] = M2MHelper.get_names( self.object, "ons_allowed_company_ids") self._in.__delitem__(index) # ==================================================================== # # Product Brand if field_id == "product_brand_id": self._out[field_id] = M2OHelper.get_id(self.object, "product_brand_id") self._in.__delitem__(index) if field_id == "product_brand": self._out[field_id] = M2OHelper.get_name(self.object, "product_brand_id") self._in.__delitem__(index)