<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ca">
	<id>http://wiki.joanillo.org/index.php?action=history&amp;feed=atom&amp;title=C%C3%A0rrega_massiva_de_dades_II</id>
	<title>Càrrega massiva de dades II - Historial de revisió</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.joanillo.org/index.php?action=history&amp;feed=atom&amp;title=C%C3%A0rrega_massiva_de_dades_II"/>
	<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=C%C3%A0rrega_massiva_de_dades_II&amp;action=history"/>
	<updated>2026-04-20T13:27:35Z</updated>
	<subtitle>Historial de revisió per a aquesta pàgina del wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>http://wiki.joanillo.org/index.php?title=C%C3%A0rrega_massiva_de_dades_II&amp;diff=980&amp;oldid=prev</id>
		<title>Joan: /* Inserció manual en la taula i_product */</title>
		<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=C%C3%A0rrega_massiva_de_dades_II&amp;diff=980&amp;oldid=prev"/>
		<updated>2008-12-01T19:06:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Inserció manual en la taula i_product&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pàgina nova&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Amb el mètode explicat a la wiki hem de crear els formats d'importació adequats i, a través d'un fitxer CSV, populem la taula i_product (o la que sigui). Després ja importem les dades i populem m_product.&lt;br /&gt;
&lt;br /&gt;
Ara bé, si es coneix l'estructura de i_product, podem fer insercions directes en aquesta taula, i el resultat és el mateix. L'esforç que fem per genera el fitxer CSV el podem fer per generar un script SQL amb tots els inserts.&lt;br /&gt;
&lt;br /&gt;
El primer que farem és inserir directament les categories de productes, i més quan el mètode oficial no ens serveix per inserir les categories de productes i serveis (no es pot inserir qualsevol cosa amb els formats d'importació).&lt;br /&gt;
&lt;br /&gt;
Les taules involucrades són:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
i_product&lt;br /&gt;
m_product&lt;br /&gt;
m_product_category&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Inserció manual de les categories de serveis==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openbravo=# select * from m_product_category;&lt;br /&gt;
&lt;br /&gt;
openbravo=# \d m_product_category&lt;br /&gt;
 m_product_category_id | numeric(10,0)               | not null&lt;br /&gt;
 ad_client_id          | numeric(10,0)               | not null&lt;br /&gt;
 ad_org_id             | numeric(10,0)               | not null&lt;br /&gt;
 isactive              | character(1)                | not null default 'Y'::bpchar&lt;br /&gt;
 created               | timestamp without time zone | not null default now()&lt;br /&gt;
 createdby             | numeric(10,0)               | not null&lt;br /&gt;
 updated               | timestamp without time zone | not null default now()&lt;br /&gt;
 updatedby             | numeric(10,0)               | not null&lt;br /&gt;
 value                 | character varying(40)       | not null&lt;br /&gt;
 name                  | character varying(60)       | not null&lt;br /&gt;
 description           | character varying(255)      | &lt;br /&gt;
 isdefault             | character(1)                | not null default 'N'::bpchar&lt;br /&gt;
 plannedmargin         | numeric                     | not null&lt;br /&gt;
 a_asset_group_id      | numeric(10,0)               | &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Veient quina és l'estructura de m_product_category (sobretot mirant quins són els camps obligatoris que no tenen valor per defecte), i a partir de les dades de què disposo, puc construir un script SQL:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000001, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'DOM-0','Dominis','Dominis','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000002, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'DOM-1','Registre dominis','Registre dominis','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000003, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'HOS-0','Hosting compartit','Hosting compartit','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000004, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'HOS-1','Plans','Plans','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000005, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'HOS-2','Servidor virtual','Servidor virtual','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000006, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'SER-0','Servidores dedicats','Servidores dedicats','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000007, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'SER-1','Servidor dedicat model','Servidor dedicat model','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000008, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'SER-2','Servidor dedicat administrat','Servidor dedicat administrat','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000009, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'SER-3','Servidor dedicat de correu','Servidor dedicat de correu','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000010, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'ACC-I','Accés a Internet','Accés a Internet','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000011, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'HOST DNS','Hosting DNS','Hosting DNS','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000012, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'HOST MAIL','Hosting de correu','Hosting de correu','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000013, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'APL-0','Aplicacions','Aplicacions','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000014, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'APL-1','Balmes Backup','Balmes Backup','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000015, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'APL-2','Alta en cercadors','Alta en cercadors','N',0);&lt;br /&gt;
insert into m_product_category(m_product_category_id,ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby,value,name,description,isdefault,plannedmargin) values(1000016, 1000000,0,'Y','2008-11-30',1000000,'2008-11-30',1000000,'APL-3','tenda online','tenda online','N',0);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
El valor de ''m_product_category_id'' el faig consecutiu a partir de l'últim valor que tinc.&lt;br /&gt;
&lt;br /&gt;
==Inserció manual en la taula i_product==&lt;br /&gt;
&lt;br /&gt;
La documentació em diu quins són els camps obligatoris per a i_product:&lt;br /&gt;
Search key, Name, Product type, Business Partner and Product Category. El Search Key normalment es correspon amb el camp ''Value'', i té el sentit de ''referència'', és a dir, una clau primària que es fa servir en l'organització per identificar l'article (no és la clau primària interna d'openbravo ..._id).&lt;br /&gt;
&lt;br /&gt;
Això no vol dir que siguin els únics camps obligatoris per a m_product. Senzillament, que si només s'especifiquen aquests, en el procés de càrrega la resta de camps obligatoris s'omplen automàticament amb valors per defecte (per ex createdby, updatedby,  c_taxcategory_id)&lt;br /&gt;
&lt;br /&gt;
Això ho podem veure fent &lt;br /&gt;
 \d i_product&lt;br /&gt;
 \d m_product&lt;br /&gt;
&lt;br /&gt;
Puc ficar directament les dades dins de i_product:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
insert into i_product(i_product_id,ad_client_id,ad_org_id,value,name,description,producttype,m_product_category_id,pricepo,pricelist) values(1,1000000,0,'ref1','article1','desc_article1','S',1000001,25,20);&lt;br /&gt;
insert into i_product(i_product_id,ad_client_id,ad_org_id,value,name,description,producttype,m_product_category_id,pricepo,pricelist) values(2,1000000,0,'ref2','article2','desc_article2','I',1000003,45,40);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*producttype fa referència a si és un article (I) o un servei (S)&lt;br /&gt;
*value és el Search Key, i de fet correspon a la referència de l'article&lt;br /&gt;
*pricepo: preu de compra&lt;br /&gt;
*priceeffective: versió de tarifa&lt;br /&gt;
&lt;br /&gt;
Després de fer el insert, vaig a importar datos -&amp;gt; importar productos, i veig com efectivament ja tinc un article en la taula i_product, llest per importar l'article a m_product. Clico sobre 'importar productos', i es trasllada de forma satisfactòria a la taula m_product (i a altres taules relacionades), excepte el preu. El problema del preu ve relacionat amb la tarifa que aplico, cosa que he de solucionar.&lt;br /&gt;
&lt;br /&gt;
 select m_product_id, value, name from m_product;&lt;br /&gt;
&lt;br /&gt;
Veig que ja tinc l'article 1000357&lt;br /&gt;
 delete from m_product where m_product_id=1000357;&lt;br /&gt;
&lt;br /&gt;
Si vull eliminar-lo, també he d'eliminar la seva referència en i_product.&lt;br /&gt;
&lt;br /&gt;
 delete from i_product where i_product_id=1;&lt;br /&gt;
 delete from m_product where m_product_id=1000357;&lt;br /&gt;
ara sí&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1. Creo llistes de tarifes&lt;br /&gt;
LListes de tarifes&lt;br /&gt;
select m_pricelist_id,name,description from m_pricelist;&lt;br /&gt;
&lt;br /&gt;
2. Creo versions de les llistes de tarifes&lt;br /&gt;
Versions de les llistes de tarifes&lt;br /&gt;
&lt;br /&gt;
select m_pricelist_version_id,name,description,isactive,m_pricelist_id,m_discountschema_id from m_pricelist_version;&lt;br /&gt;
&lt;br /&gt;
3. Ara ja puc ficar els articles a alguna de les llistes de tarifes&lt;br /&gt;
select m_pricelist_version_id,m_product_id,isactive,pricelist,pricestd,pricelimit from m_productprice;&lt;br /&gt;
&lt;br /&gt;
pricelist: preu tarifa&lt;br /&gt;
pricestd: preu estàndar&lt;br /&gt;
pricelimit: preu límit: preu que no podrà baixar per sota&lt;br /&gt;
&lt;br /&gt;
Per tant, per tal de què en fer una importació de productes m'apareguin els preus correctament, prèviament ha d'existir una llista de tarifes que tingui almenys una versió.&lt;br /&gt;
&lt;br /&gt;
i_product: pricelist, pricepo, priceeffective&lt;br /&gt;
&lt;br /&gt;
potser per acabar-ho s'ha de fer manualment, en la taula m_productprice, l'associació del producte que he importat (m_product_id) amb la versió de tarifes (m_pricelist_version_id)&lt;br /&gt;
&lt;br /&gt;
Un cop fetes aquestes insercions&lt;br /&gt;
insert into m_productprice ...&lt;br /&gt;
&lt;br /&gt;
ja podem veure els preus cercant en dades mestres -&amp;gt; producte&lt;br /&gt;
&lt;br /&gt;
Anem a fer-ho:&lt;br /&gt;
select m_product_id,name from m_product;&lt;br /&gt;
1000005;&amp;quot;art1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
select m_pricelist_version_id,name,description,isactive,m_pricelist_id,m_discountschema_id from m_pricelist_version;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1000005;&amp;quot;03-12-2008&amp;quot;;&amp;quot;&amp;quot;;&amp;quot;Y&amp;quot;;1000004;1000001&lt;br /&gt;
&lt;br /&gt;
insert into m_productprice(&lt;br /&gt;
m_pricelist_version_id,&lt;br /&gt;
m_product_id,&lt;br /&gt;
ad_client_id,&lt;br /&gt;
ad_org_id,&lt;br /&gt;
isactive,&lt;br /&gt;
createdby,&lt;br /&gt;
updatedby,&lt;br /&gt;
pricelist,&lt;br /&gt;
pricestd,&lt;br /&gt;
pricelimit)&lt;br /&gt;
VALUES(1000005,1000005,1000002,0,'Y',1000006,1000006,50,40,30);&lt;br /&gt;
&lt;br /&gt;
Precio tarifa: Precio de catálogo establecido por el proveedor.&lt;br /&gt;
Pr. estándar: Indica el precio final del producto impuestos no incluidos.&lt;br /&gt;
Pr. límite: Indica el precio más bajo para un producto establecido en los precios de las tarifas. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joan</name></author>
		
	</entry>
</feed>