Initial commit of hr_expense_lead for 11.0

This commit is contained in:
Jared Kipe
2018-05-16 10:08:45 -07:00
parent 85ebbe80d0
commit a6da310548
9 changed files with 104 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,21 @@
{
'name': 'HR Expense Lead',
'version': '11.0.1.0.0',
'author': 'Hibou Corp. <hello@hibou.io>',
'category': 'Human Resources',
'summary': 'Assign Opportunity/Lead to expenses for reporting.',
'description': """
Assign Opportunity/Lead to expenses for reporting.
""",
'website': 'https://hibou.io/',
'depends': [
'hr_expense',
'crm',
],
'data': [
'views/hr_expense_views.xml',
'views/crm_views.xml'
],
'installable': True,
'auto_install': False,
}

View File

@@ -0,0 +1,2 @@
from . import crm_lead
from . import hr_expense_lead

View File

@@ -0,0 +1,14 @@
from odoo import api, fields, models
class CRMLead(models.Model):
_inherit = 'crm.lead'
expense_total_amount = fields.Float(string='Expenses Total', compute='_compute_expense_total_amount')
expense_ids = fields.One2many('hr.expense', 'lead_id', string='Expenses')
@api.multi
@api.depends('expense_ids.unit_amount')
def _compute_expense_total_amount(self):
for lead in self.sudo():
lead.expense_total_amount = sum(lead.expense_ids.mapped('total_amount'))

View File

@@ -0,0 +1,7 @@
from odoo import api, fields, models
class HRExpenseLead(models.Model):
_inherit = 'hr.expense'
lead_id = fields.Many2one('crm.lead', string='Lead')

View File

@@ -0,0 +1 @@
from . import test_expenses

View File

@@ -0,0 +1,16 @@
from odoo.tests import common
class TestCheckVendor(common.TransactionCase):
def test_fields(self):
lead = self.env['crm.lead'].create({'name': 'Test Lead'})
expense = self.env['hr.expense'].create({
'name': 'Test Expense',
'product_id': self.env['product.product'].search([('can_be_expensed', '=', True)], limit=1).id,
'unit_amount': 34.0,
})
self.assertFalse(lead.expense_ids)
self.assertEqual(lead.expense_total_amount, 0.0)
expense.lead_id = lead
self.assertTrue(lead.expense_ids)
self.assertEqual(lead.expense_total_amount, 34.0)

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="crm_lead_form_opportunity_inherit" model="ir.ui.view">
<field name="name">crm.lead.form.opportunity.inherit</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
<field name="arch" type="xml">
<xpath expr="//sheet/div[@name='button_box']" position="inside">
<button name="%(hr_expense.hr_expense_actions_all)d" class="oe_stat_button" icon="fa-money" type="action" context="{'search_default_lead_id': active_id}">
<div class="o_stat_info">
<field name="expense_total_amount" widget="statinfo" nolabel="1"/>
<span class="o_stat_text"> Expenses</span>
</div>
</button>
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_hr_expense_form_inherit" model="ir.ui.view">
<field name="name">hr.expense.form.inherit</field>
<field name="model">hr.expense</field>
<field name="inherit_id" ref="hr_expense.hr_expense_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='sheet_id']" position="after">
<field name="lead_id"/>
</xpath>
</field>
</record>
<record id="view_hr_expense_filter_inherit" model="ir.ui.view">
<field name="name">hr.expense.filter.inherit</field>
<field name="model">hr.expense</field>
<field name="inherit_id" ref="hr_expense.view_hr_expense_filter"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='product_id']" position="after">
<field name="lead_id"/>
</xpath>
</field>
</record>
</odoo>