You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sale_id = fields.Many2one('sale.order', string='Orden de Venta', compute='calcular_saleorder')
@api.one
@api.depends('origin')
def calcular_saleorder(self):
if self.origin:
obj_sale_order = self.env['sale.order'].search([('name', '=', self.origin)], limit=1)
if obj_sale_order:
self.sale_id = obj_sale_order[0]
Consultas rápidas a Odoo
obj_product_product = self.env['product.product'].search([('active', '=', True)])
for id in obj_product_product:
# print id.name
default_code = "-"
if id.default_code:
default_code = id.default_code
Consultas rápidas a Odoo
obj_stock_move = self.env['stock.move'].search([('state', '=', 'confirmed')])
for id in obj_stock_move:
print id.name
Creando Valores
from odoo.exceptions import ValidationError
for id in self.tag_mrp_ids:
contador += 1
vals = {
'template_id': self.product_id.id,
'name': id.name,
'tag_date': datetime.today(),
}
print vals
insert = self.env['tag.list'].create(vals)
if contador != self.product_qty:
raise ValidationError(_("Importante! La cantidad de tags no es igual a los productos a producir"))
cad_short = self.default_code
# cad_short = "131012"
self.env.cr.execute("SELECT * FROM product_template WHERE default_code LIKE '" + cad_short + "%' ")
if self.env.cr.rowcount:
res = self.env.cr.dictfetchall()
for fila in res:
mayor = 0
numero_correlativo = fila['default_code']
numero_correlativo = numero_correlativo[6:9]
if numero_correlativo == '':
numero_correlativo = '0'
numero = int(numero_correlativo)
if numero > mayor:
mayor = numero
Ejemplo de consulta SQL en Odoo buscando un elemento
cr.dictfetchall() will give you [{'reg_no': 123},{'reg_no': 543},].
cr.dictfetchone() will give you {'reg_no': 123}.
cr.fetchall() will give you '[(123),(543)]'.
cr.fetchone() will give you '(123)'.
Ejemplo de busqueda con actualización
@api.multi
def run_sii_partner_update(self, exe, alias=None):
tiempo_inicial = time()
_logger.info('Se ha Iniciado el Proceso de Actualizacion de Contribuyente')
contador = 1
obj_partner = self.env['res.partner'].search([('active', '=', 'True')])
if obj_partner:
for id in obj_partner:
contador = contador + 1
if id.document_number:
print str(contador) + "-" + id.document_number
obj_partner_sii = self.env['sii.partner'].search([('document_number', '=', id.document_number)])
if obj_partner_sii:
for id_sii in obj_partner_sii:
id.dte_email = id_sii.dte_email
Orden
obj_stock_move = self.env['stock.move'].search([('picking_type_id', '=', 4), ('state', 'in', ['confirmed', 'assigned'])]).sorted('date_expected')
# ('id desc')
consecutivo_linea_so = 1
for id in obj_stock_move:
if id.state == 'confirmed' or id.state == 'assigned':
Recorrer
obj_product_product = self.env['product.product'].search([('active', '=', True)])
for id in obj_product_product:
# print id.name
default_code = "-"
if id.default_code:
default_code = id.default_code
barcode = ""
if id.barcode:
barcode = id.barcode
color = ""
numero = ""
talla = ""
if id.attribute_value_ids:
# print id.attribute_value_ids
for att in id.attribute_value_ids:
if att.attribute_id.name == "Color" or att.attribute_id.name == "color" or att.attribute_id.name == "COLOR":
color = att.name