当前位置: 首页>>代码示例>>Python>>正文


Python Product.insert方法代码示例

本文整理汇总了Python中product.Product.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Product.insert方法的具体用法?Python Product.insert怎么用?Python Product.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在product.Product的用法示例。


在下文中一共展示了Product.insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create

# 需要导入模块: from product import Product [as 别名]
# 或者: from product.Product import insert [as 别名]
def create(user_id, password, model, vals):
    _check_user(user_id, password)
    odoo_id = vals["odoo_id"]
    if model not in ["customer", "product"]:
        raise Fault("unknown_model", "Reference model does not exist!")
    if model == "customer":
        try:
            customer = Customer.get(Customer.odoo_id == odoo_id)
        except Customer.DoesNotExist:
            q = Customer.insert(**vals)
        else:
            q = Customer.update(**vals).where(Customer.odoo_id == odoo_id)
    else:
        try:
            product = Product.get(Product.odoo_id == odoo_id)
        except Product.DoesNotExist:
            q = Product.insert(**vals)
        else:
            q = Product.update(**vals).where(Product.odoo_id == odoo_id)
    q.execute()
    return True
开发者ID:gitlabuser,项目名称:CMNT_004_15,代码行数:23,代码来源:xmlrpc_interface.py

示例2: read_from_file

# 需要导入模块: from product import Product [as 别名]
# 或者: from product.Product import insert [as 别名]

#.........这里部分代码省略.........
						header = row
						# Process column names from header
						index = 0
						name_col = -1
						val_col = -1
						dev_col = -1
						pkg_col = -1
						desc_col = -1
						prod_col = -1
						bom_attribs = {}	# Key = column index, value = name of attribute
						for column in header:
							col = column.lower()
							if 'part' in col or 'name' in col:
								name_col = index
							elif 'value' in col:
								val_col = index
							elif 'device' in col:
								dev_col = index
							elif 'package' in col:
								pkg_col = index
							elif 'description' in col:
								desc_col = index
							elif 'partno' in col or 'partnum' in col or 'part number' in col or 'part#' in col or ('pn' in col and 'vendor' not in col):
								prod_col = index
							else:
								bom_attribs[index] = column
							index += 1
						if name_col == -1:
							raise KeyError("Component name column not found in header!")
						
					else:
						print 'Row: ', row
						#row_attribs = {}
						row_attribs = dict({})
						row_attribs.clear()
						for attrib in bom_attribs.items():
							if len(row[attrib[0]]) > 0:
								row_attribs[attrib[1]] = row[attrib[0]]
						#print 'Row attribs: ', row_attribs
						# No need for a "name column found" check here,
						# as a KeyError would already have been raised above
						new_name = row[name_col]	
						if val_col != -1:
							new_val = row[val_col]
						else:
							new_val = ""
						if dev_col != -1:
							new_dev = row[dev_col]
						else:
							new_dev = ""
						if pkg_col != -1:
							new_pkg = row[pkg_col]
						else:
							new_pkg = ""
						if desc_col != -1:
							new_desc = row[desc_col]
						else:
							new_desc = ""
						if prod_col != -1:
							prod = Product.select_by_pn(row[prod_col], connection)
							if prod is not None and len(prod) > 0:
								new_prod = prod[0]
							else:
								new_prod = None
						else:
							new_prod = None
						
						part = Part(new_name, self, new_val, new_dev, new_pkg, new_desc, new_prod, row_attribs)
						part.product_updater(connection)
						if part.product is None:
							self.parts.append([part.name, part.value, ''])
						else:
							self.parts.append([part.name, part.value, part.product.manufacturer_pn])
					rownum += 1
					
			else:	# No column headers
				for row in reader:
					print row
					# Check for optional product column
					if len(row) == 6:
						if len(row[5]) > 0:
							prod = Product.select_by_pn(row[5], connection)
							if prod is not None and len(prod) > 0:
								part = Part(row[0], self, row[1], row[2], row[3], row[4], prod[0])
							else:
								new_prod = Product('NULL', row[5])
								new_prod.insert(connection)
								new_prod.scrape(connection)
								part = Part(row[0], self, row[1], row[2], row[3], row[4], new_prod)
						else:
							part = Part(row[0], self, row[1], row[2], row[3], row[4], None)
					else:
						part = Part(row[0], self, row[1], row[2], row[3], row[4], None)
					#print 'Got part from CSV: '
					#part.show() 
					part.product_updater(connection)
					if part.product is None:
						self.parts.append([part.name, part.value, ''])
					else:
						self.parts.append([part.name, part.value, part.product.manufacturer_pn])
开发者ID:jbaker0428,项目名称:Eagle-BOM-Manager,代码行数:104,代码来源:bom.py

示例3: EagleManagerTestCase

