Server IP : 127.0.0.2 / Your IP : 13.58.229.23 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_fr_certification/models/ |
Upload File : |
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from openerp import fields, models, api UNALTERABLE_COUNTRIES = ['FR', 'MF', 'MQ', 'NC', 'PF', 'RE', 'GF', 'GP', 'TF'] class ResCompany(models.Model): _inherit = 'res.company' # To do in master : refactor to set sequences more generic l10n_fr_secure_sequence_id = fields.Many2one('ir.sequence', 'Sequence to use to ensure the securisation of data', readonly=True) @api.model def create(self, vals): company = super(ResCompany, self).create(vals) #when creating a new french company, create the securisation sequence as well if company._is_accounting_unalterable(): sequence_fields = ['l10n_fr_secure_sequence_id'] company._create_secure_sequence(sequence_fields) return company @api.multi def write(self, vals): res = super(ResCompany, self).write(vals) #if country changed to fr, create the securisation sequence for company in self: if company._is_accounting_unalterable(): sequence_fields = ['l10n_fr_secure_sequence_id'] company._create_secure_sequence(sequence_fields) return res def _create_secure_sequence(self, sequence_fields): """This function creates a no_gap sequence on each companies in self that will ensure a unique number is given to all posted account.move in such a way that we can always find the previous move of a journal entry. """ for company in self: vals_write = {} for seq_field in sequence_fields: if not company[seq_field]: vals = { 'name': 'French Securisation of ' + seq_field + ' - ' + company.name, 'code': 'FRSECUR', 'implementation': 'no_gap', 'prefix': '', 'suffix': '', 'padding': 0, 'company_id': company.id} seq = self.env['ir.sequence'].create(vals) vals_write[seq_field] = seq.id if vals_write: company.write(vals_write) def _is_vat_french(self): return self.vat and self.vat.startswith('FR') and len(self.vat) == 13 def _is_accounting_unalterable(self): if not self.vat and not self.country_id: return False return self.country_id and self.country_id.code in UNALTERABLE_COUNTRIES or self._is_vat_french()