Add products in inventory entries
This commit is contained in:
parent
9be913c47d
commit
3514944f5d
|
@ -1457,6 +1457,13 @@ class Categorias(BaseModel):
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _get_by_name(cls, name):
|
||||||
|
try:
|
||||||
|
return Categorias.get(Categorias.categoria==name)
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_all(cls):
|
def get_all(cls):
|
||||||
rows = (Categorias.select(
|
rows = (Categorias.select(
|
||||||
|
@ -9469,41 +9476,47 @@ class InventoryEntries(BaseModel):
|
||||||
return obj, msg
|
return obj, msg
|
||||||
|
|
||||||
# ~ teresa
|
# ~ teresa
|
||||||
def _get_or_create_product(self, args):
|
def _get_or_create_product(self, args, cant):
|
||||||
# ~ almacen = ForeignKeyField(Almacenes, null=True)
|
# ~ almacen = ForeignKeyField(Almacenes, null=True)
|
||||||
# ~ categoria = ForeignKeyField(Categorias, null=True)
|
|
||||||
# ~ clave = TextField(unique=True, index=True)
|
|
||||||
# ~ unidad = ForeignKeyField(SATUnidades)
|
|
||||||
# ~ ultimo_costo = DecimalField(default=0.0, max_digits=18, decimal_places=6,
|
|
||||||
# ~ auto_round=True)
|
|
||||||
# ~ existencia = DecimalField(default=0.0, max_digits=18, decimal_places=2,
|
|
||||||
# ~ auto_round=True)
|
|
||||||
# ~ impuestos = ManyToManyField(SATImpuestos, related_name='productos')
|
|
||||||
id = int(args.get('id_product', '0'))
|
id = int(args.get('id_product', '0'))
|
||||||
if id:
|
if id:
|
||||||
obj = Productos.get(Productos.id==id)
|
obj = Productos.get(Productos.id==id)
|
||||||
else:
|
else:
|
||||||
# ~ {'cant': '1.0'}
|
category = Categorias._get_by_name('Productos')
|
||||||
|
next_key = Productos.next_key()['value']
|
||||||
|
unit = SATUnidades.get_by_name(args['unit'])
|
||||||
fields = dict(
|
fields = dict(
|
||||||
|
categoria = category,
|
||||||
|
clave = next_key,
|
||||||
clave_sat = args['key_sat'],
|
clave_sat = args['key_sat'],
|
||||||
descripcion = args['description'],
|
descripcion = args['description'],
|
||||||
|
unidad = unit,
|
||||||
valor_unitario = Decimal(args['unit_value']),
|
valor_unitario = Decimal(args['unit_value']),
|
||||||
inventario = True,
|
inventario = True,
|
||||||
es_activo = True,
|
|
||||||
)
|
)
|
||||||
obj = Productos.create(**fields)
|
obj = Productos.create(**fields)
|
||||||
|
where = (SATImpuestos.activo==True & SATImpuestos.default==True)
|
||||||
|
taxes = SATImpuestos.select().where(where)
|
||||||
|
obj.impuestos = taxes
|
||||||
|
|
||||||
|
obj.existencia += cant
|
||||||
|
obj.save()
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
def _add_entries(self, partner, products):
|
def _add_entries(self, products):
|
||||||
msg = ''
|
msg = ''
|
||||||
|
|
||||||
for p in products:
|
for p in products:
|
||||||
print(type(p), p)
|
cant = float(p['cant'])
|
||||||
product = self._get_or_create_product(self, p)
|
product = self._get_or_create_product(self, p, cant)
|
||||||
|
values = dict(
|
||||||
|
product = product,
|
||||||
|
cant = cant,
|
||||||
|
)
|
||||||
|
InventoryEntries.create(**values)
|
||||||
|
|
||||||
msg = 'Validando'
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def _create(self, args):
|
def _create(self, args):
|
||||||
|
@ -9516,7 +9529,7 @@ class InventoryEntries(BaseModel):
|
||||||
|
|
||||||
# ~ ToDo - Save invoice
|
# ~ ToDo - Save invoice
|
||||||
|
|
||||||
error = self._add_entries(self, partner, args['products'])
|
error = self._add_entries(self, args['products'])
|
||||||
if error:
|
if error:
|
||||||
result = {'ok': False, 'msg': error}
|
result = {'ok': False, 'msg': error}
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -465,6 +465,7 @@ function _add_entries_inventory(data){
|
||||||
success:function(text, data, XmlHttpRequest){
|
success:function(text, data, XmlHttpRequest){
|
||||||
var values = data.json();
|
var values = data.json();
|
||||||
if (values.ok) {
|
if (values.ok) {
|
||||||
|
get_products()
|
||||||
$$('multi_invoices').setValue('products_home')
|
$$('multi_invoices').setValue('products_home')
|
||||||
$$('lbl_partner').setValue('')
|
$$('lbl_partner').setValue('')
|
||||||
grid.clearAll()
|
grid.clearAll()
|
||||||
|
@ -492,6 +493,7 @@ function cmd_save_products_add_click(id, e, node){
|
||||||
p.id_product = r.id_product
|
p.id_product = r.id_product
|
||||||
p.key_sat = r.key_sat1
|
p.key_sat = r.key_sat1
|
||||||
p.description = r.description1
|
p.description = r.description1
|
||||||
|
p.unit = r.unit
|
||||||
p.unit_value = r.unit_value1
|
p.unit_value = r.unit_value1
|
||||||
p.cant = r.cant1
|
p.cant = r.cant1
|
||||||
products.push(p)
|
products.push(p)
|
||||||
|
|
Loading…
Reference in New Issue