Skip to content

Commit

Permalink
[IMP] hr_expense_event_commute: pre-commit stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
oihane committed Jun 27, 2024
1 parent 3d08fdc commit 1c75dd7
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 68 deletions.
26 changes: 13 additions & 13 deletions hr_expense_event_commute/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Copyright 2021 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': "Hr Expense Event Commute",
'version': '14.0.1.0.0',
'author': 'AvanzOSC',
'website': 'http://www.avanzosc.es',
'category': 'Marketing/Events',
'license': 'AGPL-3',
'depends': [
'hr_expense_from_analytic',
'event_commute',
"name": "Hr Expense Event Commute",
"version": "14.0.1.0.0",
"author": "AvanzOSC",
"website": "https://github.com/avanzosc/hr-addons",
"category": "Marketing/Events",
"license": "AGPL-3",
"depends": [
"hr_expense_from_analytic",
"event_commute",
],
'data': [
'views/event_view.xml'
"data": [
"views/event_view.xml",
],
'installable': True,
'auto_install': True,
"installable": True,
"auto_install": True,
}
20 changes: 8 additions & 12 deletions hr_expense_event_commute/models/account_analytic_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@


class AccountAnalyticLine(models.Model):
_inherit = 'account.analytic.line'
_inherit = "account.analytic.line"

def create_condition_to_search_hr_expense(self):
cond, employee = super(
AccountAnalyticLine, self).create_condition_to_search_hr_expense()
if ('default_track_id' in self.env.context and
self.env.context.get('default_track_id', False)):
cond.append(('track_id', '=',
self.env.context.get('default_track_id').id))
AccountAnalyticLine, self
).create_condition_to_search_hr_expense()
if self.env.context.get("default_track_id", False):
cond.append(("track_id", "=", self.env.context.get("default_track_id").id))
return cond, employee

def catch_values_for_create_expense(self):
vals = super(
AccountAnalyticLine,
self).catch_values_for_create_expense()
if ('default_track_id' in self.env.context and
self.env.context.get('default_track_id', False)):
vals['track_id'] = self.env.context.get('default_track_id').id
vals = super(AccountAnalyticLine, self).catch_values_for_create_expense()
if self.env.context.get("default_track_id", False):
vals["track_id"] = self.env.context.get("default_track_id").id
return vals
9 changes: 6 additions & 3 deletions hr_expense_event_commute/models/event_track.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Copyright 2021 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models, fields
from odoo import fields, models


class EventTrack(models.Model):
_inherit = 'event.track'
_inherit = "event.track"

hr_expense_ids = fields.One2many(
string='Expenses', comodel_name='hr.expense', inverse_name='track_id')
string="Expenses",
comodel_name="hr.expense",
inverse_name="track_id",
)
8 changes: 5 additions & 3 deletions hr_expense_event_commute/models/hr_expense.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright 2021 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models, fields
from odoo import fields, models


class HrExpense(models.Model):
_inherit = 'hr.expense'
_inherit = "hr.expense"

track_id = fields.Many2one(
string='Event track', comodel_name='event.track')
string="Event track",
comodel_name="event.track",
)
84 changes: 50 additions & 34 deletions hr_expense_event_commute/tests/test_hr_expense_event_commute.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,64 @@
# Copyright 2021 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import common, tagged
from odoo import fields
from odoo.tests import common, tagged


@tagged("post_install", "-at_install")
class TestHrExpenseEventCommute(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestHrExpenseEventCommute, cls).setUpClass()
cls.uom_unit = cls.env.ref('uom.product_uom_unit')
cls.product = cls.env['product.product'].create({
'name': 'Product Hr Expense Event With Commute',
'default_code': 'PHEEWC',
'uom_id': cls.uom_unit.id,
'uom_po_id': cls.uom_unit.id,
'type': 'service',
'can_be_expensed': True})
vals = {'name': 'User Hr Expense Event With Commute',
'login': '[email protected]'}
cls.user = cls.env['res.users'].create(vals)
vals = {'name': 'Employee Hr Expense Event With Commute',
'user_id': cls.user.id}
cls.employee = cls.env['hr.employee'].create(vals)
cls.analytic_account = cls.env['account.analytic.account'].create({
'name': 'Analytic Hr Expense Event With Commute',
'partner_id': cls.user.partner_id.id})
cls.track = cls.env['event.track'].search([], limit=1)
cls.uom_unit = cls.env.ref("uom.product_uom_unit")
cls.product = cls.env["product.product"].create(
{
"name": "Product Hr Expense Event With Commute",
"default_code": "PHEEWC",
"uom_id": cls.uom_unit.id,
"uom_po_id": cls.uom_unit.id,
"type": "service",
"can_be_expensed": True,
}
)
vals = {
"name": "User Hr Expense Event With Commute",
"login": "[email protected]",
}
cls.user = cls.env["res.users"].create(vals)
vals = {
"name": "Employee Hr Expense Event With Commute",
"user_id": cls.user.id,
}
cls.employee = cls.env["hr.employee"].create(vals)
cls.analytic_account = cls.env["account.analytic.account"].create(
{
"name": "Analytic Hr Expense Event With Commute",
"partner_id": cls.user.partner_id.id,
}
)
cls.track = cls.env["event.track"].search([], limit=1)

def test_hr_expense_event_commute(self):
vals = {
'account_id': self.analytic_account.id,
'name': 'Analitic Line Sale Expense From Analytic',
'date': fields.Date.today(),
'amount': 222,
'partner_id': self.user.partner_id.id,
'product_id': self.product.id}
analytic_line = self.env['account.analytic.line'].with_context(
default_track_id=self.track).create(vals)
cond = [('name', '=', analytic_line.name),
('date', '=', analytic_line.date),
('quantity', '=', 1),
('product_id', '=', self.product.id),
('employee_id', '=', self.employee.id),
('track_id', '=', self.track.id)]
hr_expense = self.env['hr.expense'].search(cond, limit=1)
"account_id": self.analytic_account.id,
"name": "Analitic Line Sale Expense From Analytic",
"date": fields.Date.today(),
"amount": 222,
"partner_id": self.user.partner_id.id,
"product_id": self.product.id,
}
analytic_line = (
self.env["account.analytic.line"]
.with_context(default_track_id=self.track)
.create(vals)
)
cond = [
("name", "=", analytic_line.name),
("date", "=", analytic_line.date),
("quantity", "=", 1),
("product_id", "=", self.product.id),
("employee_id", "=", self.employee.id),
("track_id", "=", self.track.id),
]
hr_expense = self.env["hr.expense"].search(cond, limit=1)
self.assertEqual(len(hr_expense), 1)
5 changes: 2 additions & 3 deletions hr_expense_event_commute/views/event_view.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_event_form" model="ir.ui.view">
<field name="model">event.event</field>
<field name="inherit_id" ref="event_commute.view_event_form"/>
<field name="inherit_id" ref="event_commute.view_event_form" />
<field name="arch" type="xml">
<page name="displacement_products" position="attributes">
<attribute name="string">Displacement products And Expenses</attribute>
Expand Down

0 comments on commit 1c75dd7

Please sign in to comment.