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/product/models/ |
Upload File : |
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import fields, models, api class Partner(models.Model): _name = 'res.partner' _inherit = 'res.partner' property_product_pricelist = fields.Many2one( 'product.pricelist', 'Sale Pricelist', compute='_compute_product_pricelist', inverse="_inverse_product_pricelist", company_dependent=False, # NOT A REAL PROPERTY help="This pricelist will be used, instead of the default one, for sales to the current partner") @api.multi @api.depends('country_id') def _compute_product_pricelist(self): for p in self: if not isinstance(p.id, models.NewId): # if not onchange p.property_product_pricelist = self.env['product.pricelist']._get_partner_pricelist(p.id) @api.one def _inverse_product_pricelist(self): pls = self.env['product.pricelist'].search( [('country_group_ids.country_ids.code', '=', self.country_id and self.country_id.code or False)], limit=1 ) default_for_country = pls and pls[0] actual = self.env['ir.property'].get('property_product_pricelist', 'res.partner', 'res.partner,%s' % self.id) # update at each change country, and so erase old pricelist if self.property_product_pricelist or (actual and default_for_country and default_for_country.id != actual.id): # keep the company of the current user before sudo self.env['ir.property'].with_context(force_company=self.env.user.company_id.id).sudo().set_multi( 'property_product_pricelist', self._name, {self.id: self.property_product_pricelist or default_for_country.id}, default_value=default_for_country.id ) def _commercial_fields(self): return super(Partner, self)._commercial_fields() + ['property_product_pricelist']