Skip to content

Commit

Permalink
Merge be7d27b into d4c1348
Browse files Browse the repository at this point in the history
  • Loading branch information
yajo committed Oct 23, 2015
2 parents d4c1348 + be7d27b commit 221bf18
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 20 deletions.
30 changes: 10 additions & 20 deletions crm_lead_address_street3/model/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,21 @@
from openerp import models, fields, api


class crm_lead(models.Model):
class Lead(models.Model):
"""Add third field in lead address"""

_inherit = "crm.lead"

@api.v7
def _lead_create_contact(self, cr, uid, lead, name, is_company,
parent_id=False, context=None):
partner_obj = self.pool['res.partner']
partner = super(crm_lead, self)._lead_create_contact(
cr, uid, lead, name, is_company, parent_id=parent_id,
context=context)
partner_obj.write(cr, uid, [partner], {'street3': lead.street3},
context=context)
return partner

street3 = fields.Char('Street 3')

@api.v7
def on_change_partner_id(self, cr, uid, ids, partner_id, context=None):
res = super(crm_lead, self).on_change_partner_id(cr, uid, ids,
partner_id,
context=context)
@api.model
def _lead_create_contact(self, lead, name, is_company, parent_id=False):
return (super(Lead, self.with_context(default_street3=lead.street3))
._lead_create_contact(lead, name, is_company, parent_id))

@api.multi
def on_change_partner_id(self, partner_id):
res = super(Lead, self).on_change_partner_id(partner_id)
if partner_id:
partner = self.pool['res.partner'].browse(cr, uid, partner_id,
context=context)
partner = self.env['res.partner'].browse(partner_id)
res['value'].update({'street3': partner.street3})
return res
63 changes: 63 additions & 0 deletions crm_lead_vat/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.. 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

============
VAT in leads
============

This module was written to extend the functionality of CRM leads to support
setting the VAT.

Usage
=====

To use this module, you need to:

* Go to *Sales > Leads*.
* Open a lead.
* You will see the new field.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/111/8.0

Known issues / Roadmap
======================

* ...

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/ crm/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/ crm/issues/new?body=module:%20
crm_lead_vat%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.


Credits
=======

Contributors
------------

* Rafael Blasco <rafaelbn@antiun.com>
* Jairo Llopis <yajo.sk8@gmail.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.
5 changes: 5 additions & 0 deletions crm_lead_vat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingeniería, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
20 changes: 20 additions & 0 deletions crm_lead_vat/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingeniería, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "VAT in leads",
"summary": "Add VAT field to leads",
"version": "8.0.1.0.0",
"category": "Customer Relationship Management",
"website": "https://odoo-community.org/",
"author": "Antiun Ingeniería, S.L., Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"crm",
],
"data": [
"views/crm_lead.xml",
],
}
30 changes: 30 additions & 0 deletions crm_lead_vat/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingeniería, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import api, fields, models


class Lead(models.Model):
_inherit = "crm.lead"

vat = fields.Char(
"TIN",
help="Tax Identification Number. The first 2 characters are the "
"country code.")

@api.model
def _lead_create_contact(self, lead, name, is_company, parent_id=False):
"""Add VAT to partner."""
return (super(Lead, self.with_context(default_vat=lead.vat))
._lead_create_contact(lead, name, is_company, parent_id))

def on_change_partner_id(self, partner_id):
"""Recover VAT from partner if available."""
result = super(Lead, self).on_change_partner_id(partner_id)

if result.get("value"):
if self.partner_id and self.partner_id.vat:
result["value"]["vat"] = self.partner_id.vat

return result
Binary file added crm_lead_vat/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions crm_lead_vat/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingeniería, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import test_lead
29 changes: 29 additions & 0 deletions crm_lead_vat/tests/test_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingeniería, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.tests.common import TransactionCase


class LeadCase(TransactionCase):
def setUp(self):
super(LeadCase, self).setUp()
self.lead = self.env["crm.lead"].create({
"name": __file__,
"partner_name": u"HÎ"
})
self.partner = self.env["res.partner"].create({"name": __file__})
self.test_field = "ES98765432M"

def test_transfered_values(self):
"""Field gets transfered when creating partner."""
self.lead.vat = self.test_field
self.lead.handle_partner_assignation()
self.assertEqual(self.lead.partner_id.vat, self.test_field)

def test_onchange_partner_id(self):
"""Lead gets VAT from partner when linked to it."""
self.partner.vat = self.test_field
self.lead.partner_id = self.partner
result = self.lead.on_change_partner_id(self.partner.id)
self.assertEqual(result["value"]["vat"], self.test_field)
19 changes: 19 additions & 0 deletions crm_lead_vat/views/crm_lead.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record model="ir.ui.view" id="form_view">
<field name="name">Add VAT to lead</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='partner_id']" position="after">
<field name="vat"/>
</xpath>
</data>
</field>
</record>

</data>
</openerp>

0 comments on commit 221bf18

Please sign in to comment.