Skip to content

Commit

Permalink
[IMP] resource_booking: Button (partner -> booking)
Browse files Browse the repository at this point in the history
  • Loading branch information
norlinhenrik committed Aug 30, 2023
1 parent c480d0f commit c3a89da
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions resource_booking/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"security/ir.model.access.csv",
"templates/portal.xml",
"views/calendar_event_views.xml",
"views/res_partner_views.xml",
"views/resource_booking_combination_views.xml",
"views/resource_booking_type_views.xml",
"views/resource_booking_views.xml",
Expand Down
1 change: 1 addition & 0 deletions resource_booking/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import calendar_event
from . import res_partner
from . import resource_booking
from . import resource_booking_combination
from . import resource_booking_type
Expand Down
26 changes: 26 additions & 0 deletions resource_booking/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from odoo import fields, models


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

resource_booking_count = fields.Integer(
compute="_compute_resource_booking_count", string="Resource Booking Count"
)
resource_booking_ids = fields.One2many(
"resource.booking", "partner_id", string="Bookings"
)

def _compute_resource_booking_count(self):
for p in self:
p.resource_booking_count = len(p.resource_booking_ids)

def action_view_resource_booking(self):
self.ensure_one()
action = self.env["ir.actions.actions"]._for_xml_id(
"resource_booking.resource_booking_action"
)
action["context"] = {
"default_partner_id": self.id,
}
return action
25 changes: 25 additions & 0 deletions resource_booking/views/res_partner_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_partner_form" model="ir.ui.view">
<field name="model">res.partner</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
class="oe_stat_button"
type="object"
name="action_view_resource_booking"
groups="resource_booking.group_user"
icon="fa-calendar"
>
<field
string="Bookings"
name="resource_booking_count"
widget="statinfo"
/>
</button>
</div>
</field>
</record>
</odoo>

0 comments on commit c3a89da

Please sign in to comment.