Voy a poner un pequeño ejemplo de como importar productos a Tryton con Proteus (A library to access Tryton's models like a client.)

El CSV que uso solo tiene 3 columnas con el nombre, precio de venta y precio de coste

!/usr/bin/env python
import csv
import sys
from decimal import Decimal
from proteus import config, Model, Wizard

products = csv.reader(open('products.csv', 'r'))
config = config.set_trytond('MiBBDD', database_type='postgresql', config_file='/opt/tryton/28/trytond.conf')

Product = Model.get('product.product')
ProductTemplate = Model.get('product.template')
Category = Model.get('product.category')
ProductUom = Model.get('product.uom')

category, = Category.find([('name', '=', 'OTROS')])
unit, = ProductUom.find([('symbol', '=', 'u')])

def LoadProducts ():
  header=True
  for line in products:
    # Skip the header
    if not header:
      print line[0]
      pt = ProductTemplate()
      pt.name = line[0]
      pt.list_price = Decimal(line[1])
      pt.cost_price = Decimal(line[2])
      pt.category = category
      pt.default_uom = unit
      pt.type = 'goods'
      pt.purchasable = True
      pt.salable = True
      pt.account_category = True
      pt.taxes_category = True
      pt.code = 'code'
      pt.manufacter_code = 'manufacter_code'
      pt.save()

      product = Product(template=pt)
      product.save()

    header=False

if __name__ == "__main__":
  LoadProducts()

Esta basado en el modulo demo de gnu-health, cuando usaba CSV para importar los datos
Gracias a @sebastianmarro por la referencia :)

Caregorias

Add new comment

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
CAPTCHA
12 + 4 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.