From a62bb6b59ca291fa5b2b684f8a5986fd9d5f0be8 Mon Sep 17 00:00:00 2001 From: KLYSTRON Date: Thu, 14 May 2026 17:40:15 +0530 Subject: [PATCH 1/4] [FIX]Warning and Erros fix --- om_account_asset/models/account_asset.py | 2 -- .../asset_depreciation_confirmation_wizard.py | 1 - .../report/report_cashbook.py | 2 ++ om_account_followup/wizard/followup_print.py | 3 +-- om_fiscal_year/models/account_settings.py | 14 +++++------ om_hr_payroll/models/hr_payslip.py | 24 +++++++++++++------ ...report_contribution_register_templates.xml | 6 ++--- .../report_payslip_details_templates.xml | 4 ++-- .../models/recurring_payment.py | 10 ++++---- 9 files changed, 36 insertions(+), 30 deletions(-) diff --git a/om_account_asset/models/account_asset.py b/om_account_asset/models/account_asset.py index a09f5e88..2ae8209f 100644 --- a/om_account_asset/models/account_asset.py +++ b/om_account_asset/models/account_asset.py @@ -386,7 +386,6 @@ def _return_disposal_view(self, move_ids): view_mode = 'tree,form' return { 'name': name, - 'view_type': 'form', 'view_mode': view_mode, 'res_model': 'account.move', 'type': 'ir.actions.act_window', @@ -536,7 +535,6 @@ def open_entries(self): move_ids.append(depreciation_line.move_id.id) return { 'name': _('Journal Entries'), - 'view_type': 'form', 'view_mode': 'list,form', 'res_model': 'account.move', 'view_id': False, diff --git a/om_account_asset/wizard/asset_depreciation_confirmation_wizard.py b/om_account_asset/wizard/asset_depreciation_confirmation_wizard.py index 4d86963a..958e3092 100644 --- a/om_account_asset/wizard/asset_depreciation_confirmation_wizard.py +++ b/om_account_asset/wizard/asset_depreciation_confirmation_wizard.py @@ -20,7 +20,6 @@ def asset_compute(self): return { 'name': _('Created Asset Moves') if context.get('asset_type') == 'purchase' else _('Created Revenue Moves'), - 'view_type': 'form', 'view_mode': 'list,form', 'res_model': 'account.move', 'view_id': False, diff --git a/om_account_daily_reports/report/report_cashbook.py b/om_account_daily_reports/report/report_cashbook.py index b45e08c7..1264fd2e 100644 --- a/om_account_daily_reports/report/report_cashbook.py +++ b/om_account_daily_reports/report/report_cashbook.py @@ -25,6 +25,8 @@ def _get_account_move_entry(self, accounts, init_balance, sortby, display_accoun 'move_lines': list of move line } """ + if not accounts: + return [] cr = self.env.cr MoveLine = self.env['account.move.line'] move_lines = {x: [] for x in accounts.ids} diff --git a/om_account_followup/wizard/followup_print.py b/om_account_followup/wizard/followup_print.py index bdc4af97..cd4bac1f 100644 --- a/om_account_followup/wizard/followup_print.py +++ b/om_account_followup/wizard/followup_print.py @@ -31,7 +31,7 @@ def _get_followup(self): related='followup_id.company_id') email_conf = fields.Boolean('Send Email Confirmation') email_subject = fields.Char('Email Subject', size=64, - default=_('Invoices Reminder')) + default=lambda self: self.env._('Invoices Reminder')) partner_lang = fields.Boolean( 'Send Email in Partner Language', default=True, help='Do not change message text, if you want to send email in ' @@ -148,7 +148,6 @@ def do_process(self): 'report_data': restot['action']}) return { 'name': _('Send Letters and Emails: Actions Summary'), - 'view_type': 'form', 'context': context, 'view_mode': 'list,form', 'res_model': 'followup.sending.results', diff --git a/om_fiscal_year/models/account_settings.py b/om_fiscal_year/models/account_settings.py index d06569ce..870b8575 100644 --- a/om_fiscal_year/models/account_settings.py +++ b/om_fiscal_year/models/account_settings.py @@ -5,25 +5,25 @@ class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' fiscalyear_last_day = fields.Integer( - related='company_id.fiscalyear_last_day', readonly=False + related='company_id.fiscalyear_last_day', readonly=False, string='Fiscal Year Last Day' ) fiscalyear_last_month = fields.Selection( - related='company_id.fiscalyear_last_month', readonly=False + related='company_id.fiscalyear_last_month', readonly=False, string='Fiscal Year Last Month' ) tax_lock_date = fields.Date( - related='company_id.hard_lock_date', readonly=False + related='company_id.hard_lock_date', readonly=False, string='Tax Lock Date' ) sale_lock_date = fields.Date( - related='company_id.hard_lock_date', readonly=False + related='company_id.hard_lock_date', readonly=False, string='Sale Lock Date' ) purchase_lock_date = fields.Date( - related='company_id.hard_lock_date', readonly=False + related='company_id.hard_lock_date', readonly=False, string='Purchase Lock Date' ) hard_lock_date = fields.Date( - related='company_id.hard_lock_date', readonly=False + related='company_id.hard_lock_date', readonly=False, string='Hard Lock Date' ) fiscalyear_lock_date = fields.Date( - related='company_id.fiscalyear_lock_date', readonly=False + related='company_id.fiscalyear_lock_date', readonly=False, string='Fiscal Year Lock Date' ) group_fiscal_year = fields.Boolean( string='Fiscal Years', implied_group='om_fiscal_year.group_fiscal_year' diff --git a/om_hr_payroll/models/hr_payslip.py b/om_hr_payroll/models/hr_payslip.py index 6d095b1b..ce97c208 100644 --- a/om_hr_payroll/models/hr_payslip.py +++ b/om_hr_payroll/models/hr_payslip.py @@ -149,7 +149,6 @@ def refund_sheet(self): 'name': (_("Refund Payslip")), 'view_mode': 'list, form', 'view_id': False, - 'view_type': 'form', 'res_model': 'hr.payslip', 'type': 'ir.actions.act_window', 'target': 'current', @@ -503,12 +502,19 @@ def onchange_employee_id(self, date_from, date_to, employee_id=False, contract_i } if (not employee_id) or (not date_from) or (not date_to): return res + ttyme = datetime.combine(fields.Date.from_string(date_from), time.min) employee = self.env['hr.employee'].browse(employee_id) locale = self.env.context.get('lang') or 'en_US' res['value'].update({ - 'name': _('Salary Slip of %s for %s') % (employee.name, tools.ustr( - babel.dates.format_date(date=ttyme, format='MMMM-y', locale=locale))), + 'name': _('Salary Slip of %s for %s') % ( + employee.name, + babel.dates.format_date( + date=ttyme, + format='MMMM-y', + locale=locale + ) + ), 'company_id': employee.company_id.id, }) @@ -558,8 +564,14 @@ def onchange_employee(self): ttyme = datetime.combine(fields.Date.from_string(date_from), time.min) locale = self.env.context.get('lang') or 'en_US' - self.name = _('Salary Slip of %s for %s') % (employee.name, tools.ustr( - babel.dates.format_date(date=ttyme, format='MMMM-y', locale=locale))) + self.name = _('Salary Slip of %s for %s') % ( + employee.name, + babel.dates.format_date( + date=ttyme, + format='MMMM-y', + locale=locale + ) + ) self.company_id = employee.company_id if not self.env.context.get('version') or not self.version_id: @@ -808,7 +820,6 @@ def unlink(self): # 'name': (_("Refund Payslip")), # 'view_mode': 'list, form', # 'view_id': False, -# 'view_type': 'form', # 'res_model': 'hr.payslip', # 'type': 'ir.actions.act_window', # 'target': 'current', @@ -1470,7 +1481,6 @@ def unlink(self): # 'name': (_("Refund Payslip")), # 'view_mode': 'list, form', # 'view_id': False, -# 'view_type': 'form', # 'res_model': 'hr.payslip', # 'type': 'ir.actions.act_window', # 'target': 'current', diff --git a/om_hr_payroll/views/report_contribution_register_templates.xml b/om_hr_payroll/views/report_contribution_register_templates.xml index 30472cb9..693732f5 100644 --- a/om_hr_payroll/views/report_contribution_register_templates.xml +++ b/om_hr_payroll/views/report_contribution_register_templates.xml @@ -49,11 +49,11 @@ + t-options='{"widget": "monetary", "display_currency": o.company_id.currency_id}'/> + t-options='{"widget": "monetary", "display_currency": o.company_id.currency_id}'/> @@ -68,7 +68,7 @@ + t-options='{"widget": "monetary", "display_currency": o.company_id.currency_id}'/> diff --git a/om_hr_payroll/views/report_payslip_details_templates.xml b/om_hr_payroll/views/report_payslip_details_templates.xml index ea146691..5e72e7e0 100644 --- a/om_hr_payroll/views/report_payslip_details_templates.xml +++ b/om_hr_payroll/views/report_payslip_details_templates.xml @@ -88,7 +88,7 @@ + t-options='{"widget": "monetary", "display_currency": o.company_id.currency_id}'/> @@ -121,7 +121,7 @@ + t-options='{"widget": "monetary", "display_currency": o.company_id.currency_id}'/> diff --git a/om_recurring_payments/models/recurring_payment.py b/om_recurring_payments/models/recurring_payment.py index b5e2dfee..7384d588 100644 --- a/om_recurring_payments/models/recurring_payment.py +++ b/om_recurring_payments/models/recurring_payment.py @@ -6,7 +6,7 @@ class RecurringPayment(models.Model): _name = 'recurring.payment' - _description = 'Recurring Payment(' + _description = 'Recurring Payment' _rec_name = 'name' name = fields.Char('Name', readonly=True) @@ -86,6 +86,9 @@ def action_generate_payment(self): @api.model_create_multi def create(self, vals_list): for vals in vals_list: + if vals.get('amount', 0) <= 0: + raise ValidationError(_('Amount must be a non-zero positive number.')) + if 'company_id' in vals: vals['name'] = self.env['ir.sequence'].with_context(force_company=vals['company_id']).next_by_code( 'recurring.payment') or _('New') @@ -93,11 +96,6 @@ def create(self, vals_list): vals['name'] = self.env['ir.sequence'].next_by_code('recurring.payment') or _('New') return super(RecurringPayment, self).create(vals) - @api.constrains('amount') - def _check_amount(self): - if self.amount <= 0: - raise ValidationError(_('Amount Must Be Non-Zero Positive Number')) - def unlink(self): for rec in self: if rec.state == 'done': From ab04e475ff8eb17decb2cc561311459e2116e600 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 16 May 2026 09:50:08 +0530 Subject: [PATCH 2/4] [IMP]Warnings and errors fix --- .../models/account_move_line.py | 74 ++++-------- om_account_asset/models/account_asset.py | 2 +- .../views/account_asset_views.xml | 4 +- .../models/account_analytic_account.py | 44 +++---- om_account_budget/models/account_budget.py | 107 +++++++++++++----- 5 files changed, 126 insertions(+), 105 deletions(-) diff --git a/accounting_pdf_reports/models/account_move_line.py b/accounting_pdf_reports/models/account_move_line.py index 9beb71e7..3667005e 100644 --- a/accounting_pdf_reports/models/account_move_line.py +++ b/accounting_pdf_reports/models/account_move_line.py @@ -1,50 +1,10 @@ import ast -from odoo.osv import expression -from odoo import api, models, fields +from odoo import api, models class AccountMoveLine(models.Model): _inherit = "account.move.line" - @api.model - def _where_calc(self, domain, active_test=True): - """Computes the WHERE clause needed to implement an OpenERP domain. - - :param list domain: the domain to compute - :param bool active_test: whether the default filtering of records with - ``active`` field set to ``False`` should be applied. - :return: the query expressing the given domain as provided in domain - :rtype: Query - """ - # if the object has an active field ('active', 'x_active'), filter out all - # inactive records unless they were explicitly asked for - if self._active_name and active_test and self.env.context.get('active_test', True): - # the item[0] trick below works for domain items and '&'/'|'/'!' - # operators too - if not any(item[0] == self._active_name for item in domain): - domain = [(self._active_name, '=', 1)] + domain - - if domain: - return expression.expression(domain, self).query - else: - return Query(self.env, self._table, self._table_sql) - - @api.model - def _apply_ir_rules(self, query, mode='read'): - """Add what's missing in ``query`` to implement all appropriate ir.rules - (using the ``model_name``'s rules or the current model's rules if ``model_name`` is None) - - :param query: the current query object - """ - if self.env.su: - return - - # apply main rules on the object - Rule = self.env['ir.rule'] - domain = Rule._compute_domain(self._name, mode) - if domain: - expression.expression(domain, self.sudo(), self._table, query) - @api.model def _query_get(self, domain=None): self.check_access('read') @@ -61,7 +21,8 @@ def _query_get(self, domain=None): domain += [(date_field, '<=', context['date_to'])] if context.get('date_from'): if not context.get('strict_range'): - domain += ['|', (date_field, '>=', context['date_from']), ('account_id.include_initial_balance', '=', True)] + domain += ['|', (date_field, '>=', context['date_from']), + ('account_id.include_initial_balance', '=', True)] elif context.get('initial_bal'): domain += [(date_field, '<', context['date_from'])] else: @@ -82,7 +43,9 @@ def _query_get(self, domain=None): domain += [('company_id', '=', self.env.company.id)] if context.get('reconcile_date'): - domain += ['|', ('reconciled', '=', False), '|', ('matched_debit_ids.max_date', '>', context['reconcile_date']), ('matched_credit_ids.max_date', '>', context['reconcile_date'])] + domain += ['|', ('reconciled', '=', False), '|', + ('matched_debit_ids.max_date', '>', context['reconcile_date']), + ('matched_credit_ids.max_date', '>', context['reconcile_date'])] if context.get('account_tag_ids'): domain += [('account_id.tag_ids', 'in', context['account_tag_ids'].ids)] @@ -90,9 +53,6 @@ def _query_get(self, domain=None): if context.get('account_ids'): domain += [('account_id', 'in', context['account_ids'].ids)] - if context.get('analytic_tag_ids'): - domain += [('analytic_tag_ids', 'in', context['analytic_tag_ids'].ids)] - if context.get('analytic_account_ids'): domain += [('analytic_distribution', 'in', context['analytic_account_ids'].ids)] @@ -102,16 +62,24 @@ def _query_get(self, domain=None): if context.get('partner_categories'): domain += [('partner_id.category_id', 'in', context['partner_categories'].ids)] + tables = '"account_move_line"' where_clause = "" where_clause_params = [] - tables = '' + if domain: domain.append(('display_type', 'not in', ('line_section', 'line_note'))) domain.append(('parent_state', '!=', 'cancel')) - query = self._where_calc(domain) - self._apply_ir_rules(query) - from_string, from_params = query.from_clause - where_string, where_params = query.where_clause - tables, where_clause, where_clause_params = from_string, where_string, from_params + where_params - return tables, where_clause, where_clause_params + # Use _search() to get matching IDs, then build a simple WHERE + # This avoids touching the unstable Query object API entirely + record_ids = self._search(domain) + + if record_ids: + where_clause = '"account_move_line".id IN %s' + where_clause_params = [tuple(record_ids)] + else: + # No records match — return impossible condition + where_clause = '"account_move_line".id IS NULL' + where_clause_params = [] + + return tables, where_clause, where_clause_params \ No newline at end of file diff --git a/om_account_asset/models/account_asset.py b/om_account_asset/models/account_asset.py index 2ae8209f..b589344d 100644 --- a/om_account_asset/models/account_asset.py +++ b/om_account_asset/models/account_asset.py @@ -460,7 +460,7 @@ def onchange_date_first_depreciation(self): @api.depends('depreciation_line_ids.move_id') def _entry_count(self): for asset in self: - res = self.env['account.asset.depreciation.line'].search_count([('asset_id', '=', asset.id), ('move_id', '!=', False)]) + res = self.env['account.asset.depreciation.line'].search_count([('asset_id', 'in', asset.ids), ('move_id', '!=', False)]) asset.entry_count = res or 0 @api.constrains('prorata', 'method_time') diff --git a/om_account_asset/views/account_asset_views.xml b/om_account_asset/views/account_asset_views.xml index 8b2e0b08..9022f92a 100644 --- a/om_account_asset/views/account_asset_views.xml +++ b/om_account_asset/views/account_asset_views.xml @@ -124,8 +124,8 @@ + invisible="method_time == 'number'" + required="method_time == 'end'"/> diff --git a/om_account_budget/models/account_analytic_account.py b/om_account_budget/models/account_analytic_account.py index 412d8c16..7bb521fe 100644 --- a/om_account_budget/models/account_analytic_account.py +++ b/om_account_budget/models/account_analytic_account.py @@ -12,26 +12,26 @@ class AccountAnalyticAccount(models.Model): class AccountAnalyticLine(models.Model): _inherit = 'account.analytic.line' - @api.model - def _where_calc(self, domain, active_test=True): - """Computes the WHERE clause needed to implement an OpenERP domain. - - :param list domain: the domain to compute - :param bool active_test: whether the default filtering of records with - ``active`` field set to ``False`` should be applied. - :return: the query expressing the given domain as provided in domain - :rtype: Query - """ - # if the object has an active field ('active', 'x_active'), filter out all - # inactive records unless they were explicitly asked for - if self._active_name and active_test and self._context.get('active_test', True): - # the item[0] trick below works for domain items and '&'/'|'/'!' - # operators too - if not any(item[0] == self._active_name for item in domain): - domain = [(self._active_name, '=', 1)] + domain - - if domain: - return expression.expression(domain, self).query - else: - return Query(self.env, self._table, self._table_sql) + # @api.model + # def _where_calc(self, domain, active_test=True): + # """Computes the WHERE clause needed to implement an OpenERP domain. + # + # :param list domain: the domain to compute + # :param bool active_test: whether the default filtering of records with + # ``active`` field set to ``False`` should be applied. + # :return: the query expressing the given domain as provided in domain + # :rtype: Query + # """ + # # if the object has an active field ('active', 'x_active'), filter out all + # # inactive records unless they were explicitly asked for + # if self._active_name and active_test and self._context.get('active_test', True): + # # the item[0] trick below works for domain items and '&'/'|'/'!' + # # operators too + # if not any(item[0] == self._active_name for item in domain): + # domain = [(self._active_name, '=', 1)] + domain + # + # if domain: + # return expression.expression(domain, self).query + # else: + # return Query(self.env, self._table, self._table_sql) diff --git a/om_account_budget/models/account_budget.py b/om_account_budget/models/account_budget.py index 72068795..04a06b95 100644 --- a/om_account_budget/models/account_budget.py +++ b/om_account_budget/models/account_budget.py @@ -163,41 +163,94 @@ def _compute_practical_amount(self): acc_ids = line.general_budget_id.account_ids.ids date_to = line.date_to date_from = line.date_from + if line.analytic_account_id.id: - analytic_line_obj = self.env['account.analytic.line'] - domain = [('account_id', '=', line.analytic_account_id.id), - ('date', '>=', date_from), - ('date', '<=', date_to), - ] + domain = [ + ('account_id', '=', line.analytic_account_id.id), + ('date', '>=', date_from), + ('date', '<=', date_to), + ] if acc_ids: domain += [('general_account_id', 'in', acc_ids)] - where_query = analytic_line_obj._where_calc(domain) - analytic_line_obj._apply_ir_rules(where_query, 'read') - from_string, from_params = where_query.from_clause - where_string, where_params = where_query.where_clause - from_clause, where_clause, where_clause_params = from_string, where_string, from_params + where_params - - select = "SELECT SUM(amount) from " + from_clause + " where " + where_clause + self.env.cr.execute(""" + SELECT SUM(amount) + FROM account_analytic_line aal + WHERE aal.account_id = %s + AND aal.date >= %s + AND aal.date <= %s + {acc_filter} + """.format( + acc_filter="AND aal.general_account_id IN %s" if acc_ids else "" + ), ( + line.analytic_account_id.id, + date_from, + date_to, + *((tuple(acc_ids),) if acc_ids else ()), + )) else: - aml_obj = self.env['account.move.line'] - domain = [('account_id', 'in', - line.general_budget_id.account_ids.ids), - ('date', '>=', date_from), - ('date', '<=', date_to) - ] - where_query = aml_obj._where_calc(domain) - aml_obj._apply_ir_rules(where_query, 'read') - from_string, from_params = where_query.from_clause - where_string, where_params = where_query.where_clause - from_clause, where_clause, where_clause_params = from_string, where_string, from_params + where_params - - select = "SELECT sum(credit)-sum(debit) from " + from_clause + " where " + where_clause - - self.env.cr.execute(select, where_clause_params) + account_ids = line.general_budget_id.account_ids.ids + if not account_ids: + line.practical_amount = 0.0 + continue + + self.env.cr.execute(""" + SELECT SUM(credit) - SUM(debit) + FROM account_move_line aml + INNER JOIN account_move am ON am.id = aml.move_id + WHERE aml.account_id IN %s + AND aml.date >= %s + AND aml.date <= %s + AND am.state = 'posted' + """, ( + tuple(account_ids), + date_from, + date_to, + )) + line.practical_amount = self.env.cr.fetchone()[0] or 0.0 + # def _compute_practical_amount(self): + # for line in self: + # acc_ids = line.general_budget_id.account_ids.ids + # date_to = line.date_to + # date_from = line.date_from + # if line.analytic_account_id.id: + # analytic_line_obj = self.env['account.analytic.line'] + # domain = [('account_id', '=', line.analytic_account_id.id), + # ('date', '>=', date_from), + # ('date', '<=', date_to), + # ] + # if acc_ids: + # domain += [('general_account_id', 'in', acc_ids)] + # + # where_query = analytic_line_obj._where_calc(domain) + # analytic_line_obj._apply_ir_rules(where_query, 'read') + # from_string, from_params = where_query.from_clause + # where_string, where_params = where_query.where_clause + # from_clause, where_clause, where_clause_params = from_string, where_string, from_params + where_params + # + # select = "SELECT SUM(amount) from " + from_clause + " where " + where_clause + # + # else: + # aml_obj = self.env['account.move.line'] + # domain = [('account_id', 'in', + # line.general_budget_id.account_ids.ids), + # ('date', '>=', date_from), + # ('date', '<=', date_to) + # ] + # where_query = aml_obj._where_calc(domain) + # aml_obj._apply_ir_rules(where_query, 'read') + # from_string, from_params = where_query.from_clause + # where_string, where_params = where_query.where_clause + # from_clause, where_clause, where_clause_params = from_string, where_string, from_params + where_params + # + # select = "SELECT sum(credit)-sum(debit) from " + from_clause + " where " + where_clause + # + # self.env.cr.execute(select, where_clause_params) + # line.practical_amount = self.env.cr.fetchone()[0] or 0.0 + def _compute_theoritical_amount(self): # beware: 'today' variable is mocked in the python tests and thus, its implementation matter today = fields.Date.today() From 4df0c782b2efd7c65151ff3f599a9933970e6e7f Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 16 May 2026 23:09:48 +0530 Subject: [PATCH 3/4] [FIX]Warning and errors fix --- om_data_remove/models/model.py | 210 ++++++++++++++++++++++-------- om_fiscal_year/views/settings.xml | 118 ++++++++++------- 2 files changed, 228 insertions(+), 100 deletions(-) diff --git a/om_data_remove/models/model.py b/om_data_remove/models/model.py index 6dbba541..d0c728e0 100644 --- a/om_data_remove/models/model.py +++ b/om_data_remove/models/model.py @@ -7,6 +7,40 @@ class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' + # def _remove_data(self, o, s=[]): + # if not self.env.user.has_group('base.group_system'): + # return False + # for line in o: + # try: + # if not self.env['ir.model']._get(line): + # continue + # except Exception as e: + # _logger.warning('remove data error get ir.model: %s,%s', line, e) + # continue + # obj_name = line + # obj = self.pool.get(obj_name) + # if not obj: + # t_name = obj_name.replace('.', '_') + # else: + # t_name = obj._table + # sql = "delete from %s" % t_name + # try: + # self.env.cr.execute(sql) + # self.env.cr.commit() + # except Exception as e: + # _logger.warning('remove data error: %s,%s', line, e) + # for line in s: + # domain = ['|', ('code', '=ilike', line + '%'), ('prefix', '=ilike', line + '%')] + # try: + # seqs = self.env['ir.sequence'].sudo().search(domain) + # if seqs.exists(): + # seqs.write({ + # 'number_next': 1, + # }) + # except Exception as e: + # _logger.warning('reset sequence data error: %s,%s', line, e) + # return True + def _remove_data(self, o, s=[]): if not self.env.user.has_group('base.group_system'): return False @@ -16,6 +50,7 @@ def _remove_data(self, o, s=[]): continue except Exception as e: _logger.warning('remove data error get ir.model: %s,%s', line, e) + self.env.cr.rollback() # ← reset aborted transaction continue obj_name = line obj = self.pool.get(obj_name) @@ -25,9 +60,10 @@ def _remove_data(self, o, s=[]): t_name = obj._table sql = "delete from %s" % t_name try: - self._cr.execute(sql) - self._cr.commit() + self.env.cr.execute(sql) + self.env.cr.commit() except Exception as e: + self.env.cr.rollback() # ← reset aborted transaction _logger.warning('remove data error: %s,%s', line, e) for line in s: domain = ['|', ('code', '=ilike', line + '%'), ('prefix', '=ilike', line + '%')] @@ -38,6 +74,7 @@ def _remove_data(self, o, s=[]): 'number_next': 1, }) except Exception as e: + self.env.cr.rollback() # ← reset aborted transaction _logger.warning('reset sequence data error: %s,%s', line, e) return True @@ -89,9 +126,10 @@ def _remove_pos(self): ] res = self._remove_data(to_removes, seqs) try: - statement = self.env['account.bank.statement'].sudo().search([]) - for s in statement: - s._end_balance() + pass + # statement = self.env['account.bank.statement'].sudo().search([]) + # for s in statement: + # s._end_balance() except Exception as e: _logger.error('reset sequence data error: %s', e) return res @@ -167,8 +205,6 @@ def _remove_inventory(self): 'stock.picking', 'stock.scrap', 'stock.picking.batch', - 'stock.inventory.line', - 'stock.inventory', 'stock.valuation.layer', 'stock.production.lot', 'procurement.group', @@ -222,37 +258,56 @@ def _remove_account_chart(self): if not self.env.user.has_group('base.group_system'): return False company_id = self.env.company.id - self = self.with_context(force_company=company_id, company_id=company_id) - to_removes = [ - 'res.partner.bank', - 'account.move.line', - 'account.invoice', - 'account.payment', - 'account.bank.statement', - 'account.tax.account.tag', - 'account.tax', - 'account.account.account.tag', - 'wizard_multi_charts_accounts', - 'account.journal', - 'account.account', - ] + company = self.env['res.company'].browse(company_id) + self = self.with_company(company) + try: field1 = self.env['ir.model.fields']._get('product.template', "taxes_id").id field2 = self.env['ir.model.fields']._get('product.template', "supplier_taxes_id").id - sql = "delete from ir_default where (field_id = %s or field_id = %s) and company_id=%d" \ % (field1, field2, company_id) sql2 = "update account_journal set bank_account_id=NULL where company_id=%d;" % company_id - self._cr.execute(sql) - self._cr.execute(sql2) - - self._cr.commit() + self.env.cr.execute(sql) + self.env.cr.execute(sql2) + self.env.cr.commit() except Exception as e: + self.env.cr.rollback() _logger.error('remove data error: %s,%s', 'account_chart: set tax and account_journal', e) - if self.env['ir.model']._get('pos.config'): - self.env['pos.config'].write({ - 'journal_id': False, - }) + return False + + # Step 2: NULL out account_journal.default_account_id + try: + self.env.cr.execute( + "UPDATE account_journal SET default_account_id = NULL WHERE company_id = %d" % company_id + ) + self.env.cr.commit() + except Exception as e: + self.env.cr.rollback() + _logger.error('remove data error: %s,%s', 'account_journal default_account_id', e) + + # Step 3: NULL out pos_payment_method journal and account references + try: + if self.env['ir.model']._get('pos.payment.method'): + self.env.cr.execute( + "UPDATE pos_payment_method SET journal_id = NULL, outstanding_account_id = NULL" + ) + self.env.cr.commit() + except Exception as e: + self.env.cr.rollback() + _logger.error('remove data error: %s,%s', 'pos_payment_method journal_id', e) + + # Step 4: NULL out pos_config.journal_id via SQL + try: + if self.env['ir.model']._get('pos.config'): + self.env.cr.execute( + "UPDATE pos_config SET journal_id = NULL" + ) + self.env.cr.commit() + except Exception as e: + self.env.cr.rollback() + _logger.error('remove data error: %s,%s', 'pos_config journal_id', e) + + # Step 5: Clear partner account properties try: rec = self.env['res.partner'].search([]) for r in rec: @@ -261,20 +316,32 @@ def _remove_account_chart(self): 'property_account_payable_id': None, }) except Exception as e: - _logger.error('remove data error: %s,%s', 'account_chart', e) + self.env.cr.rollback() + _logger.error('remove data error: %s,%s', 'account_chart res.partner', e) + + # Step 6: Clear product category account properties try: + cat_fields = { + 'property_account_income_categ_id': None, + 'property_account_expense_categ_id': None, + } + optional_cat_fields = [ + 'property_account_creditor_price_difference_categ', + 'property_stock_account_input_categ_id', + 'property_stock_account_output_categ_id', + 'property_stock_valuation_account_id', + ] + for f in optional_cat_fields: + if f in self.env['product.category']._fields: + cat_fields[f] = None rec = self.env['product.category'].search([]) for r in rec: - r.write({ - 'property_account_income_categ_id': None, - 'property_account_expense_categ_id': None, - 'property_account_creditor_price_difference_categ': None, - 'property_stock_account_input_categ_id': None, - 'property_stock_account_output_categ_id': None, - 'property_stock_valuation_account_id': None, - }) + r.write(cat_fields) except Exception as e: - pass + self.env.cr.rollback() + _logger.error('remove data error: %s,%s', 'account_chart product.category', e) + + # Step 7: Clear product template account properties try: rec = self.env['product.template'].search([]) for r in rec: @@ -283,19 +350,59 @@ def _remove_account_chart(self): 'property_account_expense_id': None, }) except Exception as e: - pass + self.env.cr.rollback() + _logger.error('remove data error: %s,%s', 'account_chart product.template', e) + + # Step 8: Clear stock location account properties via SQL try: - rec = self.env['stock.location'].search([]) - for r in rec: - r.write({ - 'valuation_in_account_id': None, - 'valuation_out_account_id': None, - }) + if self.env['ir.model']._get('stock.location'): + for f in ['valuation_in_account_id', 'valuation_out_account_id']: + if f in self.env['stock.location']._fields: + self.env.cr.execute( + "UPDATE stock_location SET %s = NULL" % f + ) + self.env.cr.commit() except Exception as e: - pass - seqs = [] - res = self._remove_data(to_removes, seqs) - return res + self.env.cr.rollback() + _logger.error('remove data error: %s,%s', 'account_chart stock.location', e) + + # Step 9: NULL out payment_account_id on account_payment_method_line + try: + if self.env['ir.model']._get('account.payment.method.line'): + self.env.cr.execute( + "UPDATE account_payment_method_line SET payment_account_id = NULL" + ) + self.env.cr.commit() + except Exception as e: + self.env.cr.rollback() + _logger.error('remove data error: %s,%s', 'account_payment_method_line payment_account_id', e) + + # Step 10: Delete in correct FK order + to_removes = [ + 'account.move.line', + 'account.payment', + 'account.bank.statement', + 'account.tax.account.tag', + 'account.tax', + 'account.account.account.tag', + 'account.payment.method.line', + 'account.journal', + 'res.partner.bank', + 'account.account', + ] + return self._remove_data(to_removes, []) + + # def _remove_project(self): + # if not self.env.user.has_group('base.group_system'): + # return False + # to_removes = [ + # 'account.analytic.line', + # 'project.task', + # 'project.forecast', + # 'project.project', + # ] + # seqs = [] + # return self._remove_data(to_removes, seqs) def _remove_project(self): if not self.env.user.has_group('base.group_system'): @@ -304,6 +411,7 @@ def _remove_project(self): 'account.analytic.line', 'project.task', 'project.forecast', + 'project.update', 'project.project', ] seqs = [] diff --git a/om_fiscal_year/views/settings.xml b/om_fiscal_year/views/settings.xml index 52017e9c..ac7d6c7b 100644 --- a/om_fiscal_year/views/settings.xml +++ b/om_fiscal_year/views/settings.xml @@ -1,68 +1,88 @@ - + res.config.settings.view.form.inherit.accountant res.config.settings - - -
-
-
- -
-
-
-
+ + + +
+
+
-
-
- + +
+ + +