From d1240e013dbef71afd45e4261f5403b01b11a6a3 Mon Sep 17 00:00:00 2001 From: bch <> Date: Thu, 31 May 2007 07:40:56 +0000 Subject: [PATCH] ESALE_JOOMLA : new version (for languages and multi-categories) bzr revid: bch-2621ed2d19bc4426ca4ac69ef5a9bc7f4120eb6d --- addons/esale_joomla/__terp__.py | 2 +- .../connector/tinyerp-synchro.php | 327 ++++++++++++++++++ addons/esale_joomla/esale_joomla.py | 12 +- addons/esale_joomla/esale_joomla_view.xml | 74 ++-- .../wizard/wizard_esale_import.py | 19 +- .../wizard/wizard_product_export.py | 143 +++++--- .../wizard/wizard_product_stock.py | 50 ++- 7 files changed, 517 insertions(+), 110 deletions(-) diff --git a/addons/esale_joomla/__terp__.py b/addons/esale_joomla/__terp__.py index 154b2322c98..ceb97aa6f8d 100644 --- a/addons/esale_joomla/__terp__.py +++ b/addons/esale_joomla/__terp__.py @@ -4,7 +4,7 @@ "author" : "Tiny", "category" : "Interfaces/CMS & eCommerce", "website" : "http://tinyerp.com", - "depends" : ["product", "stock", "sale"], + "depends" : ["product", "stock", "sale", "account", "account_tax_include",], "description": """Joomla (Virtuemart) eCommerce interface synchronisation. Users can order on the website, orders are automatically imported in Tiny ERP. diff --git a/addons/esale_joomla/connector/tinyerp-synchro.php b/addons/esale_joomla/connector/tinyerp-synchro.php index e69de29bb2d..3a54b581fe7 100644 --- a/addons/esale_joomla/connector/tinyerp-synchro.php +++ b/addons/esale_joomla/connector/tinyerp-synchro.php @@ -0,0 +1,327 @@ +0)?1:0)." where + //products_id=".$tiny_product['esale_joomla_id'].";"); + return new xmlrpcresp(new xmlrpcval(1,"int")); + } + + + function set_product_category($category_id, $product_ids) { + + global $mosConfig_dbprefix; + + foreach($product_ids as $key => $value){ + $result = mysql_query("select count(*) from ".$mosConfig_dbprefix."vm_product_category_xref where category_id=".$category_id." and product_id=".$value.";"); + $row = mysql_fetch_row($result); + if (! $row[0] ){ + mysql_query("insert into ".$mosConfig_dbprefix."vm_product_category_xref values (".$category_id.", ".$value.", NULL);"); + } + } + return new xmlrpcresp(new xmlrpcval(1,"int")); + + } + + function unpublish_product($product_ids){ + global $mosConfig_dbprefix; + mysql_query("update ".$mosConfig_dbprefix."vm_product set product_publish='N' where product_id in (".implode(",",$product_ids).");"); + return new xmlrpcresp(new xmlrpcval(1,"int")); + } + + function debug($s) { + $fp = fopen("/tmp/debug.xmlrpc.txt","a"); + fwrite($fp, $s."\n"); + fclose($fp); + } + + + function set_product($tiny_product){ + global $mosConfig_dbprefix; + $prod = Array( + 'vendor_id'=>0 + ); + + $result=mysql_query("select vendor_id, vendor_currency from ".$mosConfig_dbprefix."vm_vendor;"); + if ($result && $row=mysql_fetch_row($result)) { + $prod['vendor_id']=$row[0]; + $prod['vendor_currency']=$row[1]; + } + $result=mysql_query("select shopper_group_id from ".$mosConfig_dbprefix."vm_shopper_group where vendor_id=".$vendor_id." and shopper_group_name='-default-';"); + if ($result && $row=mysql_fetch_row($result)) + $prod['shopper_group']=$row[0]; + if ( $tiny_product['esale_joomla_id']) { + $result = mysql_query("select count(*) from ".$mosConfig_dbprefix."vm_product where product_id=". $tiny_product['esale_joomla_id']); + $row = mysql_fetch_row($result); + if (! $row[0] ) + $tiny_product['esale_joomla_id'] = 0; + } + + if (! $tiny_product['esale_joomla_id']) { + mysql_query("insert into ".$mosConfig_dbprefix."vm_product () values ()"); + $osc_id=mysql_insert_id(); + mysql_query("insert into ".$mosConfig_dbprefix."vm_product_price (product_id, product_price, product_currency, product_price_vdate, product_price_edate, shopper_group_id) values (".$osc_id.", ".$tiny_product['price'].", '".$vendor_currency."', 0, 0, ".$shopper_group.");"); + mysql_query("insert into ".$mosConfig_dbprefix."vm_product_category_xref (product_id, category_id) values (".$osc_id.", ".$tiny_product['category_id'].");"); + } else { + $osc_id=$tiny_product['esale_joomla_id']; + } + + mysql_query("update ".$mosConfig_dbprefix."vm_product set ". + "product_in_stock=".$tiny_product['quantity'].",". + "product_weight=".$tiny_product['weight'].",". + "product_tax_id=".$tiny_product['tax_class_id'].",". + "product_sku='".mysql_escape_string($tiny_product['model'])."',". + "product_name='".mysql_escape_string($tiny_product['name'])."',". + "vendor_id='".$prod['vendor_id']."',". + "product_desc='".mysql_escape_string($tiny_product['description'])."', ". + "product_publish='Y',". + "product_s_desc='".mysql_escape_string(substr($tiny_product['description'],0,200))."' ". + "where product_id=".$osc_id.";"); + + // Replace or + // Delete old values + + mysql_query("update ".$mosConfig_dbprefix."vm_product_price set product_price='".$tiny_product['price']."' where product_id=".$osc_id.";"); + mysql_query("update ".$mosConfig_dbprefix."vm_product_category set category_id='".$tiny_product['category_id']."' where product_id=".$osc_id.";"); + + if ($tiny_product['haspic']==1) { + $filename=tempnam('components/com_virtuemart/shop_image/product/', 'tiny_'); + $extension=strrchr($tiny_product['fname'],'.'); + $filename.=$extension; + //file_put_contents($filename, base64_decode($tiny_product['picture'])); + $hd=fopen($filename, "w"); + fwrite($hd, base64_decode($tiny_product['picture'])); + fclose($hd); + $short=strrchr($filename,'/'); + $short=substr($short, 1, strlen($short)); + mysql_query("update ".$mosConfig_dbprefix."vm_product set product_full_image='".$short."' where product_id=".$osc_id.";"); + $newxsize = PSHOP_IMG_WIDTH; + if (!$newxsize) { + $newxsize=90; + } + $newysize = PSHOP_IMG_HEIGHT; + if (!$newysize) { + $newysize=60; + } + $extension=strtolower($extension); + if (in_array($extension, array('.jpeg', '.jpe', '.jpg', '.gif', '.png'))) { + if (in_array($extension, array('.jpeg', '.jpe', '.jpg'))) { + $extension='.jpeg'; + } + $thumb=tempnam('components/com_virtuemart/shop_image/product/', 'tiny_').$extension; + $load='imagecreatefrom'.substr($extension,1,strlen($extension)-1); + $save='image'.substr($extension,1,strlen($extension)-1); + $tmp_img=$load($filename); + $imgsize = getimagesize($filename); + if ($imgsize[0] > $newxsize || $imgsize[1] > $newysize) { + if ($imgsize[0]*$newysize > $imgsize[1]*$newxsize) { + $ratio=$imgsize[0]/$newxsize; + } else { + $ratio=$imgsize[1]/$newysize; + } + } else { + $ratio=1; + } + $tn=imagecreatetruecolor (floor($imgsize[0]/$ratio),floor($imgsize[1]/$ratio)); + imagecopyresized($tn,$tmp_img,0,0,0,0,floor($imgsize[0]/$ratio),floor($imgsize[1]/$ratio),$imgsize[0],$imgsize[1]); + $short=strrchr($thumb,'/'); + $short=substr($short,1,strlen($short)); + $save($tn, $thumb); + mysql_query("update ".$mosConfig_dbprefix."vm_product set product_thumb_image='".$short."' where product_id=".$osc_id.";"); + } + } + return new xmlrpcresp(new xmlrpcval($osc_id, "int")); + } + + function get_saleorders($last_so) { + global $mosConfig_dbprefix; + $saleorders=array(); + + $result=mysql_query( + "SELECT + o.`order_id`, c.`last_name`, c.`address_1`, c.`city`, c.`zip`, c.`state`, + c.`country`, c.`phone_1`, c.`user_email`, d.`last_name` , d.`address_1` , + d.`city`, d.`zip`, d.`state`, d.`country`, o.`cdate`, + c.title, c.first_name, d.title, d.first_name, + d.user_id, c.user_id, o.customer_note + FROM ". + $mosConfig_dbprefix."vm_orders as o,". + $mosConfig_dbprefix."vm_user_info as c, ". + $mosConfig_dbprefix."vm_user_info as d + where + o.order_id>".$last_so." and + o.user_id=c.user_id and + (c.address_type_name is NULL or c.address_type_name='-default-') and + o.user_info_id=d.user_info_id; + "); + + if ($result) while ($row=mysql_fetch_row($result)) { + $orderlines=array(); + $resultb=mysql_query("select product_id, product_quantity, product_item_price from ".$mosConfig_dbprefix."vm_order_item where order_id=".$row[0].";"); + if ($resultb) while ($rowb=mysql_fetch_row($resultb)) { + $orderlines[]=new xmlrpcval( array( + "product_id" => new xmlrpcval($rowb[0], "int"), + "product_qty" => new xmlrpcval($rowb[1], "int"), + "price" => new xmlrpcval($rowb[2], "int") + ), "struct"); + } + $saleorders[] = new xmlrpcval( array( + "id" => new xmlrpcval( $row[0], "int"), + "note" => new xmlrpcval( $row[22], "string"), + "lines" => new xmlrpcval( $orderlines, "array"), + "address" => new xmlrpcval( array( + "name" => new xmlrpcval($row[16]." ".$row[1]." ".$row[17], "string"), + "address" => new xmlrpcval($row[2], "string"), + "city" => new xmlrpcval($row[3], "string"), + "zip" => new xmlrpcval($row[4], "string"), + "state" => new xmlrpcval($row[5], "string"), + "country" => new xmlrpcval($row[6], "string"), + "phone" => new xmlrpcval($row[7], "string"), + "email" => new xmlrpcval($row[8], "string"), + "esale_id" => new xmlrpcval($row[20], "string") + ), "struct"), + "delivery" => new xmlrpcval( array( + "name" => new xmlrpcval($row[18]." ".$row[9]." ".$row[19], "string"), + "address" => new xmlrpcval($row[10], "string"), + "city" => new xmlrpcval($row[11], "string"), + "zip" => new xmlrpcval($row[12], "string"), + "state" => new xmlrpcval($row[13], "string"), + "country" => new xmlrpcval($row[14], "string"), + "email" => new xmlrpcval($row[8], "string"), + "esale_id" => new xmlrpcval($row[21], "string") + ), "struct"), + "billing" =>new xmlrpcval( array( + "name" => new xmlrpcval($row[16]." ".$row[1]." ".$row[17], "string"), + "address" => new xmlrpcval($row[2], "string"), + "city" => new xmlrpcval($row[3], "string"), + "zip" => new xmlrpcval($row[4], "string"), + "state" => new xmlrpcval($row[5], "string"), + "country" => new xmlrpcval($row[6], "string"), + "email" => new xmlrpcval($row[8], "string"), + "esale_id" => new xmlrpcval($row[20], "string") + ), "struct"), + "date" => new xmlrpcval( date('YmdHis',$row[15]), "date") + ), "struct"); + } + return new xmlrpcresp(new xmlrpcval($saleorders, "array")); + } + + function process_order($order_id) { + global $mosConfig_dbprefix; + mysql_query("update ".$mosConfig_dbprefix."vm_orders set order_status='C' where order_id=".$order_id.";"); + mysql_query("update ".$mosConfig_dbprefix."vm_order_item set oerder_status='C' where order_id=".$order_id.";"); + return new xmlrpcresp(new xmlrpcval(0, "int")); + } + + function close_order($order_id) { + global $mosConfig_dbprefix; + mysql_query("update ".$mosConfig_dbprefix."vm_orders set order_status='S' where order_id=".$order_id.";"); + mysql_query("update ".$mosConfig_dbprefix."vm_order_item set oerder_status='S' where order_id=".$order_id.";"); + return new xmlrpcresp(new xmlrpcval(0, "int")); + } + + $server = new xmlrpc_server( array( + "get_taxes" => array( + "function" => "get_taxes", + "signature" => array(array($xmlrpcArray)) + ), + "get_languages" => array( + "function" => "get_languages", + "signature" => array(array($xmlrpcArray)) + ), + "get_categories" => array( + "function" => "get_categories", + "signature" => array(array($xmlrpcArray)) + ), + "get_saleorders" => array( + "function" => "get_saleorders", + "signature" => array(array($xmlrpcArray, $xmlrpcInt)) + ), + "set_product_category" => array( + "function" => "set_product_category", + "signature" => array(array($xmlrpcInt, $xmlrpcInt, $xmlrpcArray)) + ), + "unpublish_product" => array( + "function" => "unpublish_product", + "signature" => array(array($xmlrpcInt, $xmlrpcArray)) + ), + "set_product" => array( + "function" => "set_product", + "signature" => array(array($xmlrpcInt, $xmlrpcStruct)) + ), + "set_product_stock" => array( + "function" => "set_product_stock", + "signature" => array(array($xmlrpcInt, $xmlrpcStruct)) + ), + "process_order" => array( + "function" => "process_order", + "signature" => array(array($xmlrpcInt, $xmlrpcInt)) + ), + "close_order" => array( + "function" => "close_order", + "signature" => array(array($xmlrpcInt, $xmlrpcInt)) + ) + ), false); + $server->functions_parameters_type= 'phpvals'; + $server->service(); +?> diff --git a/addons/esale_joomla/esale_joomla.py b/addons/esale_joomla/esale_joomla.py index e24755bf590..a4bf9134538 100644 --- a/addons/esale_joomla/esale_joomla.py +++ b/addons/esale_joomla/esale_joomla.py @@ -39,15 +39,17 @@ from mx import DateTime class esale_joomla_web(osv.osv): _name = "esale_joomla.web" _description = "eCommerce Website" + _columns = { 'name': fields.char('Name',size=64, required=True), 'url': fields.char('URL', size=64, required=True), 'shop_id': fields.many2one('sale.shop', 'Sale Shop', required=True), 'active': fields.boolean('Active'), 'product_ids': fields.one2many('esale_joomla.product', 'web_id', string='Products'), - 'language_ids': fields.one2many('esale_joomla.lang', 'web_id', string='Languages'), 'tax_ids': fields.one2many('esale_joomla.tax', 'web_id', string='Taxes'), + 'taxes_included_ids': fields.many2many('account.tax', 'esale_joomla_web_taxes_included_rel', 'esale_joomla_web_id', 'tax_id', 'Taxes included', domain=[('parent_id', '=', False)]), 'category_ids': fields.one2many('esale_joomla.category', 'web_id', string='Categories'), + 'language_id' : fields.many2one('res.lang', 'Language'), } _defaults = { 'active': lambda *a: 1 @@ -112,10 +114,10 @@ class esale_joomla_category(osv.osv): _name = "esale_joomla.category" _description = "eSale Category" _columns = { - 'name': fields.char('Name', size=64, reuired=True), - 'esale_joomla_id': fields.integer('Web ID', required=True), + 'name': fields.char('Name', size=64, required=True), + 'esale_joomla_id': fields.integer('Web ID', readonly=True, required=True), 'web_id': fields.many2one('esale_joomla.web', 'Website'), - 'category_id': fields.many2one('product.category', 'Category'), + 'category_id': fields.many2one('product.category', 'Category', required=True), 'include_childs': fields.boolean('Include Childs', help="If checked, Tiny ERP will also export products from categories that are childs of this one."), } esale_joomla_category() @@ -124,7 +126,7 @@ class esale_joomla_product(osv.osv): _name = "esale_joomla.product" _description = "eSale Product" _columns = { - 'web_id' : fields.many2one('esale_joomla.web', 'Web Ref'), + 'web_id' : fields.many2one('esale_joomla.web', 'Web Ref', relate=True), 'name' : fields.char('Name', size=64, required=True), 'product_id' : fields.many2one('product.product', 'Product', required=True), 'esale_joomla_id' : fields.integer('eSale product id'), diff --git a/addons/esale_joomla/esale_joomla_view.xml b/addons/esale_joomla/esale_joomla_view.xml index b11dbbc48a3..cec7aef7d79 100644 --- a/addons/esale_joomla/esale_joomla_view.xml +++ b/addons/esale_joomla/esale_joomla_view.xml @@ -10,15 +10,17 @@ - + +