Laurent Mignon (ACSONE)
9 years ago
committed by
cubells
7 changed files with 139 additions and 91 deletions
-
68base_partner_sequence/README.rst
-
21base_partner_sequence/__init__.py
-
19base_partner_sequence/__openerp__.py
-
2base_partner_sequence/models/__init__.py
-
99base_partner_sequence/models/partner.py
-
2base_partner_sequence/tests/__init__.py
-
19base_partner_sequence/tests/test_base_partner_sequence.py
@ -0,0 +1,68 @@ |
|||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
|
||||
|
====================================== |
||||
|
Add a sequence on partner's reference. |
||||
|
====================================== |
||||
|
|
||||
|
This module adds the possibility to define a sequence for |
||||
|
the partner's reference. This reference is then set as default |
||||
|
when you create a new partner, using the defined sequence. |
||||
|
|
||||
|
The reference field is treated as a commercial field, i.e. it |
||||
|
is managed from the commercial partner and then propagated to |
||||
|
the partner's contacts. The field is visible on the contacts, |
||||
|
but it can only be modified from the commercial partner. |
||||
|
|
||||
|
No references are assigned for contacts such as shipping and |
||||
|
invoice addresses. |
||||
|
This module is a migration of the original base_partner_sequence |
||||
|
addon to OpenERP version 7.0. |
||||
|
|
||||
|
|
||||
|
Usage |
||||
|
===== |
||||
|
|
||||
|
.. 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/8.0 |
||||
|
|
||||
|
|
||||
|
Bug Tracker |
||||
|
=========== |
||||
|
|
||||
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/partner-contact/issues>`_. |
||||
|
In case of trouble, please check there if your issue has already been reported. |
||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback |
||||
|
`here <https://github.com/OCA/partner-contact/issues/new?body=module:%base_partner_sequence%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
||||
|
|
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Thomas Rehn <thomas.rehn@initos.com> |
||||
|
* Stefan Rijnhart <stefan@therp.nl> |
||||
|
* Yannick Vaucher <yannick.vaucher@camptocamp.com> |
||||
|
* Sandy Carter <sandy.carter@savoirfairelinux.com> |
||||
|
* Laurent Mignon (ACSONE) <laurent.mignon@acsone.eu> |
||||
|
* Guewen Baconnier <guewen.baconnier@camptocamp.com> |
||||
|
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com> |
||||
|
|
||||
|
Maintainer |
||||
|
---------- |
||||
|
|
||||
|
.. image:: https://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
:target: https://odoo-community.org |
||||
|
|
||||
|
This module is maintained by the OCA. |
||||
|
|
||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose |
||||
|
mission is to support the collaborative development of Odoo features and |
||||
|
promote its widespread use. |
||||
|
|
||||
|
To contribute to this module, please visit http://odoo-community.org. |
@ -1,22 +1,3 @@ |
|||||
# -*- encoding: utf-8 -*- |
# -*- encoding: utf-8 -*- |
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). |
|
||||
# |
|
||||
# This program is free software: you can redistribute it and/or modify |
|
||||
# it under the terms of the GNU Affero General Public License as |
|
||||
# published by the Free Software Foundation, either version 3 of the |
|
||||
# License, or (at your option) any later version. |
|
||||
# |
|
||||
# This program is distributed in the hope that it will be useful, |
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
# GNU Affero General Public License for more details. |
|
||||
# |
|
||||
# You should have received a copy of the GNU Affero General Public License |
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
|
||||
from . import models |
from . import models |
||||
|
from . import tests |
@ -0,0 +1,2 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
from . import partner |
@ -1,76 +1,69 @@ |
|||||
# -*- encoding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). |
|
||||
# Copyright (C) 2013 initOS GmbH & Co. KG (<http://www.initos.com>). |
|
||||
# Author Thomas Rehn <thomas.rehn at initos.com> |
|
||||
# |
|
||||
# This program is free software: you can redistribute it and/or modify |
|
||||
# it under the terms of the GNU Affero General Public License as |
|
||||
# published by the Free Software Foundation, either version 3 of the |
|
||||
# License, or (at your option) any later version. |
|
||||
# |
|
||||
# This program is distributed in the hope that it will be useful, |
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
# GNU Affero General Public License for more details. |
|
||||
# |
|
||||
# You should have received a copy of the GNU Affero General Public License |
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2004-2009 Tiny SPRL (<http://tiny.be>). |
||||
|
# © 2013 initOS GmbH & Co. KG (<http://www.initos.com>). |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
from openerp.osv import orm |
|
||||
|
from openerp import models, api |
||||
|
|
||||
|
|
||||
class ResPartner(orm.Model): |
|
||||
|
class ResPartner(models.Model): |
||||
"""Assigns 'ref' from a sequence on creation and copying""" |
"""Assigns 'ref' from a sequence on creation and copying""" |
||||
|
|
||||
_inherit = 'res.partner' |
_inherit = 'res.partner' |
||||
|
|
||||
def create(self, cr, uid, vals, context=None): |
|
||||
context = context or {} |
|
||||
if not vals.get('ref') and self._needsRef(cr, uid, vals=vals, |
|
||||
context=context): |
|
||||
vals['ref'] = self.pool.get('ir.sequence')\ |
|
||||
.next_by_code(cr, uid, 'res.partner') |
|
||||
return super(ResPartner, self).create(cr, uid, vals, context) |
|
||||
|
|
||||
def copy(self, cr, uid, id, default=None, context=None): |
|
||||
default = default or {} |
|
||||
if self._needsRef(cr, uid, id=id, context=context): |
|
||||
default['ref'] = self.pool.get('ir.sequence')\ |
|
||||
.next_by_code(cr, uid, 'res.partner', |
|
||||
context=context) |
|
||||
return super(ResPartner, self).copy(cr, uid, id, default, |
|
||||
context=context) |
|
||||
|
|
||||
def _needsRef(self, cr, uid, id=None, vals=None, context=None): |
|
||||
|
@api.model |
||||
|
def _needsRef(self, partner_id=None, vals=None): |
||||
""" |
""" |
||||
Checks whether a sequence value should be assigned to a partner's 'ref' |
Checks whether a sequence value should be assigned to a partner's 'ref' |
||||
|
|
||||
:param cr: database cursor |
|
||||
:param uid: current user id |
|
||||
:param id: id of the partner object |
|
||||
|
:param parnter_id: id of the partner object |
||||
:param vals: known field values of the partner object |
:param vals: known field values of the partner object |
||||
:return: true iff a sequence value should be assigned to the\ |
:return: true iff a sequence value should be assigned to the\ |
||||
partner's 'ref' |
partner's 'ref' |
||||
""" |
""" |
||||
if not vals and not id: |
|
||||
|
if not vals and not partner_id: |
||||
raise Exception('Either field values or an id must be provided.') |
raise Exception('Either field values or an id must be provided.') |
||||
|
vals = vals or {} |
||||
# only assign a 'ref' to commercial partners |
# only assign a 'ref' to commercial partners |
||||
if id: |
|
||||
vals = self.read(cr, uid, id, ['parent_id', 'is_company'], |
|
||||
context=context) |
|
||||
|
if partner_id: |
||||
|
partner = self.browse(partner_id) |
||||
|
vals.setdefault('is_company', partner.is_company) |
||||
|
vals.setdefault('parent_id', partner.parent_id.id) |
||||
return vals.get('is_company') or not vals.get('parent_id') |
return vals.get('is_company') or not vals.get('parent_id') |
||||
|
|
||||
def _commercial_fields(self, cr, uid, context=None): |
|
||||
|
@api.model |
||||
|
def _commercial_fields(self): |
||||
""" |
""" |
||||
Make the partner reference a field that is propagated |
Make the partner reference a field that is propagated |
||||
to the partner's contacts |
to the partner's contacts |
||||
""" |
""" |
||||
return super(ResPartner, self)._commercial_fields( |
|
||||
cr, uid, context=context) + ['ref'] |
|
||||
|
return super(ResPartner, self)._commercial_fields() + ['ref'] |
||||
|
|
||||
|
@api.model |
||||
|
def _get_next_ref(self, partner=None, vals=None): |
||||
|
return self.env['ir.sequence'].get('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) |
||||
|
return super(ResPartner, self).create(vals) |
||||
|
|
||||
|
@api.multi |
||||
|
def write(self, vals): |
||||
|
for partner in self: |
||||
|
ref = vals.get('ref') if 'ref' in vals else partner.ref |
||||
|
if not ref and self._needsRef(partner.id, vals): |
||||
|
vals['ref'] = self._get_next_ref(partner, vals) |
||||
|
super(ResPartner, partner).write(vals) |
||||
|
return True |
||||
|
|
||||
|
@api.one |
||||
|
def copy(self, default=None): |
||||
|
default = default or {} |
||||
|
if self._needsRef(self.id): |
||||
|
default.update({ |
||||
|
'ref': self._get_next_ref(), |
||||
|
}) |
||||
|
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
|
||||
|
return super(ResPartner, self).copy(default) |
@ -0,0 +1,2 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
from . import test_base_partner_sequence |
@ -0,0 +1,19 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2015 ACSONE SA/NV (<http://acsone.eu>). |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
import openerp.tests.common as common |
||||
|
|
||||
|
|
||||
|
class TestBasePartnerSequence(common.TransactionCase): |
||||
|
|
||||
|
def test_ref_sequence_on_partner(self): |
||||
|
res_partner = self.env['res.partner'] |
||||
|
partner = res_partner.create({ |
||||
|
'name': "test1", |
||||
|
'email': "test@test.com"}) |
||||
|
self.assertTrue(partner.ref, "A partner has always a ref.") |
||||
|
|
||||
|
copy = partner.copy() |
||||
|
self.assertTrue(copy.ref, "A partner with ref created by copy " |
||||
|
"has a ref by default.") |
Write
Preview
Loading…
Cancel
Save
Reference in new issue