From 65d7286fb95f3fa1c0188412284d1f47f1808282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Sun, 7 Mar 2021 09:39:52 +0100 Subject: [PATCH] [ADD] Wizard change group prices --- pms/__manifest__.py | 1 + pms/models/pms_folio.py | 7 ++ pms/models/pms_reservation.py | 26 +++++- pms/security/ir.model.access.csv | 1 + pms/views/pms_folio_views.xml | 9 ++ pms/wizards/__init__.py | 1 + pms/wizards/wizard_folio_changes.py | 115 ++++++++++++++++++++++++ pms/wizards/wizard_folio_changes.xml | 128 +++++++++++++++++++++++++++ 8 files changed, 285 insertions(+), 3 deletions(-) create mode 100644 pms/wizards/wizard_folio_changes.py create mode 100644 pms/wizards/wizard_folio_changes.xml diff --git a/pms/__manifest__.py b/pms/__manifest__.py index 5147c917d..623b9a827 100644 --- a/pms/__manifest__.py +++ b/pms/__manifest__.py @@ -72,6 +72,7 @@ "wizards/wizard_advanced_filters.xml", "wizards/wizard_folio.xml", "wizards/wizard_invoice_filter_days.xml", + "wizards/wizard_folio_changes.xml", ], "demo": [ "demo/pms_master_data.xml", diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index 4097a4b14..c1578b37d 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -759,6 +759,13 @@ class PmsFolio(models.Model): action = {"type": "ir.actions.act_window_close"} return action + def folio_multi_changes(self): + self.ensure_one() + reservation_ids = self.reservation_ids.ids + action = self.env.ref("pms.action_folio_changes").sudo().read()[0] + action["context"] = ({"default_reservation_ids": [(6, 0, reservation_ids)]},) + return action + # def action_return_payments(self): # self.ensure_one() # return_move_ids = [] diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index fb61d5f65..835437dfd 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -69,6 +69,7 @@ class PmsReservation(models.Model): ondelete="restrict", domain="[('id', 'in', allowed_room_ids)]", copy=False, + tracking=True, ) allowed_room_ids = fields.Many2many( "pms.room", @@ -88,6 +89,7 @@ class PmsReservation(models.Model): compute="_compute_board_service_room_id", store=True, readonly=False, + tracking=True, ) room_type_id = fields.Many2one( "pms.room.type", @@ -111,11 +113,13 @@ class PmsReservation(models.Model): related="folio_id.agency_id", readonly=False, store=True, + tracking=True, ) channel_type_id = fields.Many2one( related="folio_id.channel_type_id", store=True, readonly=False, + tracking=True, ) partner_invoice_id = fields.Many2one( "res.partner", @@ -154,6 +158,7 @@ class PmsReservation(models.Model): compute="_compute_pricelist_id", store=True, readonly=False, + tracking=True, ) show_update_pricelist = fields.Boolean( string="Has Pricelist Changed", @@ -167,6 +172,7 @@ class PmsReservation(models.Model): compute="_compute_commission_percent", store=True, readonly=False, + tracking=True, ) commission_amount = fields.Float( string="Commission amount", @@ -315,10 +321,18 @@ class PmsReservation(models.Model): ) out_service_description = fields.Text("Cause of out of service") checkin = fields.Date( - "Check In", required=True, default=_get_default_checkin, copy=False + "Check In", + required=True, + default=_get_default_checkin, + copy=False, + tracking=True, ) checkout = fields.Date( - "Check Out", required=True, default=_get_default_checkout, copy=False + "Check Out", + required=True, + default=_get_default_checkout, + copy=False, + tracking=True, ) arrival_hour = fields.Char( "Arrival Hour", @@ -365,11 +379,15 @@ class PmsReservation(models.Model): detail_origin = fields.Char( "Detail Origin", compute="_compute_detail_origin", store=True ) - folio_pending_amount = fields.Monetary(related="folio_id.pending_amount") + folio_pending_amount = fields.Monetary( + related="folio_id.pending_amount", + tracking=True, + ) folio_payment_state = fields.Selection( related="folio_id.payment_state", string="Payment State", store=True, + tracking=True, ) shared_folio = fields.Boolean(compute="_compute_shared") # Used to notify is the reservation folio has other reservations/services @@ -445,6 +463,7 @@ class PmsReservation(models.Model): readonly=True, store=True, compute="_compute_amount_reservation", + tracking=True, ) price_tax = fields.Float( string="Taxes Amount", @@ -470,6 +489,7 @@ class PmsReservation(models.Model): compute="_compute_discount", readonly=False, store=True, + tracking=True, ) date_order = fields.Date( compute="_compute_pms_creation_date", diff --git a/pms/security/ir.model.access.csv b/pms/security/ir.model.access.csv index 56d958429..ce18fbbfd 100644 --- a/pms/security/ir.model.access.csv +++ b/pms/security/ir.model.access.csv @@ -60,3 +60,4 @@ user_access_folio_make_invoice_advance,user_access_folio_make_invoice_advance,mo user_access_pms_invoice_filter_days,user_access_pms_invoice_filter_days,model_pms_invoice_filter_days,pms.group_pms_user,1,1,1,1 user_access_pms_invoice_filter_days_items,user_access_pms_invoice_filter_days_items,model_pms_invoice_filter_days_items,pms.group_pms_user,1,1,1,1 user_access_wizard_payment_folio,user_access_wizard_payment_folio,model_wizard_payment_folio,pms.group_pms_user,1,1,1,1 +user_access_wizard_folio_changes,user_access_wizard_folio_changes,model_wizard_folio_changes,pms.group_pms_user,1,1,1,1 diff --git a/pms/views/pms_folio_views.xml b/pms/views/pms_folio_views.xml index 50eb1ed78..d68cfd691 100644 --- a/pms/views/pms_folio_views.xml +++ b/pms/views/pms_folio_views.xml @@ -102,6 +102,14 @@ string="Invoices" /> + + diff --git a/pms/wizards/__init__.py b/pms/wizards/__init__.py index 443562250..d6820319a 100644 --- a/pms/wizards/__init__.py +++ b/pms/wizards/__init__.py @@ -6,3 +6,4 @@ from . import wizard_folio_availability from . import folio_make_invoice_advance from . import wizard_invoice_filter_days from . import wizard_payment_folio +from . import wizard_folio_changes diff --git a/pms/wizards/wizard_folio_changes.py b/pms/wizards/wizard_folio_changes.py new file mode 100644 index 000000000..d1040a97f --- /dev/null +++ b/pms/wizards/wizard_folio_changes.py @@ -0,0 +1,115 @@ +from odoo import _, api, fields, models + + +class WizardFolioChanges(models.TransientModel): + + _name = "wizard.folio.changes" + _description = "Folio Changes" + + def _default_folio_id(self): + folio_id = self._context.get("active_id") + folio = self.env["pms.folio"].browse(folio_id) + return folio + + def _default_reservation_ids(self): + folio_id = self._context.get("active_id") + folio = self.env["pms.folio"].browse(folio_id) + return folio.reservation_ids + + folio_id = fields.Many2one( + "pms.folio", + string="Folio", + default=_default_folio_id, + ) + reservation_ids = fields.Many2many( + "pms.reservation", + string="Reservations", + default=_default_reservation_ids, + domain="[('id', 'in', allowed_reservation_ids)]", + ) + allowed_reservation_ids = fields.Many2many( + "pms.reservation", + string="Allowed Reservations", + compute="_compute_allowed_reservations", + ) + new_price = fields.Float( + string="New Price", + ) + new_discount = fields.Float( + string="New Discount %", + ) + apply_on_monday = fields.Boolean( + string="Apply Availability Rule on mondays", + default=False, + ) + apply_on_tuesday = fields.Boolean( + string="Apply Availability Rule on tuesdays", + default=False, + ) + apply_on_wednesday = fields.Boolean( + string="Apply Availability Rule on wednesdays", + default=False, + ) + apply_on_thursday = fields.Boolean( + string="Apply Availability Rule on thursdays", + default=False, + ) + apply_on_friday = fields.Boolean( + string="Apply Availability Rule on fridays", + default=False, + ) + apply_on_saturday = fields.Boolean( + string="Apply Availability Rule on saturdays", + default=False, + ) + apply_on_sunday = fields.Boolean( + string="Apply Availability Rule on sundays", + default=False, + ) + apply_on_all_week = fields.Boolean( + string="Apply Availability Rule for the whole week", + default=True, + ) + + @api.depends("folio_id") + def _compute_allowed_reservations(self): + self.ensure_one() + self.allowed_reservation_ids = self.folio_id.reservation_ids + + def button_change(self): + vals = {} + week_days_to_apply = ( + self.apply_on_monday, + self.apply_on_tuesday, + self.apply_on_wednesday, + self.apply_on_thursday, + self.apply_on_friday, + self.apply_on_saturday, + self.apply_on_sunday, + ) + reservation_lines = self.reservation_ids.reservation_line_ids + if not self.apply_on_all_week: + reservation_lines = reservation_lines.filtered( + lambda x: week_days_to_apply[x.date.timetuple()[6]] + ) + if self.new_price: + vals["price"] = self.new_price + if self.new_discount: + vals["discount"] = self.new_discount + + reservation_lines.write(vals) + + self.folio_id.message_post( + body=_( + "Prices/Discounts have been changed from folio", + ) + ) + reservations = self.env["pms.reservation"].browse( + reservation_lines.mapped("reservation_id.id") + ) + for reservation in reservations: + reservation.message_post( + body=_( + "Prices/Discounts have been changed from folio", + ) + ) diff --git a/pms/wizards/wizard_folio_changes.xml b/pms/wizards/wizard_folio_changes.xml new file mode 100644 index 000000000..7242963a2 --- /dev/null +++ b/pms/wizards/wizard_folio_changes.xml @@ -0,0 +1,128 @@ + + + + wizard.folio.changes.view.form + wizard.folio.changes + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
All daysSundayMondayTuesdayWednesdayThursdayFridaySaturday
+ + + + + + + + + + + + + + + +
+
+
+
+
+ + + + + +
+
+ + + + +
+
+
+
+
+
+
+ + + Folio Changes + ir.actions.act_window + wizard.folio.changes + + form + new + + +