clearcorp team mailing list archive
-
clearcorp team
-
Mailing list archive
-
Message #00326
lp:~dr.clearcorp/openerp-ccorp-addons/6.1-static_module_magento into lp:openerp-ccorp-addons
Diana Rodríguez Martínez has proposed merging lp:~dr.clearcorp/openerp-ccorp-addons/6.1-static_module_magento into lp:openerp-ccorp-addons.
Requested reviews:
CLEARCORP drivers (clearcorp-drivers)
For more details, see:
https://code.launchpad.net/~dr.clearcorp/openerp-ccorp-addons/6.1-static_module_magento/+merge/130435
--
https://code.launchpad.net/~dr.clearcorp/openerp-ccorp-addons/6.1-static_module_magento/+merge/130435
Your team CLEARCORP development team is subscribed to branch lp:openerp-ccorp-addons.
=== modified file 'magento_stadistic/magento_stadistic.py'
--- magento_stadistic/magento_stadistic.py 2012-10-12 22:34:13 +0000
+++ magento_stadistic/magento_stadistic.py 2012-10-18 21:41:23 +0000
@@ -19,7 +19,7 @@
_description = 'Magento stadistic info'
_columns = {
'product_ids': fields.many2one('product.product','Product'),
- 'date_out_of_stock': fields.date('Date'),
+ 'date_out_of_stock': fields.datetime('Date'),
'customer_ids': fields.many2one('res.partner','Customer'),
'qty_product':fields.integer('Quantity'),
'address':fields.related('customer_ids','address',type="one2many",relation="res.partner.address",string="Address",store=False)
@@ -36,55 +36,66 @@
'CHECK(qty_product > 0)',
'The quantity of product must be greater than 0.'),
]
- """
- def onchance_customer(self, cr, uid, ids, customer_ids, context={}):
- v={}
- if customer_ids:
- id = self.pool.get('res.partner').search(cr,uid,customer_ids)
- customer = self.pool.get('res.partner').browse(cr,uid,customer_ids)
- v['address']=customer.address.id
- if customer.address.id:
- v['name']=customer.name.id
-
-
- return {'value':v}
- """
- def save_product (self,cr,uid,product_id,customer_id,qty_product):
+
+ def save_product (self,cr,uid,product_id,customer_id,qty_product,date_order):
magento_connect = self.pool.get('sneldev.magento')
- try:
- #First, import the product. If exist, update the info
- magento_connect.import_products(cr, uid,product_id)
-
- #search the product in openerp and save in the magento_stadistic object
- product_ids = []
- product_ids_openerp = self.pool.get('product.product').search(cr, uid, ['magento_id', '=', product_id])
- for product in product_ids_openerp:
- if product.id not in product_ids:
- product_ids.append(product.id)
-
- #Search the customer, if exist, update info and
- magento_connect.import_customers(cr,uid,customer_id)
- customer_ids = []
- customer_ids_openerp = self.pool.get('res.partner').search(cr,uid,['magento_id','=',customer_id])
- for customer in customer_ids_openerp:
- if customer.id not in customer_ids:
- customer_ids.append(customer.id)
-
- today = str(datetime.date.today())
-
- product_of_stock = {
- 'product_ids':[(6, 0, product_ids )],
- 'date_out_of_stock': today,
- 'customer_ids':[(6, 0, customer_ids )],
- 'qty_product':qty_product,
- }
-
- self.pool.get('magento.stadistic').create(cr, uid, product_of_stock)
-
- except:
- log.append('Cannot create stadistic')
- raise osv.except_osv(_('Error !'), _('Cannot get product, check Magento web user config'))
- traceback.print_exc(file=sys.stdout)
+
+ #First check if the product don't exist in the stadistic
+ list_stadistic = self.pool.get('magento.stadistic').search(cr, uid,
+ [('product_ids', '=', product_id),
+ ('customer_ids','=',customer_id),
+ ('date_out_of_stock','=',date_order)])
+ if len(list_stadistic) == 0:
+ #Import the product. If exist, update the info
+ result = magento_connect.import_products(cr, uid,product_id)
+
+ if result == 0:
+ #search the product in openerp and save in the magento_stadistic object
+ product_ids = []
+ product_ids_search = self.pool.get('product.product').search(cr, uid, [('magento_id', '=', product_id)])
+ product_ids_browse = self.pool.get('product.product').browse(cr, uid, product_ids_search)
+ for product in product_ids_browse:
+ if product.id not in product_ids:
+ product_ids.append(product.id)
+
+ #Search the customer, if exist, update info and
+ magento_connect.import_customers(cr,uid,customer_id)
+ customer_ids = []
+ customer_ids_search = self.pool.get('res.partner').search(cr,uid,[('magento_id','=',customer_id)])
+ customer_ids_browse = self.pool.get('res.partner').browse(cr,uid,customer_ids_search)
+ for customer in customer_ids_browse:
+ if customer.id not in customer_ids:
+ customer_ids.append(customer.id)
+
+ indice = 0
+
+ day = int(date_order[0:2])
+ month = int(date_order[3:5])
+ year = int(date_order[6:11])
+
+ hour = int(date_order[11:13])
+ minute = int(date_order[14:16])
+ second = int(date_order[17:19])
+
+ date_object = datetime.datetime(year,month,day,hour,minute,second)
+
+ for p in product_ids:
+ product_of_stock = {
+ 'product_ids':product_ids[indice],
+ 'date_out_of_stock': date_object,
+ 'customer_ids':customer_ids[0],
+ 'qty_product':qty_product,
+ }
+ indice + 1
+ self.pool.get('magento.stadistic').create(cr, uid, product_of_stock)
+ return 0
+
+ else:
+ raise osv.except_osv(_('Error !'), _('Cannot get product, check Magento web user config'))
+ return -1
+
+ else:
+ raise osv.except_osv(_('Error !'), _('Already exist the stadistic'))
return -1
magento_stadistic()
\ No newline at end of file
=== modified file 'sneldev_magento/sneldev_magento.py'
--- sneldev_magento/sneldev_magento.py 2012-10-08 22:26:26 +0000
+++ sneldev_magento/sneldev_magento.py 2012-10-18 21:41:23 +0000
@@ -576,7 +576,8 @@
##################################################################
# Product import
##################################################################
- def import_products(self, cr, uid):
+ def import_products(self, cr, uid,product_id):
+ products = []
log.define(self.pool.get('sneldev.logs'), cr, uid)
if (export_is_running() == False):
try:
@@ -584,9 +585,6 @@
start_timestamp = str(DateTime.utc())
website_ids = self.pool.get('sneldev.magento').search(cr, uid, [])
magento_params = self.pool.get('sneldev.magento').get_magento_params(cr, uid)
- # Last update
- last_import = magento_params[0].last_imported_product_timestamp
- # Get latest products from Magento
self.pool = pooler.get_pool(cr.dbname)
[status, server, session] = magento_connect(self, cr, uid)
if not status:
@@ -603,15 +601,20 @@
increment = 300
index = 1
while True:
- stop = index + increment - 1
- log.append('Products ID from ' + str(index) + ' to ' + str(stop))
- all_products = server.call(session, 'product.list',[{'product_id': {'from': str(index), 'to': str(stop)}}])
- if last_import:
- products = server.call(session, 'product.list',[{'updated_at': {'from': last_import}, 'product_id': {'from': str(index), 'to': str(stop)}}])
- log.append('Last import: ' + last_import)
- else:
- products = all_products
- index = stop + 1
+ if product_id != '':
+ new_product = server.call(session, 'product.info',[product_id])
+ products.append(new_product)
+ all_products = products
+ else:
+ stop = index + increment - 1
+ log.append('Products ID from ' + str(index) + ' to ' + str(stop))
+ all_products = server.call(session, 'product.list',[{'product_id': {'from': str(index), 'to': str(stop)}}])
+ if last_import:
+ products = server.call(session, 'product.list',[{'updated_at': {'from': last_import}, 'product_id': {'from': str(index), 'to': str(stop)}}])
+ log.append('Last import: ' + last_import)
+ else:
+ products = all_products
+ index = stop + 1
for prod in products:
try:
@@ -619,7 +622,7 @@
info_product = server.call(session, 'product.info',[prod['product_id']])
product = { 'magento_id' : info_product['product_id'],
'name' : info_product['name'],
- 'default_code' : prod['sku'],
+ 'default_code' : info_product['sku'],
'modified' : False,
'export_to_magento': True,
}
@@ -648,6 +651,7 @@
else:
log.append('Default category')
product['categ_id'] = magento_params[0].default_category.id
+
log.append('Updating product ' + product['default_code'] + ' ' + product['name'])
prod_ids = self.pool.get('product.product').search(cr, uid, [('magento_id', '=', product['magento_id'])])
if prod_ids == []:
@@ -672,9 +676,13 @@
set_export_finished()
log.append("Done")
return 0
- log.append('Import already running')
- raise osv.except_osv(_('Error !'), _('Import already running'))
- return -1
+ else:
+ set_export_finished()
+ return 0
+ else:
+ log.append('Import already running')
+ raise osv.except_osv(_('Error !'), _('Import already running'))
+ return -1
##################################################################
# Customer import
@@ -706,7 +714,7 @@
return -1
if customer_id != '':
- new_customer = server.call(session,'customer.info',customer_id)
+ new_customer = server.call(session, 'customer.info',[customer_id])
customers.append(new_customer)
else:
=== modified file 'sneldev_magento/sneldev_magento_menu.xml'
--- sneldev_magento/sneldev_magento_menu.xml 2012-10-10 19:14:10 +0000
+++ sneldev_magento/sneldev_magento_menu.xml 2012-10-18 21:41:23 +0000
@@ -10,8 +10,8 @@
<menuitem id="base.menu_magento" name="Magento" web_icon="static/src/img/magento.png" web_icon_hover="static/src/img/magento.png" />
- <menuitem name="Magento Settings" id="menu_magento_form" parent="base.menu_magento" groups="group_magento_manager"/>
- <menuitem id="base.menu_magento_sub_form" action="action_magento_form" parent="menu_magento_form" name="Magento settings"></menuitem>
+ <menuitem name="Configuration" id="menu_magento_form" parent="base.menu_magento" groups="group_magento_manager"/>
+ <menuitem id="base.menu_magento_sub_form" action="action_magento_form" parent="menu_magento_form" name="Configuration"></menuitem>
<menuitem id="base.import_menu_magento" name="Import" parent="base.menu_magento"/>
<menuitem name="Import categories from Magento" action="action_sneldev_categories_import" parent="base.import_menu_magento" id="base.menu_magento_categories_import" />
=== modified file 'sneldev_magento/wizard/sneldev_magento_products_import.py'
--- sneldev_magento/wizard/sneldev_magento_products_import.py 2012-09-10 15:35:49 +0000
+++ sneldev_magento/wizard/sneldev_magento_products_import.py 2012-10-18 21:41:23 +0000
@@ -39,8 +39,10 @@
}
def do_products_import(self, cr, uid, ids, context=None):
+ product_id = '';
+
self.pool.get('sneldev.magento').import_categories(cr, uid)
- if (self.pool.get('sneldev.magento').import_products(cr, uid) < 0):
+ if (self.pool.get('sneldev.magento').import_products(cr, uid,product_id) < 0):
raise osv.except_osv(('Warning'), ('Import failed, please refer to log file for failure details.'))
return {'type': 'ir.actions.act_window_close'}
Follow ups