ESALE_JOOMLA : new version (for languages and multi-categories)
bzr revid: bch-2621ed2d19bc4426ca4ac69ef5a9bc7f4120eb6d
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
|
||||
define( '_VALID_MOS', 1);
|
||||
|
||||
include("xmlrpc.inc");
|
||||
include("xmlrpcs.inc");
|
||||
|
||||
require_once( 'configuration.php' );
|
||||
require_once( 'includes/joomla.php' );
|
||||
require_once( 'administrator/components/com_virtuemart/virtuemart.cfg.php' );
|
||||
|
||||
$con = mysql_pconnect($mosConfig_host, $mosConfig_user,$mosConfig_password );
|
||||
mysql_select_db($mosConfig_db);
|
||||
|
||||
function get_taxes() {
|
||||
global $mosConfig_dbprefix;
|
||||
$taxes=array();
|
||||
|
||||
$result=mysql_query("select tax_rate_id, tax_rate*100 from ".$mosConfig_dbprefix."vm_tax_rate;");
|
||||
if ($result) while ($row=mysql_fetch_row($result)) {
|
||||
$taxes[]=new xmlrpcval(array(new xmlrpcval($row[0], "int"), new xmlrpcval("Tax ".$row[1]."%", "string")), "array");
|
||||
}
|
||||
return new xmlrpcresp( new xmlrpcval($taxes, "array"));
|
||||
}
|
||||
|
||||
function get_languages() {
|
||||
$languages=array();
|
||||
|
||||
$languages[]=new xmlrpcval(array(new xmlrpcval(1, "int"), new xmlrpcval("Unique", "string")), "array");
|
||||
return new xmlrpcresp( new xmlrpcval($languages, "array"));
|
||||
}
|
||||
|
||||
function get_categories() {
|
||||
global $mosConfig_dbprefix;
|
||||
$categories=array();
|
||||
|
||||
$result=mysql_query("select category_id, category_name from ".$mosConfig_dbprefix."vm_category;");
|
||||
if ($result) while ($row=mysql_fetch_row($result)) {
|
||||
$categories[]=new xmlrpcval(array(new xmlrpcval($row[0], "int"), new xmlrpcval(parent_category($row[0],$row[1]), "string")), "array");
|
||||
}
|
||||
return new xmlrpcresp( new xmlrpcval($categories, "array"));
|
||||
}
|
||||
|
||||
function parent_category($id, $name) {
|
||||
global $mosConfig_dbprefix;
|
||||
$result=mysql_query("select category_parent_id from ".$mosConfig_dbprefix."vm_category_xref where category_child_id=".$id.";");
|
||||
if ($result && $row=mysql_fetch_row($result)) {
|
||||
if ($row[0]==0) {
|
||||
return $name;
|
||||
} else {
|
||||
$resultb=mysql_query("select category_name from ".$mosConfig_dbprefix."vm_category where category_id=".$row[0].";");
|
||||
if ($resultb && $rowb=mysql_fetch_row($resultb)) {
|
||||
$name=parent_category($row[0], $rowb[0] . " \\ ". $name);
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
function set_product_stock($tiny_product) {
|
||||
global $mosConfig_dbprefix;
|
||||
mysql_query("update ".$mosConfig_dbprefix."vm_product set product_in_stock=".$tiny_product['quantity']." where
|
||||
product_id=".$tiny_product['esale_joomla_id'].";");
|
||||
//mysql_query("update products set products_status=".(($tiny_product['quantity']>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();
|
||||
?>
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -10,15 +10,17 @@
|
||||
<notebook>
|
||||
<page string="General Informations">
|
||||
<separator string="Web Shop Info" colspan="4"/>
|
||||
<field name="name" select="1" colspan="4"/>
|
||||
<field name="name" select="1" colspan="3"/>
|
||||
<field name="url" widget="url" required="1"/>
|
||||
<field name="active" select="1"/>
|
||||
<field name="shop_id" select="1" required="1"/>
|
||||
<field name="language_id" select="1" required="1"/>
|
||||
<separator string="Configuration Instructions" colspan="4"/>
|
||||
<label string="After having completed the above data, proceed to the taxes, languages and categories mapping. Go to the next tabs, import data form the website and complete the third column." align="0.0" colspan="4"/>
|
||||
</page>
|
||||
<page string="Taxes Mapping">
|
||||
<button type="object" string="Initial Import of Taxes" colspan="4" name="tax_import"/>
|
||||
<separator string="Taxes" colspan="4"/>
|
||||
<field colspan="4" name="tax_ids" nolabel="1">
|
||||
<tree editable="bottom">
|
||||
<field name="name"/>
|
||||
@@ -26,16 +28,8 @@
|
||||
<field name="tax_id"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
<page string="Languages Mapping">
|
||||
<button type="object" string="Initial Import of Languages" colspan="4" name="lang_import"/>
|
||||
<field colspan="4" name="language_ids" nolabel="1">
|
||||
<tree editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="esale_joomla_id" readonly="1"/>
|
||||
<field name="language_id"/>
|
||||
</tree>
|
||||
</field>
|
||||
<separator string="Taxes included" colspan="4"/>
|
||||
<field colspan="4" name="taxes_included_ids" nolabel="1"/>
|
||||
</page>
|
||||
<page string="Categories Mapping">
|
||||
<button type="object" string="Synchronise products categories" colspan="4" name="category_import"/>
|
||||
@@ -48,20 +42,13 @@
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
<page string="Active Products">
|
||||
<field name="product_ids" colspan="4" nolabel="1">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="esale_joomla_id"/>
|
||||
<field name="product_id"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="action_esale_joomla_form">
|
||||
<field name="name">esale_joomla.web</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">esale_joomla.web</field>
|
||||
<field name="view_type">form</field>
|
||||
@@ -69,6 +56,42 @@
|
||||
</record>
|
||||
<menuitem name="Sales Management/eSale/Definition/Web Shop" id="menu_action_esale_joomla_web" action="action_esale_joomla_form" groups="admin"/>
|
||||
|
||||
<record model="ir.ui.view" id="view_esale_joomla_product_form">
|
||||
<field name="name">esale_joomla.product.form</field>
|
||||
<field name="model">esale_joomla.product</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="eSale product">
|
||||
<field name="name" select="1"/>
|
||||
<field name="esale_joomla_id" select="1"/>
|
||||
<field name="product_id" select="1"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_esale_joomla_product_tree">
|
||||
<field name="name">esale_joomla.product.tree</field>
|
||||
<field name="model">esale_joomla.product</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="eSale product">
|
||||
<field name="name" select="1"/>
|
||||
<field name="esale_joomla_id" select="1"/>
|
||||
<field name="product_id" select="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="action_esale_joomla_product_form">
|
||||
<field name="name">esale_joomla.product</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">esale_joomla.product</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_esale_joomla_product_tree"/>
|
||||
</record>
|
||||
<menuitem name="Sales Management/eSale/Definition/Web Product" id="menu_action_esale_joomla_product" action="action_esale_joomla_product_form" groups="admin"/>
|
||||
|
||||
<record model="ir.ui.view" id="view_order_tree">
|
||||
<field name="name">esale_joomla.order.tree</field>
|
||||
<field name="model">esale_joomla.order</field>
|
||||
@@ -109,14 +132,15 @@
|
||||
<button type="object" name="order_cancel" states="draft" string="Cancel Order"/>
|
||||
</page>
|
||||
<page string="Others data">
|
||||
<field name="order_id" colspan="4"/>
|
||||
<field name="note" colspan="4"/>
|
||||
<field name="order_id" colspan="3"/>
|
||||
<field name="note" colspan="3"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.actions.act_window" id="action_order_form">
|
||||
<field name="name">esale_joomla.order</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">esale_joomla.order</field>
|
||||
<field name="view_type">form</field>
|
||||
@@ -125,7 +149,7 @@
|
||||
<menuitem name="Sales Management/eSale/eSale Orders" id="menu_action_order_form" action="action_order_form" groups="admin"/>
|
||||
|
||||
<record model="ir.actions.act_window" id="action_order_tree">
|
||||
<field name="name">Draft eSale Orders</field>
|
||||
<field name="name">esale_joomla.order</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">esale_joomla.order</field>
|
||||
<field name="view_type">form</field>
|
||||
@@ -141,8 +165,8 @@
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="eSales Order Line">
|
||||
<field name="name" colspan="4"/>
|
||||
<field name="product_id" colspan="4"/>
|
||||
<field name="name" colspan="3"/>
|
||||
<field name="product_id" colspan="3"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom_id"/>
|
||||
<field name="price_unit"/>
|
||||
|
||||
@@ -57,30 +57,35 @@ def _do_import(self, cr, uid, data, context):
|
||||
})
|
||||
|
||||
for orderline in so['lines']:
|
||||
print orderline, website.id
|
||||
ids=self.pool.get('esale_joomla.product').search(cr, uid, [('esale_joomla_id', '=', orderline['product_id']), ('web_id', '=', website.id)])
|
||||
|
||||
print 'Products', ids
|
||||
if len(ids):
|
||||
if ids:
|
||||
osc_product_id=ids[0]
|
||||
osc_product=self.pool.get('esale_joomla.product').browse(cr, uid, osc_product_id)
|
||||
price=orderline['price']
|
||||
taxes_included=[]
|
||||
for taxe in osc_product.product_id.taxes_id:
|
||||
for t in website.taxes_included_ids:
|
||||
if t.id == taxe.id:
|
||||
taxes_included.append(taxe)
|
||||
for c in self.pool.get('account.tax').compute_inv(cr, uid, taxes_included, price, 1, product=osc_product.product_id):
|
||||
price-=c['amount']
|
||||
|
||||
a = {
|
||||
'product_id': osc_product.product_id.id,
|
||||
'product_qty': orderline['product_qty'],
|
||||
'name': osc_product.name,
|
||||
'order_id': order_id,
|
||||
'product_uom_id': osc_product.product_id.uom_id.id,
|
||||
'price_unit': orderline['price'],
|
||||
'price_unit': price,
|
||||
}
|
||||
print '-'*50
|
||||
print a
|
||||
self.pool.get('esale_joomla.order.line').create(cr, uid, {
|
||||
'product_id': osc_product.product_id.id,
|
||||
'product_qty': orderline['product_qty'],
|
||||
'name': osc_product.name,
|
||||
'order_id': order_id,
|
||||
'product_uom_id': osc_product.product_id.uom_id.id,
|
||||
'price_unit': orderline['price'],
|
||||
'price_unit': price,
|
||||
})
|
||||
cr.commit()
|
||||
return {'num':total}
|
||||
|
||||
@@ -32,6 +32,8 @@ import netsvc
|
||||
import xmlrpclib
|
||||
import netsvc
|
||||
import pooler
|
||||
import urllib
|
||||
import base64
|
||||
|
||||
import wizard
|
||||
from osv import osv
|
||||
@@ -49,93 +51,121 @@ _export_done_fields = {
|
||||
'prod_update': {'string':'Updated products', 'type':'float', 'readonly': True},
|
||||
}
|
||||
|
||||
def _product_id_to_joomla_id(cr,uid,pool,product,website):
|
||||
esale_joomla_id2 = pool.get('esale_joomla.product').search(cr, uid, [('web_id','=',website.id),('product_id','=',product.id)])
|
||||
esale_joomla_id = 0
|
||||
if esale_joomla_id2:
|
||||
esale_joomla_id = pool.get('esale_joomla.product').read(cr, uid, [esale_joomla_id2[0]],["esale_joomla_id"])[0]["esale_joomla_id"]
|
||||
return esale_joomla_id
|
||||
|
||||
def _do_export(self, cr, uid, data, context):
|
||||
self.pool = pooler.get_pool(cr.dbname)
|
||||
ids = self.pool.get('esale_joomla.web').search(cr, uid, [])
|
||||
for website in self.pool.get('esale_joomla.web').browse(cr, uid, ids):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
ids = pool.get('esale_joomla.web').search(cr, uid, [])
|
||||
prod_new = 0
|
||||
prod_update = 0
|
||||
for website in pool.get('esale_joomla.web').browse(cr, uid, ids):
|
||||
|
||||
pricelist = website.shop_id.pricelist_id.id
|
||||
if not pricelist:
|
||||
raise wizard.except_wizard('UserError', 'You must define a pricelist in your shop !')
|
||||
server = xmlrpclib.ServerProxy("%s/tinyerp-synchro.php" % website.url)
|
||||
print 'SERVER', "%s/tinyerp-synchro.php" % website.url
|
||||
|
||||
prod_new = 0
|
||||
prod_update = 0
|
||||
context['lang']=website.language_id.code
|
||||
categ_processed = []
|
||||
|
||||
## delete book if necessary :
|
||||
cr.execute("select jp.id, esale_joomla_id from esale_joomla_product jp inner join product_template pt on pt.id = jp.product_id where pt.categ_id not in (select category_id from esale_joomla_category) ")
|
||||
esale_ids= []
|
||||
joomla_ids= []
|
||||
for res in cr.fetchall():
|
||||
esale_ids.append(res[0])
|
||||
joomla_ids.append(res[1])
|
||||
if joomla_ids : server.unpublish_product(joomla_ids)
|
||||
pool.get('esale_joomla.product').unlink(cr,uid,esale_ids)
|
||||
|
||||
for categ in website.category_ids:
|
||||
if not categ.category_id:
|
||||
print 'Skipping Category', categ.name, categ.id
|
||||
if not categ.category_id: continue
|
||||
## for product already uploaded via another category we
|
||||
## just update the current category :
|
||||
if categ.category_id.id in categ_processed :
|
||||
prod_ids = pool.get('product.product').search(cr, uid, [('categ_id','in',cat_ids)])
|
||||
product_ids = []
|
||||
for product in pool.get('product.product').browse(cr, uid, prod_ids, context=context):
|
||||
product_ids.append( _product_id_to_joomla_id(cr,uid,pool,product,website))
|
||||
server.set_product_category(categ.esale_joomla_id ,product_ids)
|
||||
continue
|
||||
|
||||
cat_ids = [categ.category_id.id]
|
||||
if categ.include_childs:
|
||||
pass
|
||||
#
|
||||
# Use cat_ids and compute for childs
|
||||
#
|
||||
prod_ids = self.pool.get('product.product').search(cr, uid, [('categ_id','=',categ.category_id.id)])
|
||||
for product in self.pool.get('product.product').browse(cr, uid, prod_ids):
|
||||
def _add_child(cat_ids, categ):
|
||||
for child in categ.child_id:
|
||||
if child.id not in cat_ids:
|
||||
cat_ids.append(child.id)
|
||||
_add_child(cat_ids, child)
|
||||
_add_child(cat_ids, categ.category_id)
|
||||
categ_processed.extend(cat_ids)
|
||||
|
||||
category_id=categ.id
|
||||
prod_ids = pool.get('product.product').search(cr, uid, [('categ_id','in',cat_ids)])
|
||||
for product in pool.get('product.product').browse(cr, uid, prod_ids, context=context):
|
||||
|
||||
esale_joomla_id= _product_id_to_joomla_id(cr,uid,pool,product,website)
|
||||
|
||||
esale_joomla_id2 = self.pool.get('esale_joomla.product').search(cr, uid, [('web_id','=',website.id),('product_id','=',product.id)])
|
||||
esale_joomla_id = 0
|
||||
if esale_joomla_id2:
|
||||
esale_joomla_id = self.pool.get('esale_joomla.product').browse(cr, uid, esale_joomla_id2[0]).esale_joomla_id
|
||||
price = pool.get('product.pricelist').price_get(cr, uid, [pricelist], product.id, 1, 'list')[pricelist]
|
||||
|
||||
taxes_included=[]
|
||||
taxes_name=[]
|
||||
for taxe in product.taxes_id:
|
||||
for t in website.taxes_included_ids:
|
||||
if t.id == taxe.id:
|
||||
taxes_included.append(taxe)
|
||||
for c in pool.get('account.tax').compute(cr, uid, taxes_included, price, 1): # DELETED product = product
|
||||
price+=c['amount']
|
||||
taxes_name.append(c['name'])
|
||||
|
||||
tax_class_id = 1
|
||||
print [pricelist], product.id, 1, 'list'
|
||||
webproduct={
|
||||
'esale_joomla_id' : esale_joomla_id or 0,
|
||||
'quantity' : self.pool.get('product.product')._product_virtual_available(cr, uid, [product.id], '', False, {'shop':website.shop_id.id})[product.id],
|
||||
'model' : product.code or '',
|
||||
'price' : 10.0, #self.pool.get('product.pricelist').price_get(cr, uid, [pricelist], product.id, 1, 'list')[pricelist],
|
||||
'weight' : float(product.weight),
|
||||
'tax_class_id' : tax_class_id,
|
||||
'category_id' : category_id,
|
||||
'esale_joomla_id': esale_joomla_id,
|
||||
'quantity': pool.get('product.product')._product_virtual_available(cr, uid, [product.id], '', False, {'shop':website.shop_id.id})[product.id],
|
||||
'model': product.code or '',
|
||||
'price': price,
|
||||
'weight': float(0.0),
|
||||
'length': float(0.0),
|
||||
'width': float(0.0),
|
||||
'height': float(0.0),
|
||||
'tax_class_id': tax_class_id,
|
||||
'category_id': categ.esale_joomla_id,
|
||||
}
|
||||
|
||||
attach_ids = self.pool.get('ir.attachment').search(cr, uid, [('res_model','=','product.product'), ('res_id', '=',product.id)])
|
||||
data = self.pool.get('ir.attachment').read(cr, uid, attach_ids)
|
||||
|
||||
attach_ids = pool.get('ir.attachment').search(cr, uid, [('res_model','=','product.product'), ('res_id', '=',product.id)])
|
||||
data = pool.get('ir.attachment').read(cr, uid, attach_ids)
|
||||
if len(data):
|
||||
webproduct['haspic'] = 1
|
||||
webproduct['picture'] = data[0]['datas']
|
||||
if not data[0]['link']:
|
||||
webproduct['picture'] = data[0]['datas']
|
||||
else:
|
||||
try:
|
||||
webproduct['picture'] = base64.encodestring(urllib.urlopen(data[0]['link']).read())
|
||||
except:
|
||||
webproduct['haspic'] = 0
|
||||
webproduct['fname'] = data[0]['datas_fname']
|
||||
else:
|
||||
webproduct['haspic'] =0
|
||||
|
||||
langs={}
|
||||
products_pool=pooler.get_pool(cr.dbname).get('product.product')
|
||||
for lang in website.language_ids:
|
||||
if lang.language_id and lang.language_id.translatable:
|
||||
langs[str(lang.esale_joomla_id)] = {
|
||||
'name': products_pool.read(cr, uid, [osc_product.product_id.id], ['name'], {'lang': lang.language_id.code})[0]['name'] or '',
|
||||
'description': products_pool.read(cr, uid, [osc_product.product_id.id], ['description_sale'], {'lang': lang.language_id.code})[0]['description_sale'] or ''
|
||||
}
|
||||
|
||||
webproduct['langs'] = langs
|
||||
webproduct['name'] = str(product.name or '')
|
||||
webproduct['description'] = str(product.description_sale or '')
|
||||
|
||||
print webproduct
|
||||
webproduct['description'] = str((product.description_sale or '') + (len(taxes_name) and ("\n(" + (', '.join(taxes_name)) + ')') or ''))
|
||||
webproduct['short_description'] = str(product.description_sale or '')
|
||||
|
||||
osc_id=server.set_product(webproduct)
|
||||
|
||||
print osc_id
|
||||
if osc_id!=webproduct['esale_joomla_id']:
|
||||
if esale_joomla_id2:
|
||||
self.pool.get('esale_joomla.product').write(cr, uid, [esale_joomla_id2[0]], {'esale_joomla_id': osc_id})
|
||||
print 'Changing', webproduct['esale_joomla_id'], 'to', osc_id
|
||||
if osc_id!=esale_joomla_id:
|
||||
if esale_joomla_id:
|
||||
pool.get('esale_joomla.product').write(cr, uid, [esale_joomla_id], {'esale_joomla_id': osc_id})
|
||||
prod_update += 1
|
||||
else:
|
||||
self.pool.get('esale_joomla.product').create(cr, uid, {
|
||||
'product_id': product.id,
|
||||
'web_id': website.id,
|
||||
'esale_joomla_id': osc_id,
|
||||
'name': product.name
|
||||
})
|
||||
pool.get('esale_joomla.product').create(cr, uid, {'product_id': product.id, 'web_id': website.id, 'esale_joomla_id': osc_id, 'name': product.name })
|
||||
prod_new += 1
|
||||
else:
|
||||
prod_update += 1
|
||||
prod_update += 1
|
||||
return {'prod_new':prod_new, 'prod_update':prod_update}
|
||||
|
||||
class wiz_esale_joomla_products(wizard.interface):
|
||||
@@ -146,3 +176,4 @@ class wiz_esale_joomla_products(wizard.interface):
|
||||
}
|
||||
}
|
||||
wiz_esale_joomla_products('esale_joomla.products');
|
||||
|
||||
|
||||
@@ -1,3 +1,31 @@
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsability of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# garantees and support are strongly adviced to contract a Free Software
|
||||
# Service Company
|
||||
#
|
||||
# This program is Free Software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
import ir
|
||||
import time
|
||||
import os
|
||||
@@ -28,7 +56,6 @@ def _do_export(self, cr, uid, data, context):
|
||||
server = xmlrpclib.ServerProxy("%s/tinyerp-synchro.php" % website.url)
|
||||
for osc_product in website.product_ids:
|
||||
if osc_product.esale_joomla_id:
|
||||
print "sending product %s" % osc_product.name
|
||||
webproduct={
|
||||
'esale_joomla_id': osc_product.esale_joomla_id,
|
||||
'quantity': pooler.get_pool(cr.dbname).get('product.product')._product_virtual_available(cr, uid, [osc_product.product_id.id], '', False, {'shop':website.shop_id.id})[osc_product.product_id.id],
|
||||
@@ -38,21 +65,12 @@ def _do_export(self, cr, uid, data, context):
|
||||
|
||||
class wiz_esale_joomla_stocks(wizard.interface):
|
||||
|
||||
states = { #'init' : { 'actions' : [],
|
||||
# 'result' : { 'type' : 'form',
|
||||
# 'arch' : _import_form,
|
||||
# 'fields' : _import_fields,
|
||||
# 'state' : [('import', 'Import languages and taxes'), ('end', 'Cancel')]
|
||||
# },
|
||||
# },
|
||||
'init' : { 'actions' : [_do_export],
|
||||
'result' : { 'type' : 'form',
|
||||
'arch' : _export_done_form,
|
||||
'fields' : _export_done_fields,
|
||||
'state' : [('end', 'End')]
|
||||
}
|
||||
}
|
||||
}
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [_do_export],
|
||||
'result': { 'type': 'form', 'arch': _export_done_form, 'fields': _export_done_fields, 'state': [('end', 'End')]}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wiz_esale_joomla_stocks('esale_joomla.stocks');
|
||||
|
||||
Reference in New Issue
Block a user