Skip to content

Commit

Permalink
[MIG] partner_prospect: Migration to 11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
oihane committed Oct 26, 2017
1 parent f205d60 commit 0cc44a6
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 105 deletions.
4 changes: 2 additions & 2 deletions partner_prospect/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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/167/8.0
:target: https://runbot.odoo-community.org/runbot/167/11.0

For further information, please visit:

Expand All @@ -28,7 +28,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20partner_prospect%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`here <https://github.com/OCA/sale-workflow/issues/new?body=module:%20partner_prospect%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.


Credits
Expand Down
5 changes: 3 additions & 2 deletions partner_prospect/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

{
"name": "Partner Prospect",
"version": "8.0.1.0.0",
"version": "11.0.1.0.0",
"license": "AGPL-3",
"author": "AvanzOSC, "
"Serv. Tecnol. Avanzados - Pedro M. Baeza,"
"Odoo Community Association (OCA)",
Expand All @@ -36,5 +37,5 @@
"data": [
"views/res_partner_view.xml",
],
'installable': False
"installable": True,
}
43 changes: 0 additions & 43 deletions partner_prospect/i18n/partner_prospect.pot

This file was deleted.

31 changes: 22 additions & 9 deletions partner_prospect/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,38 @@
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################

from openerp import models, fields, api
from openerp import api, fields, models


class ResPartner(models.Model):
_inherit = 'res.partner'

@api.one
@api.multi
@api.depends('commercial_partner_id',
'commercial_partner_id.sale_order_ids',
'commercial_partner_id.sale_order_ids.state',
'commercial_partner_id.child_ids',
'commercial_partner_id.child_ids.sale_order_ids',
'commercial_partner_id.child_ids.sale_order_ids.state')
'commercial_partner_id.child_ids.sale_order_ids.state',
'commercial_partner_id.invoice_ids',
'commercial_partner_id.child_ids.invoice_ids')
def _compute_prospect(self):
sale_ids = (
self.commercial_partner_id.sale_order_ids +
self.commercial_partner_id.mapped('child_ids.sale_order_ids'))
self.prospect = not sale_ids.filtered(
lambda r: r.state not in ('draft', 'sent', 'cancel'))
for partner in self:
sale_ids = (
partner.commercial_partner_id.sale_order_ids +
partner.commercial_partner_id.mapped(
'child_ids.sale_order_ids'))
invoice_ids = (
partner.commercial_partner_id.invoice_ids +
partner.commercial_partner_id.mapped(
'child_ids.invoice_ids'))
partner.prospect = (
not sale_ids.filtered(
lambda r: r.state not in
('draft', 'sent', 'cancel')) and
not invoice_ids.filtered(
lambda r: r.type in ('out_invoice', 'out_refund')))

prospect = fields.Boolean(
string='Prospect', compute='_compute_prospect', store=True)
string='Prospect', compute='_compute_prospect', default=False,
store=True)
38 changes: 30 additions & 8 deletions partner_prospect/tests/test_partner_prospect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ def setUp(self):
super(TestPartnerProspect, self).setUp()
self.sale_order_model = self.env['sale.order']
self.partner_model = self.env['res.partner']
self.partner1 = self.partner_model.create({'name': 'Partner1'})
self.invoice_model = self.env['account.invoice']
self.partner1 = self.partner_model.create({
'name': 'Partner1',
})
self.partner2 = self.partner_model.create({
'name': 'Partner2',
'parent_id': self.partner1.id,
Expand All @@ -21,39 +24,58 @@ def setUp(self):
'name': 'Partner3',
'parent_id': self.partner1.id,
})
self.partner4 = self.partner_model.create({'name': 'Partner4'})
self.partner4 = self.partner_model.create({
'name': 'Partner4',
})
self.product = self.env.ref('product.product_product_4')
self.sale_order1 = self.sale_order_model.create({
'partner_id': self.partner1.id,
'order_policy': 'manual',
'order_line': [(0, 0, {'product_id': self.product.id, })],
})
self.sale_order2 = self.sale_order_model.create({
'partner_id': self.partner2.id,
'order_policy': 'manual',
'order_line': [(0, 0, {'product_id': self.product.id, })],
})
self.sale_order3 = self.sale_order_model.create({
'partner_id': self.partner4.id,
'order_policy': 'manual',
'order_line': [(0, 0, {'product_id': self.product.id, })],
})

def test_partner_child_check(self):
self.sale_order2.action_button_confirm()
self.sale_order2.action_confirm()
self.assertFalse(self.partner1.prospect, 'Partner1 is a prospect')
self.assertFalse(self.partner2.prospect, 'Partner2 is a prospect')
self.assertFalse(self.partner3.prospect, 'Partner3 is a prospect')

def test_partner_parent_check(self):
self.sale_order1.action_button_confirm()
self.sale_order1.action_confirm()
self.assertFalse(self.partner1.prospect, 'Partner1 is a prospect')
self.assertFalse(self.partner2.prospect, 'Partner2 is a prospect')
self.assertFalse(self.partner3.prospect, 'Partner3 is a prospect')

def test_partner_prospect(self):
self.assertTrue(self.partner4.prospect, 'Partner4 is not a prospect')
self.sale_order3.action_button_confirm()
self.sale_order3.action_confirm()
self.assertFalse(self.partner4.prospect, 'Partner4 is a prospect')
self.sale_order3.action_cancel()
self.assertTrue(self.partner4.prospect, 'Partner4 is not a prospect')

def test_partner_child_check_invoice(self):
type = 'out_invoice'
self.invoice_model.create({
'partner_id': self.partner2.id,
'type': type,
})._onchange_partner_id()
self.assertFalse(self.partner1.prospect, 'Partner1 is a prospect')
self.assertFalse(self.partner2.prospect, 'Partner2 is a prospect')
self.assertFalse(self.partner3.prospect, 'Partner3 is a prospect')

def test_partner_parent_check_invoice(self):
type = 'out_refund'
self.invoice_model.create({
'partner_id': self.partner1.id,
'type': type,
})._onchange_partner_id()
self.assertFalse(self.partner1.prospect, 'Partner1 is a prospect')
self.assertFalse(self.partner2.prospect, 'Partner2 is a prospect')
self.assertFalse(self.partner3.prospect, 'Partner3 is a prospect')
86 changes: 45 additions & 41 deletions partner_prospect/views/res_partner_view.xml
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="res_partner_prospect_form_view" model="ir.ui.view">
<field name="name">res.partner.prospect.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<label for="street" position="before">
<field name="prospect" />
</label>
</field>
</record>
<odoo>
<data>
<record id="res_partner_prospect_form_view" model="ir.ui.view">
<field name="name">res.partner.prospect.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<label for="street" position="before">
<field name="prospect" />
</label>
</field>
</record>

<record id="res_partner_prospect_tree_view" model="ir.ui.view">
<field name="name">res.partner.prospect.tree</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree" />
<field name="arch" type="xml">
<field name="email" position="after">
<field name="prospect" />
</field>
<record id="res_partner_prospect_tree_view" model="ir.ui.view">
<field name="name">res.partner.prospect.tree</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree" />
<field name="arch" type="xml">
<field name="email" position="after">
<field name="prospect" />
</field>
</record>
</field>
</record>

<record id="res_partner_prospect_search_view" model="ir.ui.view">
<field name="name">res.partner.prospect.search</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter" />
<field name="arch" type="xml">
<filter string="Suppliers" position="after">
<separator/>
<filter string="Actual Customer" name="noprospect" domain="[('prospect','=',False)]"/>
<filter string="Prospect" name="prospect" domain="[('prospect','=',True)]"/>
</filter>
<group string="Group By" position="inside">
<filter string="Prospect" domain="[]" context="{'group_by':'prospect'}"/>
</group>
</field>
</record>
<record id="res_partner_prospect_search_view" model="ir.ui.view">
<field name="name">res.partner.prospect.search</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter" />
<field name="arch" type="xml">
<filter name="supplier" position="after">
<separator/>
<filter string="Actual Customer" name="noprospect" domain="[('prospect','=',False)]"/>
<filter string="Prospect" name="prospect" domain="[('prospect','=',True)]"/>
</filter>
<group name="group_by" position="inside">
<filter string="Prospect" domain="[]" context="{'group_by':'prospect'}"/>
</group>
</field>
</record>

<record id="base.action_partner_form" model="ir.actions.act_window">
<field name="context">{"search_default_customer": 1, "search_default_noprospect": 1}</field>
</record>

<record id="base.action_partner_form" model="ir.actions.act_window">
<field name="context">{"search_default_customer": 1, "search_default_noprospect": 1}</field>
</record>
</data>
</openerp>
<record id="base.action_partner_customer_form" model="ir.actions.act_window">
<field name="context">{'default_customer':1, 'search_default_customer':1, 'search_default_noprospect': 1, 'default_company_type': 'company','default_is_company': 1}</field>
</record>
</data>
</odoo>

0 comments on commit 0cc44a6

Please sign in to comment.