Monedero configurable por servicio y artículo
- Campo genera_monedero (default true) en servicios e items de inventario - Puntos proporcionales a las líneas elegibles al liquidar la venta - Toggle con icono Wallet en Servicios e Inventario
This commit is contained in:
@@ -35,6 +35,8 @@ class SkeenServicio(models.Model):
|
||||
color = fields.Char(string='Color', default='#1abc9c')
|
||||
service_group = fields.Char(string='Grupo')
|
||||
is_favorite = fields.Boolean(string='Favorito', default=False)
|
||||
genera_monedero = fields.Boolean(string='Genera monedero', default=True,
|
||||
help='Si está activo, la venta de este servicio acumula puntos monedero.')
|
||||
tag_ids = fields.Many2many('skeen.service.tag', string='Etiquetas')
|
||||
|
||||
# Configuración
|
||||
|
||||
@@ -120,6 +120,7 @@
|
||||
<field name="code"/>
|
||||
<field name="category"/>
|
||||
<field name="active"/>
|
||||
<field name="genera_monedero"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="price"/>
|
||||
|
||||
@@ -28,6 +28,8 @@ class SkeenInventarioItem(models.Model):
|
||||
expiry_date = fields.Date(string='Caducidad')
|
||||
last_count_date = fields.Date(string='Último conteo físico')
|
||||
active = fields.Boolean(string='Activo', default=True)
|
||||
genera_monedero = fields.Boolean(string='Genera monedero', default=True,
|
||||
help='Si está activo, la venta de este artículo acumula puntos monedero.')
|
||||
notes = fields.Text(string='Notas')
|
||||
|
||||
move_ids = fields.One2many('skeen.inventario.move', 'item_id', string='Movimientos')
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<field name="qty_optimal"/>
|
||||
<field name="cost"/>
|
||||
<field name="price"/>
|
||||
<field name="genera_monedero"/>
|
||||
<field name="inventory_value" sum="Total"/>
|
||||
<field name="stock_level" widget="badge"
|
||||
decoration-danger="stock_level=='out'"
|
||||
@@ -41,6 +42,7 @@
|
||||
<field name="category"/>
|
||||
<field name="unit"/>
|
||||
<field name="active"/>
|
||||
<field name="genera_monedero"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="qty"/>
|
||||
|
||||
@@ -87,11 +87,16 @@ class SkeenVenta(models.Model):
|
||||
'payment_state': 'paid',
|
||||
'amount_paid': venta.total,
|
||||
})
|
||||
# Acumular puntos
|
||||
# Acumular puntos (proporcional a líneas que generan monedero)
|
||||
monedero = self.env['skeen.monedero'].search([('partner_id', '=', venta.partner_id.id)], limit=1)
|
||||
if not monedero:
|
||||
monedero = self.env['skeen.monedero'].create({'partner_id': venta.partner_id.id})
|
||||
points = int(venta.total / 10)
|
||||
subtotal_total = sum(l.subtotal for l in venta.line_ids)
|
||||
elegible = sum(
|
||||
l.subtotal for l in venta.line_ids
|
||||
if (l.service_id and l.service_id.genera_monedero) or (l.item_id and l.item_id.genera_monedero)
|
||||
)
|
||||
points = int(venta.total * (elegible / subtotal_total) / 10) if subtotal_total else 0
|
||||
if points > 0:
|
||||
monedero.add_points(points, description=f'Venta {venta.name}', reference=venta.name)
|
||||
|
||||
|
||||
@@ -1555,7 +1555,7 @@ class SkeenFrontendController(http.Controller):
|
||||
if not service.exists():
|
||||
return json_response({'status': 'error', 'message': 'Servicio no encontrado'}, 404)
|
||||
data = _parse_json_body()
|
||||
allowed = ['name', 'code', 'category', 'price', 'duration_min', 'package_price', 'package_sessions', 'package_notes', 'description', 'color', 'service_group', 'is_favorite', 'active']
|
||||
allowed = ['name', 'code', 'category', 'price', 'duration_min', 'package_price', 'package_sessions', 'package_notes', 'description', 'color', 'service_group', 'is_favorite', 'genera_monedero', 'active']
|
||||
vals = {k: data[k] for k in allowed if k in data}
|
||||
Servicio = request.env['skeen.servicio'].sudo()
|
||||
if vals.get('name'):
|
||||
@@ -1586,6 +1586,7 @@ class SkeenFrontendController(http.Controller):
|
||||
'color': s.color,
|
||||
'service_group': s.service_group or '',
|
||||
'is_favorite': s.is_favorite,
|
||||
'genera_monedero': s.genera_monedero,
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
@@ -3290,6 +3291,7 @@ class SkeenFrontendController(http.Controller):
|
||||
'expiry_date': it.expiry_date.strftime('%Y-%m-%d') if it.expiry_date else None,
|
||||
'last_count_date': it.last_count_date.strftime('%Y-%m-%d') if it.last_count_date else None,
|
||||
'active': it.active,
|
||||
'genera_monedero': it.genera_monedero,
|
||||
'notes': it.notes or '',
|
||||
'stock_level': it.stock_level,
|
||||
}
|
||||
@@ -3373,7 +3375,7 @@ class SkeenFrontendController(http.Controller):
|
||||
return json_response({'status': 'error', 'message': 'Item no encontrado'}, 404)
|
||||
data = _parse_json_body()
|
||||
allowed = ['name', 'kind', 'sku', 'category', 'unit', 'qty_optimal', 'qty_min',
|
||||
'cost', 'expiry_date', 'notes', 'active']
|
||||
'cost', 'expiry_date', 'notes', 'active', 'genera_monedero']
|
||||
vals = {}
|
||||
for k in allowed:
|
||||
if k in data:
|
||||
|
||||
Reference in New Issue
Block a user