Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX][CL] La cantidad debe ser positiva en apunte analítico #30

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stock_analytic/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
"name": "Stock Analytic",
"summary": "Adds analytic distribution in stock move",
"version": "16.0.1.2.0",
"version": "16.0.1.2.1",
"author": "Julius Network Solutions, "
"ClearCorp, OpenSynergy Indonesia, "
"Hibou Corp., "
Expand Down
16 changes: 16 additions & 0 deletions stock_analytic/migrations/16.0.1.2.1/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from openupgradelib import openupgrade

@openupgrade.migrate(use_env=True)
def migrate(env, version):
"""
A todos los registros en la tabla account_analytic_line que tengan un valor negativo en el campo unit_amount
lo convierte a positivo mediante SQL para no desencadenar algún método
"""
env.cr.execute("""
UPDATE account_analytic_line
SET unit_amount = ABS(unit_amount)
WHERE unit_amount < 0
""")
1 change: 1 addition & 0 deletions stock_analytic/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from . import stock_move
from . import stock_picking
from . import stock_scrap
from . import account_analytic_line
21 changes: 21 additions & 0 deletions stock_analytic/models/account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, _


class AccountAnalyticLine(models.Model):
_inherit = 'account.analytic.line'

# CRUD METHODS
@api.model_create_multi
def create(self, vals):
"""
Antes de crear, se verifica que el campo de cantidad sea positivo
Si no lo es, se lo convierte a positivo
"""
for val in vals:
if 'unit_amount' in val:
if val['unit_amount'] < 0:
val['unit_amount'] = abs(val['unit_amount'])
return super().create(vals)
Comment on lines +11 to +21
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seguro no hay como desde los métodos que hereda el stock_move @CILC98??? Está muy agresivo desde el create...

Copy link
Author

@CILC98 CILC98 Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existe tal vez algún caso en que los apuntes analíticos deban tener la cantidad en negativo? Si no es así, creo que sería la mejor opción, ya que no solo desde un lugar se crean estos apuntes.

Loading