<commit_before># Copyright (C) 2020  <NAME> - Akretion <<EMAIL>>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class BaseWizardMixin(models.TransientModel):
    _name = 'l10n_br_fiscal.base.wizard.mixin'
    _description = 'Fiscal Base Wizard Mixin'

    document_id = fields.Many2one(
        comodel_name='l10n_br_fiscal.document',
        string='Fiscal Document',
    )

    document_type_id = fields.Many2one(
        comodel_name='l10n_br_fiscal.document.type',
        string='Document Type',
    )

    event_id = fields.Many2one(
        comodel_name='l10n_br_fiscal.event',
        string='Fiscal Event',
    )

    partner_id = fields.Many2one(
        comodel_name='res.partner',
        string='Partner',
    )

    justification = fields.Text(
        string='Justification',
        size=255,
        required=True,
    )

    state = fields.Selection(
        selection=[
            ('init', 'init'),
            ('confirm', 'confirm'),
            ('done', 'done')
        ],
        string='State',
        readonly=True,
        default='init',
    )

    @api.model
    def default_get(self, fields_list):
        default_values = super().default_get(fields_list)
        active_model = self.env.context['active_model']
        active_id = self.env.context['active_id']

        key_field = {
            'l10n_br_fiscal.document': 'document_id',
            'res.partner': 'partner_id',
        }

        default_values.update({key_field[active_model]: active_id})
        return default_values

    @api.multi
    def button_back(self):
        self.ensure_one()
        self.state = 'init'
        return self._reopen()

    @api.multi
    def _reopen(self):
        self.ensure_one()
        return {
            'type': 'ir.actions.act_window',
            'res_model': self._name,
            'view_mode': 'form',
            'view_type': 'form',
            'res_id': self.id,
            'views': [(False, 'form')],
            'target': 'new',
            'nodestroy': True
        }<commit_msg>[REF] Base Wizard Mixin<commit_after># Copyright (C) 2020  <NAME> - Akretion <<EMAIL>>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class BaseWizardMixin(models.TransientModel):
    _name = 'l10n_br_fiscal.base.wizard.mixin'
    _description = 'Fiscal Base Wizard Mixin'

    document_id = fields.Many2one(
        comodel_name='l10n_br_fiscal.document',
        string='Fiscal Document',
    )

    document_type_id = fields.Many2one(
        comodel_name='l10n_br_fiscal.document.type',
        string='Document Type',
    )

    event_id = fields.Many2one(
        comodel_name='l10n_br_fiscal.event',
        string='Fiscal Event',
    )

    partner_id = fields.Many2one(
        comodel_name='res.partner',
        string='Partner',
    )

    justification = fields.Text(
        string='Justification',
        size=255,
        required=True,
    )

    state = fields.Selection(
        selection=[
            ('init', 'init'),
            ('confirm', 'confirm'),
            ('done', 'done')
        ],
        string='State',
        readonly=True,
        default='init',
    )

    @api.model
    def default_get(self, fields_list):
        default_values = super().default_get(fields_list)
        active_model = self.env.context['active_model']
        active_id = self.env.context['active_id']

        key_field = {
            'l10n_br_fiscal.document': 'document_id',
            'res.partner': 'partner_id',
        }

        default_values.update({key_field[active_model]: active_id})
        return default_values

    @api.multi
    def button_back(self):
        self.ensure_one()
        self.state = 'init'
        return self._reopen()

    @api.multi
    def _reopen(self):
        self.ensure_one()
        return {
            'type': 'ir.actions.act_window',
            'res_model': self._name,
            'view_mode': 'form',
            'view_type': 'form',
            'res_id': self.id,
            'views': [(False, 'form')],
            'target': 'new',
            'nodestroy': True
        }

    @api.multi
    def _close(self):
        return {'type': 'ir.actions.act_window_close'}
{'fraction_non_alphanumeric': 0.13158510887380004, 'fraction_numerical': 0.010770311402481855, 'mean_word_length': 2.14580265095729, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5541265', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1363, 'n_words': 233}