Browse Source

[MIG] base_partner_sequence: Migration to 10.0

14.0
Akim Juillerat 8 years ago
committed by mostafaala2
parent
commit
f3b915cf41
  1. 32
      base_partner_sequence/README.rst
  2. 9
      base_partner_sequence/__manifest__.py
  3. 2
      base_partner_sequence/data/partner_sequence.xml
  4. 111
      base_partner_sequence/models/partner.py

32
base_partner_sequence/README.rst

@ -1,10 +1,10 @@
.. 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
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
======================================
Add a sequence on partner's reference.
======================================
=====================
Base Partner Sequence
=====================
This module adds the possibility to define a sequence for
the partner's reference. This reference is then set as default
@ -18,13 +18,24 @@ but it can only be modified from the commercial partner.
No references are assigned for contacts such as shipping and
invoice addresses.
Installation
============
There are no special instructions regarding installation.
Configuration
=============
No configuration is needed.
Usage
=====
To use this module, you need to:
.. 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
Bug Tracker
@ -38,6 +49,11 @@ help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
@ -49,6 +65,8 @@ Contributors
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* Akim Juillerat <akim.juillerat@camptocamp.com>
Maintainer
----------
@ -63,4 +81,4 @@ 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.
To contribute to this module, please visit https://odoo-community.org.

9
base_partner_sequence/__openerp__.py → base_partner_sequence/__manifest__.py

@ -2,15 +2,16 @@
# Copyright 2004-2009 Tiny SPRL (<http://tiny.be>).
# Copyright 2013 initOS GmbH & Co. KG (<http://www.initos.com>).
# Copyright 2016 Tecnativa - Vicent Cubells
# Copyright 2016 Camptocamp - Akim Juillerat (<http://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Add a sequence on customers' code",
"version": "9.0.0.1.0",
"author": "Tiny/initOS GmbH & Co. KG,"
"ACSONE SA/NV,"
"Tecnativa, "
"Odoo Community Association (OCA)",
"Odoo Community Association (OCA), "
"Camptocamp, ",
"name": "Add a sequence on customers' code",
"version": "10.0.1.0.0",
"category": "Generic Modules/Base",
"website": "http://www.initos.com",
"depends": [

2
base_partner_sequence/data/partner_sequence.xml

@ -1,11 +1,9 @@
<?xml version="1.0"?>
<odoo noupdate="1">
<record model="ir.sequence" id="seq_res_partner">
<field name="name">Partner code</field>
<field name="code">res.partner</field>
<field name="prefix">P/</field>
<field name="padding">5</field>
</record>
</odoo>

111
base_partner_sequence/models/partner.py

@ -1,10 +1,28 @@
# -*- coding: utf-8 -*-
# Copyright 2004-2009 Tiny SPRL (<http://tiny.be>).
# Copyright 2013 initOS GmbH & Co. KG (<http://www.initos.com>).
# Copyright 2016 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
##############################################################################
#
# 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>
# Copyright (C) 2016 Camptocamp SA (<http://www.camptocamp.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/>.
#
##############################################################################
from openerp import models, api, exceptions, _
from odoo import api, models, exceptions, _
class ResPartner(models.Model):
@ -13,28 +31,49 @@ class ResPartner(models.Model):
_inherit = 'res.partner'
@api.model
def _needsRef(self, partner_id=None, vals=None):
def create(self, vals):
if not vals.get('ref') and self._needsRef(vals=vals):
vals['ref'] = self.env['ir.sequence'].next_by_code('res.partner')
return super(ResPartner, self).create(vals)
@api.multi
def copy(self, default=None):
default = default or {}
if self._needsRef():
default['ref'] = self.env['ir.sequence'].\
next_by_code('res.partner')
return super(ResPartner, self).copy(default)
@api.multi
def write(self, vals):
for partner in self:
if not vals.get('ref') and partner._needsRef(vals):
vals['ref'] = self.env['ir.sequence'].\
next_by_code('res.partner')
super(ResPartner, partner).write(vals)
return True
@api.multi
def _needsRef(self, vals=None):
"""
Checks whether a sequence value should be assigned to a partner's 'ref'
:param partner_id: id of the partner object
:param cr: database cursor
:param uid: current user id
:param id: id of the partner object
:param vals: known field values of the partner object
:return: true if a sequence value should be assigned to the
partner's 'ref'
:return: true iff a sequence value should be assigned to the\
partner's 'ref'
"""
if not vals and not partner_id:
raise exceptions.Warning(
_('Either field values or an id must be provided.')
)
if vals is None:
vals = {}
values = vals.copy()
if not vals and not self: # pragma: no cover
raise exceptions.UserError(_(
'Either field values or an id must be provided.'))
# only assign a 'ref' to commercial partners
if partner_id:
partner = self.browse(partner_id)
values.setdefault('is_company', partner.is_company)
values.setdefault('parent_id', partner.parent_id.id)
return values.get('is_company') or not values.get('parent_id')
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')
@api.model
def _commercial_fields(self):
@ -43,33 +82,3 @@ class ResPartner(models.Model):
to the partner's contacts
"""
return super(ResPartner, self)._commercial_fields() + ['ref']
@api.model
def _get_next_ref(self, partner=None, vals=None):
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)
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.multi
def copy(self, default=None):
for partner in self:
default = default or {}
if self._needsRef(self.id):
default.update({
'ref': self._get_next_ref(),
})
return super(ResPartner, self).copy(default)
Loading…
Cancel
Save