Skip to content

Commit 8b13d41

Browse files
rov-adhoccav-adhoc
authored andcommitted
[IMP] account_ux: reset to draft in out invoice when stock_valuation_layer changes
closes #515 X-original-commit: abeb628 Signed-off-by: Juan José Scarafía <[email protected]> Signed-off-by: Camila Vives <[email protected]>
1 parent 591bdc8 commit 8b13d41

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

account_ux/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
##############################################################################
55
from . import models
66
from . import wizards
7+
from .monkey_patches import *

account_ux/__manifest__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
##############################################################################
2020
{
2121
'name': 'Account UX',
22-
'version': "17.0.1.4.0",
22+
'version': "17.0.1.5.0",
2323
'category': 'Accounting',
2424
'sequence': 14,
2525
'summary': '',
@@ -55,4 +55,5 @@
5555
# instale
5656
'auto_install': True,
5757
'application': False,
58+
'post_load': 'monkey_patches',
5859
}

account_ux/models/account_move.py

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class AccountMove(models.Model):
1212
)
1313
other_currency = fields.Boolean(compute='_compute_other_currency')
1414

15+
allow_move_with_valuation_cancelation = fields.Boolean(compute='_compute_allow_move_with_valuation_cancelation')
16+
1517
def get_invoice_report(self):
1618
self.ensure_one()
1719
bin_data, __ = self.env['ir.actions.report']._render_qweb_pdf('account.account_invoices', self.id)
@@ -154,3 +156,12 @@ def _check_dates_on_invoices(self):
154156
for rec in invoices_to_check:
155157
error_msg += str(rec.date) + '\t'*2 + str(rec.invoice_date) + '\t'*3 + rec.display_name + '\n'
156158
raise UserError(_('The date and invoice date of a sale invoice must be the same: %s') % (error_msg))
159+
160+
def _compute_allow_move_with_valuation_cancelation(self):
161+
with_valuation = self.filtered('line_ids.stock_valuation_layer_ids')
162+
(self - with_valuation).allow_move_with_valuation_cancelation = False
163+
for rec in with_valuation:
164+
rec.allow_move_with_valuation_cancelation = not rec.show_reset_to_draft_button
165+
if rec.restrict_mode_hash_table:
166+
rec.with_context(bypass_valuation_cancelation= True)._compute_show_reset_to_draft_button()
167+
rec.allow_move_with_valuation_cancelation = rec.show_reset_to_draft_button

account_ux/monkey_patches.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from . import models
2+
from . import wizards
3+
from odoo.addons.stock_account.models.account_move import AccountMove
4+
5+
def monkey_patches():
6+
7+
original_method = AccountMove._compute_show_reset_to_draft_button
8+
9+
# monkey patch
10+
def _compute_show_reset_to_draft_button(self):
11+
original_method(self)
12+
if self._context.get('bypass_valuation_cancelation'):
13+
for move in self:
14+
if move.sudo().line_ids.stock_valuation_layer_ids:
15+
move.show_reset_to_draft_button = False
16+
17+
AccountMove._compute_show_reset_to_draft_button = _compute_show_reset_to_draft_button

account_ux/views/account_move_views.xml

+11-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,19 @@
1717
<field name="price_total" position="attributes">
1818
<attribute name="column_invisible"></attribute>
1919
</field>
20-
20+
2121
<button name="button_draft" position="after">
2222
<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"/>
23+
<field name="allow_move_with_valuation_cancelation" invisible = "1"/>
24+
<button name="button_draft"
25+
string="Reset to Draft"
26+
invisible="not allow_move_with_valuation_cancelation or state == 'draft'"
27+
type="object"
28+
groups="account.group_account_invoice"
29+
data-hotkey="r"
30+
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.
31+
&#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."
32+
/>
2333
</button>
2434

2535
<field name="narration" position="after">

0 commit comments

Comments
 (0)