Skip to content

Commit

Permalink
Merge d0daf2e into 17be632
Browse files Browse the repository at this point in the history
  • Loading branch information
yajo committed Oct 6, 2015
2 parents 17be632 + d0daf2e commit 549229d
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 0 deletions.
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",
],
}
34 changes: 34 additions & 0 deletions crm_lead_vat/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- 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.one
def _map_values_to_partner(self, *args, **kwargs):
"""Add VAT to mapped values."""
result = super(Lead, self)._map_values_to_partner(*args, **kwargs)[0]
result["vat"] = self.vat
return result

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

if result.get("value"):
partner = self.pool.get("res.partner").browse(
cr, uid, partner_id, context=context)
if partner.vat:
result["value"]["vat"] = partner.vat

return result
Binary file added crm_lead_vat/static/description/icon.png
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
26 changes: 26 additions & 0 deletions crm_lead_vat/tests/test_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- 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__})
self.partner = self.env["res.partner"].create({"name": __file__})
self.test_vat = "ES98765432M"

def test_mapped_values(self):
"""VAT gets mapped when creating partner."""
self.lead.vat = self.test_vat
mapped = self.lead._map_values_to_partner(self.lead.name, False)[0]
self.assertEqual(mapped["vat"], self.test_vat)

def test_onchange_partner_id(self):
"""Lead gets VAT from partner when linked to it."""
self.partner.vat = self.test_vat
self.lead.partner_id = self.partner
result = self.lead.on_change_partner_id(self.partner.id)
self.assertEqual(result["value"]["vat"], self.test_vat)
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 549229d

Please sign in to comment.