Browse Source

fix after review

fix demo data for tests on other module to pass
pull/380/head
Damien Crier 7 years ago
parent
commit
466dd47720
  1. 2
      partner_changeset/README.rst
  2. 4
      partner_changeset/demo/changeset_field_rule.xml
  3. 2
      partner_changeset/models/changeset_field_rule.py
  4. 12
      partner_changeset/models/res_partner.py
  5. 53
      partner_changeset/models/res_partner_changeset.py

2
partner_changeset/README.rst

@ -123,7 +123,7 @@ Screenshot:
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/134/9.0
:target: https://runbot.odoo-community.org/runbot/134/10.0
Known issues / Roadmap
======================

4
partner_changeset/demo/changeset_field_rule.xml

@ -8,7 +8,7 @@
<record model="changeset.field.rule" id="changeset_field_rule_street">
<field name="field_id" ref="base.field_res_partner_street"/>
<field name="action">validate</field>
<field name="action">auto</field>
</record>
<record model="changeset.field.rule" id="changeset_field_rule_street2">
@ -38,7 +38,7 @@
<record model="changeset.field.rule" id="changeset_field_rule_country_id">
<field name="field_id" ref="base.field_res_partner_country_id"/>
<field name="action">validate</field>
<field name="action">auto</field>
</record>
<record model="changeset.field.rule" id="changeset_field_rule_credit_limit">

2
partner_changeset/models/changeset_field_rule.py

@ -2,7 +2,7 @@
# Copyright 2015-2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api
from odoo import api, fields, models
from odoo.tools.cache import ormcache

12
partner_changeset/models/res_partner.py

@ -2,7 +2,7 @@
# Copyright 2015-2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api
from odoo import api, fields, models
class ResPartner(models.Model):
@ -17,13 +17,13 @@ class ResPartner(models.Model):
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)
for rec in self:
changesets = rec.changeset_ids.filtered(
lambda rev: rev.state == 'draft' and rev.partner_id == rec
)
rec.count_pending_changesets = len(changesets)
@api.multi
def write(self, values):

53
partner_changeset/models/res_partner_changeset.py

@ -6,7 +6,8 @@ from itertools import groupby
from lxml import etree
from operator import attrgetter
from odoo import models, fields, api, exceptions, _
from odoo import api, fields, models
from odoo import exceptions, _
from odoo.osv.orm import setup_modifiers
# sentinel object to be sure that no empty value was passed to
@ -52,14 +53,14 @@ class ResPartnerChangeset(models.Model):
models = self.env['ir.model'].search([])
return [(model.model, model.name) for model in models]
@api.one
@api.depends('change_ids', 'change_ids.state')
def _compute_state(self):
if all(change.state in ('done', 'cancel') for change
in self.mapped('change_ids')):
self.state = 'done'
else:
self.state = 'draft'
for rec in self:
if all(change.state in ('done', 'cancel') for change
in rec.mapped('change_ids')):
rec.state = 'done'
else:
rec.state = 'draft'
@api.multi
def apply(self):
@ -69,7 +70,7 @@ class ResPartnerChangeset(models.Model):
def cancel(self):
self.mapped('change_ids').cancel()
@api.multi
@api.model
def add_changeset(self, record, values):
""" Add a changeset on a partner
@ -306,25 +307,25 @@ class ResPartnerChangesetChange(models.Model):
_old_value_fields +
_new_value_fields)
@api.one
@api.depends('changeset_id.partner_id')
def _compute_origin_values(self):
field_name = self.get_field_for_type(self.field_id, 'origin')
if self.state == 'draft':
value = self.changeset_id.partner_id[self.field_id.name]
else:
old_field = self.get_field_for_type(self.field_id, 'old')
value = self[old_field]
setattr(self, field_name, value)
for rec in self:
field_name = rec.get_field_for_type(rec.field_id, 'origin')
if rec.state == 'draft':
value = rec.changeset_id.partner_id[rec.field_id.name]
else:
old_field = rec.get_field_for_type(rec.field_id, 'old')
value = rec[old_field]
setattr(rec, field_name, value)
@api.one
@api.depends(lambda self: self._value_fields)
def _compute_value_display(self):
for prefix in ('origin', 'new'):
value = getattr(self, 'get_%s_value' % prefix)()
if self.field_id.ttype == 'many2one' and value:
value = value.display_name
setattr(self, '%s_value_display' % prefix, value)
for rec in self:
for prefix in ('origin', 'new'):
value = getattr(rec, 'get_%s_value' % prefix)()
if rec.field_id.ttype == 'many2one' and value:
value = value.display_name
setattr(rec, '%s_value_display' % prefix, value)
@api.model
def get_field_for_type(self, field, prefix):
@ -369,7 +370,8 @@ class ResPartnerChangesetChange(models.Model):
"""
changes_ok = self.browse()
key = attrgetter('changeset_id')
for changeset, changes in groupby(self.sorted(key=key), key=key):
for changeset, changes in groupby(self.with_context(
__no_changeset=True).sorted(key=key), key=key):
values = {}
partner = changeset.partner_id
for change in changes:
@ -405,7 +407,7 @@ class ResPartnerChangesetChange(models.Model):
'this one.')
)
partner.with_context(__no_changeset=True).write(values)
partner.write(values)
changes_ok.write({'state': 'done'})
@ -455,7 +457,7 @@ class ResPartnerChangesetChange(models.Model):
else:
return value
@api.multi
@api.model
def _prepare_changeset_change(self, record, rule, field_name, value):
""" Prepare data for a changeset change
@ -494,6 +496,7 @@ class ResPartnerChangesetChange(models.Model):
return change, pop_value
@api.model
def fields_view_get(self, *args, **kwargs):
_super = super(ResPartnerChangesetChange, self)
result = _super.fields_view_get(*args, **kwargs)

Loading…
Cancel
Save