diff --git a/account_ux/__init__.py b/account_ux/__init__.py index 6c1e1357a..7ccf57687 100644 --- a/account_ux/__init__.py +++ b/account_ux/__init__.py @@ -4,3 +4,4 @@ ############################################################################## from . import models from . import wizards +from .monkey_patches import * diff --git a/account_ux/__manifest__.py b/account_ux/__manifest__.py index 66dd270c0..671501593 100644 --- a/account_ux/__manifest__.py +++ b/account_ux/__manifest__.py @@ -19,7 +19,7 @@ ############################################################################## { 'name': 'Account UX', - 'version': "17.0.1.4.0", + 'version': "17.0.1.5.0", 'category': 'Accounting', 'sequence': 14, 'summary': '', @@ -55,4 +55,5 @@ # instale 'auto_install': True, 'application': False, + 'post_load': 'monkey_patches', } diff --git a/account_ux/models/account_move.py b/account_ux/models/account_move.py index 59a822ab2..6472217df 100644 --- a/account_ux/models/account_move.py +++ b/account_ux/models/account_move.py @@ -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) @@ -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 diff --git a/account_ux/monkey_patches.py b/account_ux/monkey_patches.py new file mode 100644 index 000000000..86d4f5ff8 --- /dev/null +++ b/account_ux/monkey_patches.py @@ -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 diff --git a/account_ux/views/account_move_views.xml b/account_ux/views/account_move_views.xml index a28fdb8ea..ac5d2b965 100644 --- a/account_ux/views/account_move_views.xml +++ b/account_ux/views/account_move_views.xml @@ -17,9 +17,19 @@ - +