Server IP : 127.0.0.2 / Your IP : 18.222.84.251 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/account_tax_python/models/ |
Upload File : |
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import models, fields, api from odoo.tools.safe_eval import safe_eval class AccountTaxPython(models.Model): _inherit = "account.tax" amount_type = fields.Selection(selection_add=[('code', 'Python Code')]) python_compute = fields.Text(string='Python Code', default="result = price_unit * 0.10", help="Compute the amount of the tax by setting the variable 'result'.\n\n" ":param base_amount: float, actual amount on which the tax is applied\n" ":param price_unit: float\n" ":param quantity: float\n" ":param company: res.company recordset singleton\n" ":param product: product.product recordset singleton or None\n" ":param partner: res.partner recordset singleton or None") python_applicable = fields.Text(string='Applicable Code', default="result = True", help="Determine if the tax will be applied by setting the variable 'result' to True or False.\n\n" ":param price_unit: float\n" ":param quantity: float\n" ":param company: res.company recordset singleton\n" ":param product: product.product recordset singleton or None\n" ":param partner: res.partner recordset singleton or None") def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None): self.ensure_one() if self.amount_type == 'code': company = self.env.user.company_id localdict = {'base_amount': base_amount, 'price_unit':price_unit, 'quantity': quantity, 'product':product, 'partner':partner, 'company': company} safe_eval(self.python_compute, localdict, mode="exec", nocopy=True) return localdict['result'] return super(AccountTaxPython, self)._compute_amount(base_amount, price_unit, quantity, product, partner) @api.multi def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None): taxes = self.filtered(lambda r: r.amount_type != 'code') company = self.env.user.company_id for tax in self.filtered(lambda r: r.amount_type == 'code'): localdict = {'price_unit': price_unit, 'quantity': quantity, 'product': product, 'partner': partner, 'company': company} safe_eval(tax.python_applicable, localdict, mode="exec", nocopy=True) if localdict.get('result', False): taxes += tax return super(AccountTaxPython, taxes).compute_all(price_unit, currency, quantity, product, partner) class AccountTaxTemplatePython(models.Model): _inherit = 'account.tax.template' amount_type = fields.Selection(selection_add=[('code', 'Python Code')]) python_compute = fields.Text(string='Python Code', default="result = price_unit * 0.10", help="Compute the amount of the tax by setting the variable 'result'.\n\n" ":param base_amount: float, actual amount on which the tax is applied\n" ":param price_unit: float\n" ":param quantity: float\n" ":param product: product.product recordset singleton or None\n" ":param partner: res.partner recordset singleton or None") python_applicable = fields.Text(string='Applicable Code', default="result = True", help="Determine if the tax will be applied by setting the variable 'result' to True or False.\n\n" ":param price_unit: float\n" ":param quantity: float\n" ":param product: product.product recordset singleton or None\n" ":param partner: res.partner recordset singleton or None") def _get_tax_vals(self, company): """ This method generates a dictionnary of all the values for the tax that will be created. """ self.ensure_one() res = super(AccountTaxTemplatePython, self)._get_tax_vals(company) res['python_compute'] = self.python_compute res['python_applicable'] = self.python_applicable return res