You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.9 KiB
50 lines
1.9 KiB
# -*- coding: utf-8 -*-
|
|
# © 2015-2016 Camptocamp SA
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
from openerp import models, fields, api
|
|
|
|
|
|
class ResPartner(models.Model):
|
|
_inherit = 'res.partner'
|
|
|
|
changeset_ids = fields.One2many(comodel_name='res.partner.changeset',
|
|
inverse_name='partner_id',
|
|
string='Changesets',
|
|
readonly=True)
|
|
count_pending_changesets = fields.Integer(
|
|
string='Changes',
|
|
compute='_count_pending_changesets',
|
|
search='_search_count_pending_changesets')
|
|
|
|
@api.one
|
|
@api.depends('changeset_ids', 'changeset_ids.state')
|
|
def _count_pending_changesets(self):
|
|
changesets = self.changeset_ids.filtered(
|
|
lambda rev: rev.state == 'draft' and rev.partner_id == self
|
|
)
|
|
self.count_pending_changesets = len(changesets)
|
|
|
|
@api.multi
|
|
def write(self, values):
|
|
if self.env.context.get('__no_changeset'):
|
|
return super(ResPartner, self).write(values)
|
|
else:
|
|
changeset_model = self.env['res.partner.changeset']
|
|
for record in self:
|
|
local_values = changeset_model.add_changeset(record, values)
|
|
super(ResPartner, record).write(local_values)
|
|
return True
|
|
|
|
def _search_count_pending_changesets(self, operator, value):
|
|
if operator not in ('=', '!=', '<', '<=', '>', '>=', 'in', 'not in'):
|
|
return []
|
|
query = ("SELECT p.id "
|
|
"FROM res_partner p "
|
|
"INNER JOIN res_partner_changeset r ON r.partner_id = p.id "
|
|
"WHERE r.state = 'draft' "
|
|
"GROUP BY p.id "
|
|
"HAVING COUNT(r.id) %s %%s ") % operator
|
|
self.env.cr.execute(query, (value,))
|
|
ids = [row[0] for row in self.env.cr.fetchall()]
|
|
return [('id', 'in', ids)]
|