# 需要导入模块: from product import Product [as 别名]
# 或者: from product.Product import insert [as 别名]
class EagleManagerTestCase(unittest.TestCase):
	def setUp(self):
		unittest.TestCase.setUp(self)
		from product import *
		from part import Part
		from bom import BOM
		
		self.wspace = Workspace('DB Tests', os.path.join(os.getcwd(), 'testfixtures', 'dbtests.sqlite'))
		
		
		self.test_product = Product('TDK Corporation', 'C1608X5R1E105K', 'general_B11.pdf', 'CAP CER 1UF 25V 10% X5R 0603', '0603 (1608 Metric)')
		self.prices_ct = dict({10 : 0.09000, 100 : 0.04280, 250 : 0.03600, 500 : 0.03016, 1000 : 0.02475})
		self.prices_tr = dict({4000 : 0.01935, 8000 : 0.01800, 12000 : 0.01710, 280000 : 0.01620, 100000 : 0.01227})
		self.prices_dr = dict({10 : 0.09000, 100 : 0.04280, 250 : 0.03600, 500 : 0.03016, 1000 : 0.02475})
		self.test_listing_ct = Listing(VENDOR_DK, '445-5146-1-ND', 'C1608X5R1E105K', self.prices_ct, 566342, 'Cut Tape (CT)', 0, 'Capacitors', 'Ceramic', 'C')
		self.test_listing_tr = Listing(VENDOR_DK, '445-5146-2-ND', 'C1608X5R1E105K', self.prices_tr, 552000, 'Tape & Reel (TR)', 0, 'Capacitors', 'Ceramic', 'C')
		self.test_listing_dr = Listing(VENDOR_DK, '445-5146-6-ND', 'C1608X5R1E105K', self.prices_dr, 566342, 'Digi-Reel', 7, 'Capacitors', 'Ceramic', 'C')
		self.test_product.listings[self.test_listing_ct.key()] = self.test_listing_ct
		self.test_product.listings[self.test_listing_tr.key()] = self.test_listing_tr
		self.test_product.listings[self.test_listing_dr.key()] = self.test_listing_dr
		self.part_attribs = dict({'TOL' : '10%', 'VOLT' : '25V', 'TC' : 'X5R'})
		
		
	def test_db(self):
		#try:
		self.wspace.create_tables()
		from product import Product, Listing
		from part import Part
		from bom import BOM
		tables = []
		cur = self.wspace.memory.cursor()
		for row in cur.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"):
			tables.append(row[0])
		
		cur.close()
		
		assert 'products' in tables
		assert 'parts' in tables
		assert 'part_attributes' in tables
		assert 'listings' in tables
		assert 'projects' in tables
		assert 'pricebreaks' in tables
		assert 'preferred_listings' in tables
		
		self.test_BOM = BOM.new_project('dbtests', 'Databse Unit tests', '', self.wspace.memory)
		self.wspace.projects = self.wspace.list_projects()
		
		assert len(self.wspace.projects) == 1
		assert 'dbtests' in self.wspace.projects
		
		self.test_part = Part('C1', self.test_BOM, '1uF', 'C-USC0603', 'C0603', 'CAPACITOR, American symbol', self.test_product, self.part_attribs)
		
		self.test_product.insert(self.wspace.memory)
		self.test_listing_ct.insert(self.wspace.memory)
		self.test_listing_tr.insert(self.wspace.memory)
		self.test_listing_dr.insert(self.wspace.memory)
		preferred_listing = self.test_product.get_preferred_listing(self.test_BOM, self.wspace.memory)
		assert preferred_listing is None
		self.test_product.set_preferred_listing(self.test_BOM, self.test_listing_ct, self.wspace.memory)
		preferred_listing = self.test_product.get_preferred_listing(self.test_BOM, self.wspace.memory)
		assert preferred_listing is not None
		assert preferred_listing.key() == self.test_listing_ct.key()
		self.test_product.set_preferred_listing(self.test_BOM, self.test_listing_dr, self.wspace.memory)
		preferred_listing = self.test_product.get_preferred_listing(self.test_BOM, self.wspace.memory)
		assert preferred_listing is not None
		assert preferred_listing.key() == self.test_listing_dr.key()
		self.test_part.insert(self.wspace.memory)
		
		# Product.select_by_pn fetches listings for the product, and fetch_listings fetches the price dicts
		ret_products = Product.select_by_pn(self.test_product.manufacturer_pn, self.wspace.memory)
		assert self.test_product.is_in_db(self.wspace.memory)
				
		# Should only return one result:
		assert len(ret_products) == 1
		
		# Product.equals() calls Listing.equals() as part of the check
		assert len (Listing.select_by_vendor_pn(self.test_listing_ct.vendor_pn, self.wspace.memory)) == 1
		assert len (Listing.select_by_vendor_pn(self.test_listing_tr.vendor_pn, self.wspace.memory)) == 1
		assert len (Listing.select_by_vendor_pn(self.test_listing_dr.vendor_pn, self.wspace.memory)) == 1
		assert len (Listing.select_by_manufacturer_pn(self.test_product.manufacturer_pn, self.wspace.memory)) == 3
		assert self.test_product.equals(ret_products[0])
		
		assert self.test_part.has_attribute('TOL', self.wspace.memory)
		assert self.test_part.has_attribute('VOLT', self.wspace.memory)
		assert self.test_part.has_attribute('TC', self.wspace.memory)
		ret_parts = Part.select_by_name(self.test_part.name, self.wspace.memory, self.test_BOM)
		try:
			assert len(ret_parts) == 1
		except AssertionError:
			print 'Assertion failed: assert len(ret_parts) == 1'
			print 'len(ret_parts): ', len(ret_parts)
			raise AssertionError
		assert self.test_part.equals(ret_parts[0])
		assert self.test_part.is_in_db(self.wspace.memory)
		ret_parts = self.test_BOM.select_parts_by_name(self.test_part.name, self.wspace.memory)
		assert len(ret_parts) == 1
		assert self.test_part.equals(ret_parts[0])
		
		self.test_part.delete(self.wspace.memory)
		assert len(self.test_BOM.select_parts_by_name(self.test_part.name, self.wspace.memory)) == 0
