🎉 Initial commit - Hazard Odoo 16 project
- Custom modules: hazard_shopify, hazard_inventory_report, hazard_website - Third-party modules: bi_sql_editor, query_deluxe, sql_request_abstract, l10n_mx_sat_sync_itadmin_ee - Docker setup: Odoo 16 + PostgreSQL 17 - Utility scripts: backup_hazard.sh, update_module.py - Agent configuration: .agents/AGENTS.md - Security: Enterprise modules, credentials, backups and production data excluded via .gitignore
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
import xmlrpc.client
|
||||
|
||||
url = 'http://localhost:16001'
|
||||
db = 'hazard_new'
|
||||
username = 'admin'
|
||||
password = '123'
|
||||
|
||||
try:
|
||||
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
|
||||
uid = common.authenticate(db, username, 'admin', {})
|
||||
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
|
||||
|
||||
print("Iniciando creación de datos de prueba...")
|
||||
|
||||
# 1. Buscar IDs de Categorías
|
||||
cat_insumo = models.execute_kw(db, uid, 'admin', 'product.category', 'search', [[['name', '=', 'Insumos / Materia Prima']]])
|
||||
cat_custom = models.execute_kw(db, uid, 'admin', 'product.category', 'search', [[['name', '=', 'Producto Final Custom']]])
|
||||
|
||||
if not cat_insumo or not cat_custom:
|
||||
print("Error: No se encontraron las categorías. ¿Se ejecutó el paso 2?")
|
||||
exit(1)
|
||||
|
||||
cat_insumo_id = cat_insumo[0]
|
||||
cat_custom_id = cat_custom[0]
|
||||
|
||||
# 2. Crear Partners
|
||||
vendor_id = models.execute_kw(db, uid, 'admin', 'res.partner', 'create', [{
|
||||
'name': 'Fábrica China Test',
|
||||
'is_company': True,
|
||||
'supplier_rank': 1,
|
||||
}])
|
||||
print("Vendor creado:", vendor_id)
|
||||
|
||||
client_id = models.execute_kw(db, uid, 'admin', 'res.partner', 'create', [{
|
||||
'name': 'Club de Golf Test',
|
||||
'is_company': True,
|
||||
'customer_rank': 1,
|
||||
}])
|
||||
print("Cliente creado:", client_id)
|
||||
|
||||
# 3. Crear Productos
|
||||
insumo_id = models.execute_kw(db, uid, 'admin', 'product.product', 'create', [{
|
||||
'name': 'Tela Azul Premium (Test)',
|
||||
'type': 'product',
|
||||
'categ_id': cat_insumo_id,
|
||||
'uom_id': 1, # Unidades
|
||||
'uom_po_id': 1,
|
||||
'standard_price': 50.0,
|
||||
}])
|
||||
print("Insumo creado:", insumo_id)
|
||||
|
||||
# Para el producto final, creamos primero la línea de proveedor (seller)
|
||||
seller_id = models.execute_kw(db, uid, 'admin', 'product.supplierinfo', 'create', [{
|
||||
'partner_id': vendor_id,
|
||||
'price': 250.0, # Costo de maquila
|
||||
'delay': 7,
|
||||
}])
|
||||
|
||||
product_id = models.execute_kw(db, uid, 'admin', 'product.product', 'create', [{
|
||||
'name': 'Camisa Custom Club de Golf (Test)',
|
||||
'type': 'product',
|
||||
'categ_id': cat_custom_id,
|
||||
'list_price': 800.0, # Precio de venta
|
||||
'seller_ids': [(4, seller_id)],
|
||||
}])
|
||||
print("Producto Final creado:", product_id)
|
||||
|
||||
# Obtener el product_tmpl_id para la BoM
|
||||
prod_data = models.execute_kw(db, uid, 'admin', 'product.product', 'read', [[product_id]], {'fields': ['product_tmpl_id']})
|
||||
tmpl_id = prod_data[0]['product_tmpl_id'][0]
|
||||
|
||||
# 4. Crear BoM de Subcontratación
|
||||
bom_id = models.execute_kw(db, uid, 'admin', 'mrp.bom', 'create', [{
|
||||
'product_tmpl_id': tmpl_id,
|
||||
'type': 'subcontract',
|
||||
'subcontractor_ids': [(4, vendor_id)],
|
||||
'bom_line_ids': [
|
||||
(0, 0, {
|
||||
'product_id': insumo_id,
|
||||
'product_qty': 1.5,
|
||||
})
|
||||
]
|
||||
}])
|
||||
print("Lista de Materiales (BoM) creada:", bom_id)
|
||||
|
||||
# 5. Agregar Inventario Inicial (100 unidades de Tela)
|
||||
wh_stock = models.execute_kw(db, uid, 'admin', 'stock.location', 'search', [[['usage', '=', 'internal'], ['name', '=', 'Stock']]])
|
||||
if wh_stock:
|
||||
quant_id = models.execute_kw(db, uid, 'admin', 'stock.quant', 'create', [{
|
||||
'product_id': insumo_id,
|
||||
'location_id': wh_stock[0],
|
||||
'inventory_quantity': 100.0,
|
||||
}])
|
||||
models.execute_kw(db, uid, 'admin', 'stock.quant', 'action_apply_inventory', [[quant_id]])
|
||||
print("Inventario de Tela agregado (100 uds).")
|
||||
|
||||
# 6. Crear Cotización (SO)
|
||||
so_id = models.execute_kw(db, uid, 'admin', 'sale.order', 'create', [{
|
||||
'partner_id': client_id,
|
||||
'order_line': [
|
||||
(0, 0, {
|
||||
'product_id': product_id,
|
||||
'product_uom_qty': 5.0,
|
||||
})
|
||||
]
|
||||
}])
|
||||
print("Cotización de Venta Creada:", so_id)
|
||||
|
||||
# 7. Crear Orden de Compra (PO)
|
||||
po_id = models.execute_kw(db, uid, 'admin', 'purchase.order', 'create', [{
|
||||
'partner_id': vendor_id,
|
||||
'order_line': [
|
||||
(0, 0, {
|
||||
'product_id': product_id,
|
||||
'product_qty': 5.0,
|
||||
'price_unit': 250.0,
|
||||
})
|
||||
]
|
||||
}])
|
||||
print("Orden de Compra Creada:", po_id)
|
||||
|
||||
print("--- ¡Datos de prueba creados exitosamente! ---")
|
||||
|
||||
except Exception as e:
|
||||
print("Error general:", e)
|
||||
Reference in New Issue
Block a user