-
Notifications
You must be signed in to change notification settings - Fork 0
/
26_script_inventario.py
55 lines (48 loc) · 1.8 KB
/
26_script_inventario.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import csv
from proteus import config, Model, Wizard
from datetime import datetime, timedelta
import pytz
database = 'database_name'
user = 'nodux_admin_user'
password = 'nodux_admin_password'
config_file = 'path_to_file_nodux_config'
config = config.set_trytond(database=database, user=user, language='es_EC.UTF-8', password=password, config_file=config_file)
Product = Model.get('product.product')
ProductUom = Model.get('product.uom')
ProductSupplier = Model.get('purchase.product_supplier')
unit, = ProductUom.find([('symbol', '=', 'u')])
Inventory = Model.get('stock.inventory')
Location = Model.get('stock.location')
InventoryLines = Model.get('stock.inventory.line')
def LoadInventory():
timezone = pytz.timezone('America/Guayaquil')
dt = datetime.today()
fecha = datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone)
inventory = Inventory()
location = Location.find([('type', '=', 'storage'), ('id', '=', 3)])
print "Location ", location
inventory.location = location[0]
inventory.date = fecha
lost_found, = Location.find([('type', '=', 'lost_found')])
inventory.lost_found = lost_found
products = csv.reader(open('inventario.csv', 'r'))
inicio = 2
for i in range(inicio - 1):
products.next()
cont = 1
for index,row in enumerate(products):
code = row[0]
cantidad = int(row[1])
if cantidad < 1:
cantidad = int(0)
producto = Product.find([('code', '=', code)])
if producto:
if producto[0].template.type == "service":
pass
else:
print "Product ",cont, producto[0].code
inventory.lines.new(product=producto[0], quantity=cantidad)
cont = cont +1
inventory.save()
print "Creado inventario", inventory
LoadInventory()