Server IP : 127.0.0.2 / Your IP : 3.15.145.122 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/sale/models/ |
Upload File : |
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from datetime import date from odoo import api, fields, models class CrmTeam(models.Model): _inherit = 'crm.team' use_quotations = fields.Boolean('Quotations', default=True, help="Check this box to manage quotations in this sales team.") use_invoices = fields.Boolean('Invoices', help="Check this box to manage invoices in this sales team.") invoiced = fields.Integer( compute='_compute_invoiced', string='Invoiced This Month', readonly=True, help="Invoice revenue for the current month. This is the amount the sales " "team has invoiced this month. It is used to compute the progression ratio " "of the current and target revenue on the kanban view.") invoiced_target = fields.Integer( string='Invoice Target', help="Target of invoice revenue for the current month. This is the amount the sales " "team estimates to be able to invoice this month.") sales_to_invoice_amount = fields.Integer( compute='_compute_sales_to_invoice_amount', string='Amount of sales to invoice', readonly=True, ) currency_id = fields.Many2one("res.currency", related='company_id.currency_id', string="Currency", readonly=True, required=True) @api.multi def _compute_sales_to_invoice_amount(self): amounts = self.env['sale.order'].read_group([ ('team_id', 'in', self.ids), ('invoice_status', '=', 'to invoice'), ], ['amount_total', 'team_id'], ['team_id']) for rec in amounts: self.browse(rec['team_id'][0]).sales_to_invoice_amount = rec['amount_total'] @api.multi def _compute_invoiced(self): for team in self: invoices = self.env['account.invoice'].search([ ('state', 'in', ['open', 'paid']), ('team_id', '=', team.id), ('date', '<=', date.today()), ('date', '>=', date.today().replace(day=1)), ('type', 'in', ['out_invoice', 'out_refund']), ]) team.invoiced = sum(invoices.mapped('amount_untaxed_signed')) @api.multi def update_invoiced_target(self, value): return self.write({'invoiced_target': round(float(value or 0))}) @api.onchange('use_quotations') def _onchange_use_quotation(self): if self.use_quotations: self.use_invoices = True