|
|
@ -4,29 +4,29 @@ |
|
|
|
# Copyright 2016 Camptocamp - Akim Juillerat (<http://www.camptocamp.com>). |
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
|
|
|
|
from odoo import api, models, exceptions, _ |
|
|
|
from odoo import _, api, exceptions, models |
|
|
|
|
|
|
|
|
|
|
|
class ResPartner(models.Model): |
|
|
|
"""Assigns 'ref' from a sequence on creation and copying""" |
|
|
|
|
|
|
|
_inherit = 'res.partner' |
|
|
|
_inherit = "res.partner" |
|
|
|
|
|
|
|
@api.multi |
|
|
|
def _get_next_ref(self, vals=None): |
|
|
|
return self.env['ir.sequence'].next_by_code('res.partner') |
|
|
|
return self.env["ir.sequence"].next_by_code("res.partner") |
|
|
|
|
|
|
|
@api.model |
|
|
|
def create(self, vals): |
|
|
|
if not vals.get('ref') and self._needsRef(vals=vals): |
|
|
|
vals['ref'] = self._get_next_ref(vals=vals) |
|
|
|
if not vals.get("ref") and self._needsRef(vals=vals): |
|
|
|
vals["ref"] = self._get_next_ref(vals=vals) |
|
|
|
return super(ResPartner, self).create(vals) |
|
|
|
|
|
|
|
@api.multi |
|
|
|
def copy(self, default=None): |
|
|
|
default = default or {} |
|
|
|
if self._needsRef(): |
|
|
|
default['ref'] = self._get_next_ref() |
|
|
|
default["ref"] = self._get_next_ref() |
|
|
|
return super(ResPartner, self).copy(default) |
|
|
|
|
|
|
|
@api.multi |
|
|
@ -34,11 +34,11 @@ class ResPartner(models.Model): |
|
|
|
for partner in self: |
|
|
|
partner_vals = vals.copy() |
|
|
|
if ( |
|
|
|
not partner_vals.get('ref') |
|
|
|
and partner._needsRef(partner_vals) |
|
|
|
and not partner.ref |
|
|
|
not partner_vals.get("ref") |
|
|
|
and partner._needsRef(partner_vals) |
|
|
|
and not partner.ref |
|
|
|
): |
|
|
|
partner_vals['ref'] = partner._get_next_ref(vals=partner_vals) |
|
|
|
partner_vals["ref"] = partner._get_next_ref(vals=partner_vals) |
|
|
|
super(ResPartner, partner).write(partner_vals) |
|
|
|
return True |
|
|
|
|
|
|
@ -52,14 +52,15 @@ class ResPartner(models.Model): |
|
|
|
partner's 'ref' |
|
|
|
""" |
|
|
|
if not vals and not self: # pragma: no cover |
|
|
|
raise exceptions.UserError(_( |
|
|
|
'Either field values or an id must be provided.')) |
|
|
|
raise exceptions.UserError( |
|
|
|
_("Either field values or an id must be provided.") |
|
|
|
) |
|
|
|
# only assign a 'ref' to commercial partners |
|
|
|
if self: |
|
|
|
vals = {} |
|
|
|
vals['is_company'] = self.is_company |
|
|
|
vals['parent_id'] = self.parent_id |
|
|
|
return vals.get('is_company') or not vals.get('parent_id') |
|
|
|
vals["is_company"] = self.is_company |
|
|
|
vals["parent_id"] = self.parent_id |
|
|
|
return vals.get("is_company") or not vals.get("parent_id") |
|
|
|
|
|
|
|
@api.model |
|
|
|
def _commercial_fields(self): |
|
|
@ -67,4 +68,4 @@ class ResPartner(models.Model): |
|
|
|
Make the partner reference a field that is propagated |
|
|
|
to the partner's contacts |
|
|
|
""" |
|
|
|
return super(ResPartner, self)._commercial_fields() + ['ref'] |
|
|
|
return super(ResPartner, self)._commercial_fields() + ["ref"] |