Skip to content

Commit

Permalink
[ADD] fieldservice_expense
Browse files Browse the repository at this point in the history
  • Loading branch information
EdgarRetes committed Dec 6, 2024
1 parent 69e8c44 commit bae75e8
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 0 deletions.
35 changes: 35 additions & 0 deletions fieldservice_expense/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
**This file is going to be generated by oca-gen-addon-readme.**

*Manual changes will be overwritten.*

Please provide content in the ``readme`` directory:

* **DESCRIPTION.rst** (required)
* INSTALL.rst (optional)
* CONFIGURE.rst (optional)
* **USAGE.rst** (optional, highly recommended)
* DEVELOP.rst (optional)
* ROADMAP.rst (optional)
* HISTORY.rst (optional, recommended)
* **CONTRIBUTORS.rst** (optional, highly recommended)
* CREDITS.rst (optional)

Content of this README will also be drawn from the addon manifest,
from keys such as name, authors, maintainers, development_status,
and license.

A good, one sentence summary in the manifest is also highly recommended.


Automatic changelog generation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`HISTORY.rst` can be auto generated using `towncrier <https://pypi.org/project/towncrier>`_.

Just put towncrier compatible changelog fragments into `readme/newsfragments`
and the changelog file will be automatically generated and updated when a new fragment is added.

Please refer to `towncrier` documentation to know more.

NOTE: the changelog will be automatically generated when using `/ocabot merge $option`.
If you need to run it manually, refer to `OCA/maintainer-tools README <https://github.com/OCA/maintainer-tools>`_.
1 change: 1 addition & 0 deletions fieldservice_expense/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions fieldservice_expense/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) 2018 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Field Service - Expenses",
"summary": "Manage expenses of orders",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"category": "TMS",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/field-service",
"depends": ["fieldservice", "hr_expense"],
"data": [
"views/hr_expense_views.xml",
"views/fsm_order_views.xml",
],
"demo": [],
"development_status": "Alpha",
"maintainers": ["max3903", "EdgarRetes"],
}
2 changes: 2 additions & 0 deletions fieldservice_expense/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import hr_expense
from . import fsm_order
31 changes: 31 additions & 0 deletions fieldservice_expense/models/fsm_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (C) 2024 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models


class FSMOrder(models.Model):
_inherit = "fsm.order"

expense_ids = fields.One2many(
"hr.expense",
"fsm_order_id",
)

expense_count = fields.Integer(compute="_compute_expenses")

@api.depends("expense_ids")
def _compute_expenses(self):
for record in self:
record.expense_count = len(record.expense_ids)

Check warning on line 20 in fieldservice_expense/models/fsm_order.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_expense/models/fsm_order.py#L20

Added line #L20 was not covered by tests

def action_view_expenses(self):
self.ensure_one()
return {

Check warning on line 24 in fieldservice_expense/models/fsm_order.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_expense/models/fsm_order.py#L23-L24

Added lines #L23 - L24 were not covered by tests
"type": "ir.actions.act_window",
"res_model": "hr.expense",
"view_mode": "list,form",
"domain": [("fsm_order_id", "=", self.id)],
"context": {"default_fsm_order_id": self.id},
"name": _("Expenses for FSM Order %s") % self.name,
}
21 changes: 21 additions & 0 deletions fieldservice_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2024 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, fields, models


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

fsm_order_id = fields.Many2one("fsm.order")

def action_view_order(self):
self.ensure_one()
return {

Check warning on line 14 in fieldservice_expense/models/hr_expense.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_expense/models/hr_expense.py#L13-L14

Added lines #L13 - L14 were not covered by tests
"type": "ir.actions.act_window",
"res_model": "fsm.order",
"view_mode": "form",
"res_id": self.fsm_order_id.id,
"target": "current",
"name": _("Order: %s") % self.fsm_order_id.name,
}
3 changes: 3 additions & 0 deletions fieldservice_expense/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
4 changes: 4 additions & 0 deletions fieldservice_expense/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Create expenses in orders
1. Go to FSM module.
2. Select or create a new order.
3. In the Expense page, create a new expense.
25 changes: 25 additions & 0 deletions fieldservice_expense/views/fsm_order_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<odoo>
<record id="fsm_order_inherit_view_form" model="ir.ui.view">
<field name="name">fsm.order.inherit.view.form</field>
<field name="model">fsm.order</field>
<field name="inherit_id" ref="fieldservice.fsm_order_form" />
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button
name="action_view_expenses"
type="object"
class="oe_stat_button"
icon="fa-money"
invisible="not expense_ids"
>
<field string="Expenses" name="expense_count" widget="statinfo" />
</button>
</xpath>
<xpath expr="//page[@name='execution_page']" position="before">
<page string="Expenses">
<field name="expense_ids" />
</page>
</xpath>
</field>
</record>
</odoo>
47 changes: 47 additions & 0 deletions fieldservice_expense/views/hr_expense_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<odoo>
<record id="fsm_hr_expense_inherit_view_form" model="ir.ui.view">
<field name="name">fsm.hr.expense.inherit.view.form</field>
<field name="model">hr.expense</field>
<field name="inherit_id" ref="hr_expense.hr_expense_view_form" />
<field name="arch" type="xml">
<xpath expr="//sheet" position="inside">
<div class="oe_button_box" name="button_box">
<button
name="action_view_order"
type="object"
class="oe_stat_button"
icon="fa-code-fork"
invisible="not fsm_order_id"
>
<span class="o_stat_text">FSM Order</span>
</button>
</div>
</xpath>
<xpath expr="//sheet" position="inside">
<notebook>
<page string="FSM Order">
<group>
<field name="fsm_order_id" string="Order" />
</group>
</page>
</notebook>
</xpath>
</field>
</record>

<record id="hr_expense_inherit_view_search" model="ir.ui.view">
<field name="name">hr.expense.inherit.view.search</field>
<field name="model">hr.expense</field>
<field name="inherit_id" ref="hr_expense.hr_expense_view_search" />
<field name="arch" type="xml">
<xpath expr="//filter[@name='activities_upcoming_all']" position="after">
<separator />
<filter
string="Order"
name="order"
domain="[('fsm_order_id', '!=', False)]"
/>
</xpath>
</field>
</record>
</odoo>

0 comments on commit bae75e8

Please sign in to comment.