#.........这里部分代码省略.........
开发者ID:jbaker0428,项目名称:Eagle-BOM-Manager,代码行数:103,代码来源:tests.py

示例4: product_updater

# 需要导入模块: from product import Product [as 别名]
# 或者: from product.Product import insert [as 别名]
	def product_updater(self, connection, check_wspace=True):
		''' Checks if the Part is already in the DB. 
		Inserts/updates self into DB depending on:
		- The presence of a matching Part in the DB
		- The value of self.product.manufacturer_pn
		- The product of the matching Part in the DB
		Passing an open connection to this method is recommended. '''
		unset_pn = ('', 'NULL', 'none', None, [])
		if(self.is_in_db(connection)):
			#print "Part of same name already in DB"
			old_part = Part.select_by_name(self.name, connection, self.project)[0]
			if self.equals(old_part, True, True, True, False):
				if self.product is not None and self.product.manufacturer_pn not in unset_pn:
					if old_part.product is not None and old_part.product.manufacturer_pn not in unset_pn:
						# TODO: prompt? Defaulting to old_part.product for now (aka do nothing)
						#print 'Matching CSV and DB parts with non-NULL product mismatch, keeping DB version...'
						pass
					elif old_part.product is None or old_part.product.manufacturer_pn in unset_pn:
						self.update(connection)
				elif self.product is None or self.product.manufacturer_pn in unset_pn:
					if old_part.product is not None and old_part.product.manufacturer_pn not in unset_pn:
						pass	# Do nothing in this case
					elif old_part.product is None or old_part.product.manufacturer_pn in unset_pn:
						(candidate_proj_parts, candidate_wspace_parts) = self.find_similar_parts(connection, check_wspace)
						#print 'first find_similar_parts call'
						candidate_products = self.find_matching_products(candidate_proj_parts, candidate_wspace_parts, connection)
						if len(candidate_products) == 0:
							#print 'No matching products found, nothing to do'
							pass
						elif len(candidate_products) == 1:
							self.product = candidate_products[0]
							#print 'Found exactly one matching product, setting product and updating', #self.show()
							self.update(connection)
						else:
							#print 'Found multiple product matches, prompting for selection...'
							# TODO: Currently going with first result, need to prompt for selection
							self.product = candidate_products[0]
							self.update(connection)
						
			else:	# Value/device/package/attribs mismatch
				if self.product is not None and self.product.manufacturer_pn not in unset_pn:
					self.update(connection)
				elif self.product is None or self.product.manufacturer_pn in unset_pn:
					(candidate_proj_parts, candidate_wspace_parts) = self.find_similar_parts(connection, check_wspace)
					#print 'second find_similar_parts call'
					candidate_products = self.find_matching_products(candidate_proj_parts, candidate_wspace_parts, connection)
					if len(candidate_products) == 0:
						#print 'No matching products found, updating as-is'
						pass
					elif len(candidate_products) == 1:
						self.product = candidate_products[0]
						#print 'Found exactly one matching product, setting product and updating'#, self.show()
					else:
						#print 'Found multiple product matches, prompting for selection...'
						# TODO: Currently going with first result, need to prompt for selection
						self.product = candidate_products[0]
					self.update(connection)
		
		else:
			#print 'Part not in DB'
			if self.product is None or self.product.manufacturer_pn in unset_pn:
				(candidate_proj_parts, candidate_wspace_parts) = self.find_similar_parts(connection, check_wspace)
				#print 'third find_similar_parts call'
				candidate_products = self.find_matching_products(candidate_proj_parts, candidate_wspace_parts, connection)
				if len(candidate_products) == 0:
					#print 'No matching products found, inserting as-is'#, self.show()
					pass
				elif len(candidate_products) == 1:
					self.product = candidate_products[0]
					#print 'Found exactly one matching product, setting product and inserting'#, self.show()
				else:
					#print 'Found multiple product matches, prompting for selection...'
					# TODO: Currently going with first result, need to prompt for selection
					self.product = candidate_products[0]
			else:
				if self.product.is_in_db(connection) == False:
					newprod = Product('NULL', self.product.manufacturer_pn)
					newprod.insert(connection)
					newprod.scrape(connection)
			self.insert(connection)
开发者ID:jbaker0428,项目名称:Eagle-BOM-Manager,代码行数:82,代码来源:part.py


注:本文中的product.Product.insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。