Skip to content

Commit

Permalink
[IMP] account_ux: reset to draft in out invoice when stock_valuation_…
Browse files Browse the repository at this point in the history
…layer changes

closes #515

X-original-commit: abeb628
Signed-off-by: Juan José Scarafía <[email protected]>
Signed-off-by: Camila Vives <[email protected]>
  • Loading branch information
rov-adhoc authored and cav-adhoc committed May 16, 2024
1 parent 591bdc8 commit 8b13d41
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions account_ux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
##############################################################################
from . import models
from . import wizards
from .monkey_patches import *
3 changes: 2 additions & 1 deletion account_ux/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Account UX',
'version': "17.0.1.4.0",
'version': "17.0.1.5.0",
'category': 'Accounting',
'sequence': 14,
'summary': '',
Expand Down Expand Up @@ -55,4 +55,5 @@
# instale
'auto_install': True,
'application': False,
'post_load': 'monkey_patches',
}
11 changes: 11 additions & 0 deletions account_ux/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class AccountMove(models.Model):
)
other_currency = fields.Boolean(compute='_compute_other_currency')

allow_move_with_valuation_cancelation = fields.Boolean(compute='_compute_allow_move_with_valuation_cancelation')

def get_invoice_report(self):
self.ensure_one()
bin_data, __ = self.env['ir.actions.report']._render_qweb_pdf('account.account_invoices', self.id)
Expand Down Expand Up @@ -154,3 +156,12 @@ def _check_dates_on_invoices(self):
for rec in invoices_to_check:
error_msg += str(rec.date) + '\t'*2 + str(rec.invoice_date) + '\t'*3 + rec.display_name + '\n'
raise UserError(_('The date and invoice date of a sale invoice must be the same: %s') % (error_msg))

def _compute_allow_move_with_valuation_cancelation(self):
with_valuation = self.filtered('line_ids.stock_valuation_layer_ids')
(self - with_valuation).allow_move_with_valuation_cancelation = False
for rec in with_valuation:
rec.allow_move_with_valuation_cancelation = not rec.show_reset_to_draft_button
if rec.restrict_mode_hash_table:
rec.with_context(bypass_valuation_cancelation= True)._compute_show_reset_to_draft_button()
rec.allow_move_with_valuation_cancelation = rec.show_reset_to_draft_button
17 changes: 17 additions & 0 deletions account_ux/monkey_patches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from . import models
from . import wizards
from odoo.addons.stock_account.models.account_move import AccountMove

def monkey_patches():

original_method = AccountMove._compute_show_reset_to_draft_button

# monkey patch
def _compute_show_reset_to_draft_button(self):
original_method(self)
if self._context.get('bypass_valuation_cancelation'):
for move in self:
if move.sudo().line_ids.stock_valuation_layer_ids:
move.show_reset_to_draft_button = False

AccountMove._compute_show_reset_to_draft_button = _compute_show_reset_to_draft_button
12 changes: 11 additions & 1 deletion account_ux/views/account_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@
<field name="price_total" position="attributes">
<attribute name="column_invisible"></attribute>
</field>

<button name="button_draft" position="after">
<button name="delete_number" string="Delete Number" invisible="state != 'cancel' or not name or name == '/'" type="object" help="Deleting the number will allow you to delete this invoice or to get a new number if you re-validate it. If this invoice represents a voided invoice, then you should not clean it." confirm="Warning! This can't be undone. Deleting the number will allow you to delete this invoice or to get a new number if you re-validate it. If this invoice represents a voided invoice, then you should not clean it. Do you want to continue?" groups="account.group_account_manager"/>
<field name="allow_move_with_valuation_cancelation" invisible = "1"/>
<button name="button_draft"
string="Reset to Draft"
invisible="not allow_move_with_valuation_cancelation or state == 'draft'"
type="object"
groups="account.group_account_invoice"
data-hotkey="r"
confirm="Este asiento contable está relacionado a una valoración de inventario, tenga en consideración que al reestablecer a borrador, la misma no se eliminará. Es decir, que si usted vuelve a re-validar la factura se le duplicará la valoración.
&#10;&#10;Recomendación: Con modo desarrollador, dirigirse al menú de Inventario/Informes/Valoración, agrupar por 'Producto', desplegar el producto a ajustar y a través del '+' se puede generar un asiento de valoración manual para realizar el ajuste correspondiente."
/>
</button>

<field name="narration" position="after">
Expand Down

0 comments on commit 8b13d41

Please sign in to comment.