From 234e50b25f6e1383a3e8f48e6afd7522853550a6 Mon Sep 17 00:00:00 2001 From: sergio-teruel Date: Wed, 23 Oct 2024 00:13:16 +0200 Subject: [PATCH] [IMP] sale_planner_calendar: Refactor to use calendar.event model instead of sale.planner.calendar.event --- sale_planner_calendar/__manifest__.py | 2 +- .../migrations/16.0.2.0.0/post-migration.py | 80 ++++++++++++ .../migrations/16.0.2.0.0/pre-migration.py | 27 ++++ sale_planner_calendar/models/calendar.py | 34 +---- sale_planner_calendar/models/sale_order.py | 35 +++-- .../models/sale_payment_sheet.py | 4 +- .../models/sale_planner_calendar_event.py | 94 +++++++------- .../models/sale_planner_calendar_summary.py | 96 +++++++------- .../security/ir.model.access.csv | 1 - ...er_calendar_event_sales_kanban_view.esm.js | 2 +- ...nner_calendar_event_sales_list_view.esm.js | 2 +- .../tests/test_sale_planner_calendar.py | 2 +- sale_planner_calendar/views/calendar_view.xml | 11 +- .../sale_planner_calendar_event_view.xml | 120 ++++++++---------- .../sale_planner_calendar_summary_view.xml | 21 +-- .../wizard/sale_invoice_payment.py | 4 +- .../wizard/sale_planner_calendar_reassign.py | 1 + .../wizard/sale_planner_calendar_wizard.py | 4 +- 18 files changed, 287 insertions(+), 253 deletions(-) create mode 100644 sale_planner_calendar/migrations/16.0.2.0.0/post-migration.py create mode 100644 sale_planner_calendar/migrations/16.0.2.0.0/pre-migration.py diff --git a/sale_planner_calendar/__manifest__.py b/sale_planner_calendar/__manifest__.py index 27d137caf5f..4975648091d 100644 --- a/sale_planner_calendar/__manifest__.py +++ b/sale_planner_calendar/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Sale planner calendar", "summary": "Sale planner calendar", - "version": "16.0.1.0.1", + "version": "16.0.2.0.0", "development_status": "Beta", "category": "Sale", "website": "https://github.com/OCA/sale-workflow", diff --git a/sale_planner_calendar/migrations/16.0.2.0.0/post-migration.py b/sale_planner_calendar/migrations/16.0.2.0.0/post-migration.py new file mode 100644 index 00000000000..1f663f1002e --- /dev/null +++ b/sale_planner_calendar/migrations/16.0.2.0.0/post-migration.py @@ -0,0 +1,80 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade +from psycopg2.extensions import AsIs + + +def _sale_planner_calendar_event_to_calendar_event(env): + """Move all data from sale_planner_calendar_event to code model calendar_event""" + sql = """ + UPDATE calendar_event SET + sale_planner_state = spce.state, + calendar_issue_type_id = spce.calendar_issue_type_id, + calendar_event_profile_id = spce.calendar_event_profile_id, + comment = spce.comment, + calendar_summary_id = spce.calendar_summary_id, + off_planning = spce.off_planning + FROM sale_planner_calendar_event spce + WHERE spce.calendar_event_id = calendar_event.id + """ + openupgrade.logged_query(env.cr, sql) + + +def _sale_order_to_calendar_event(env): + """Link sale order to calendar events instead of sale planner calendar event model""" + # drop_constraint(env.cr, 'sale_order', 'sale_order_sale_planner_calendar_event_id_fkey') + openupgrade.logged_query( + env.cr, + """ + UPDATE sale_order SET + sale_planner_calendar_event_id = spce.calendar_event_id + FROM sale_planner_calendar_event spce + WHERE sale_order.%(old_column)s = spce.id + """, + { + "old_column": AsIs( + openupgrade.get_legacy_name("sale_planner_calendar_event_id") + ) + }, + ) + + +def _payment_sheet_to_calendar_event(env): + """Link sale payment sheet to calendar events instead of sale planner calendar + event model + """ + # drop_constraint(env.cr, 'sale_payment_sheet_line', + # 'sale_payment_sheet_line_sale_planner_calendar_event_id_fkey') + openupgrade.logged_query( + env.cr, + """ + UPDATE sale_payment_sheet_line SET + sale_planner_calendar_event_id = spce.calendar_event_id + FROM sale_planner_calendar_event spce + WHERE sale_payment_sheet_line.%(old_column)s = spce.id + """, + { + "old_column": AsIs( + openupgrade.get_legacy_name("sale_planner_calendar_event_id") + ) + }, + ) + + +def _remove_selection_field_values(env): + sql = """ + DELETE FROM ir_model_fields_selection + WHERE field_id IN + (SELECT id + FROM ir_model_fields + WHERE ttype='selection' AND model='sale.planner.calendar.event') + """ + openupgrade.logged_query(env.cr, sql) + + +@openupgrade.migrate() +def migrate(env, version): + _sale_planner_calendar_event_to_calendar_event(env) + _sale_order_to_calendar_event(env) + _payment_sheet_to_calendar_event(env) + # _remove_selection_field_values(env) diff --git a/sale_planner_calendar/migrations/16.0.2.0.0/pre-migration.py b/sale_planner_calendar/migrations/16.0.2.0.0/pre-migration.py new file mode 100644 index 00000000000..5c8de1f187b --- /dev/null +++ b/sale_planner_calendar/migrations/16.0.2.0.0/pre-migration.py @@ -0,0 +1,27 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + +_column_renames = { + "sale_order": [ + ("sale_planner_calendar_event_id", None), + ], + "sale_payment_sheet_line": [("sale_planner_calendar_event_id", None)], +} + + +def _remove_selection_field_values(env): + sql = """ + DELETE FROM ir_model_fields_selection + WHERE field_id IN + (SELECT id + FROM ir_model_fields + WHERE ttype='selection' AND model='sale.planner.calendar.event') + """ + openupgrade.logged_query(env.cr, sql) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.rename_columns(env.cr, _column_renames) + _remove_selection_field_values(env) diff --git a/sale_planner_calendar/models/calendar.py b/sale_planner_calendar/models/calendar.py index 440d4359f48..e92da1b1daa 100644 --- a/sale_planner_calendar/models/calendar.py +++ b/sale_planner_calendar/models/calendar.py @@ -22,18 +22,8 @@ class CalendarEvent(models.Model): calendar_event_profile_id = fields.Many2one( comodel_name="sale.planner.calendar.event.profile" ) - currency_id = fields.Many2one( - comodel_name="res.currency", related="target_partner_id.currency_id" - ) hour = fields.Float(compute="_compute_hour", inverse="_inverse_hour") target_partner_mobile = fields.Char(related="target_partner_id.mobile") - sale_planner_calendar_event_id = fields.Many2one( - comodel_name="sale.planner.calendar.event", - compute="_compute_sale_planner_calendar_event_id", - ) - event_planner_state = fields.Char( - compute="_compute_sale_planner_calendar_event_id", - ) # When arrive this date we will unsubscribe user from partner documents unsubscribe_date = fields.Date() is_dynamic_end_date = fields.Boolean(copy=False) @@ -59,25 +49,6 @@ def _compute_hour(self): date = rec._get_hour_tz_offset() rec.hour = date.hour + date.minute / 60 - @api.depends("start", "target_partner_id", "user_id") - def _compute_sale_planner_calendar_event_id(self): - # TODO: Adjust order or use [:1] or [-1:] when know model order - domain = [ - ("calendar_event_date", "in", self.mapped("start")), - ("partner_id", "in", self.mapped("target_partner_id").ids), - ("user_id", "=", self.user_id.id), - ] - events = self.env["sale.planner.calendar.event"].search(domain) - for rec in self: - rec.sale_planner_calendar_event_id = events.filtered( - lambda r: ( - r.calendar_event_date == fields.Datetime.to_datetime(rec.start) - and r.partner_id == rec.target_partner_id - and r.user_id == rec.user_id - ) - )[:1] - rec.event_planner_state = rec.sale_planner_calendar_event_id.state - def _get_hour_tz_offset(self): timezone = self._context.get("tz") or self.env.user.partner_id.tz or "UTC" self_tz = self.with_context(tz=timezone) @@ -102,13 +73,12 @@ def _inverse_hour(self): ) def _create_event_planner(self): - return self.env["sale.planner.calendar.event"].create( + return self.env["calendar.event"].create( { "name": self.name, "partner_id": self.target_partner_id.id, "user_id": self.user_id.id, - "calendar_event_date": self.start, - "calendar_event_id": self.id, + "start": self.start, "calendar_event_profile_id": self.calendar_event_profile_id.id, } ) diff --git a/sale_planner_calendar/models/sale_order.py b/sale_planner_calendar/models/sale_order.py index c30c09ccf4d..5c18dc7e6a1 100644 --- a/sale_planner_calendar/models/sale_order.py +++ b/sale_planner_calendar/models/sale_order.py @@ -1,5 +1,6 @@ # Copyright 2021 Tecnativa - Sergio Teruel # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from datetime import timedelta from odoo import _, api, fields, models from odoo.tools import relativedelta @@ -8,9 +9,7 @@ class SaleOrder(models.Model): _inherit = "sale.order" - sale_planner_calendar_event_id = fields.Many2one( - comodel_name="sale.planner.calendar.event" - ) + sale_planner_calendar_event_id = fields.Many2one(comodel_name="calendar.event") def _action_confirm(self): event_obj = self.env["calendar.event"] @@ -32,13 +31,16 @@ def _action_confirm(self): return super()._action_confirm() def _prepare_calendar_event_planner(self): + categ = self.env.ref("sale_planner_calendar.event_type_commercial_visit") return { "name": _("Sale off planning"), - "partner_id": self.partner_id.id, + "target_partner_id": self.partner_id.id, "user_id": self.user_id.id, - "date": self.date_order, + "start": self.date_order, + "stop": self.date_order + + timedelta(minutes=round((categ.duration or 1.0) * 60)), "off_planning": True, - "state": "done", + "sale_planner_state": "done", } def action_set_planner_calendar_event(self, planner_summary=False): @@ -55,20 +57,17 @@ def action_set_planner_calendar_event(self, planner_summary=False): max(order_dates), self.env.company.sale_planner_order_cut_hour ) + relativedelta(days=1) calendar_event_domain = [ - ("partner_id", "in", orders.partner_id.ids), + ("target_partner_id", "in", orders.partner_id.ids), ("user_id", "in", orders.user_id.ids), - ("date", ">=", date_from), - ("date", "<", date_to), + ("start", ">=", date_from), + ("start", "<", date_to), ] if planner_summary.event_type_id: calendar_event_domain.append( - ("calendar_event_id.categ_ids", "in", planner_summary.event_type_id.ids) + ("categ_ids", "in", planner_summary.event_type_id.ids) ) - calendar_events = self.env["sale.planner.calendar.event"].search( - calendar_event_domain - ) + calendar_events = self.env["calendar.event"].search(calendar_event_domain) planner_summary_domain = [ - ("user_id", "in", orders.user_id.ids), ("user_id", "in", orders.user_id.ids), ("date", ">=", date_from.date()), ("date", "<", date_to.date()), @@ -85,11 +84,11 @@ def action_set_planner_calendar_event(self, planner_summary=False): cut_time = date_from.time() for order in orders: event = calendar_events.filtered( - lambda ev: ev.partner_id == order.partner_id + lambda ev: ev.target_partner_id == order.partner_id and ev.user_id == order.user_id - and (ev.date.combine(ev.date.date(), cut_time) <= order.date_order) + and (ev.start.combine(ev.start.date(), cut_time) <= order.date_order) and ( - ev.date.combine(ev.date.date(), cut_time) + relativedelta(days=1) + ev.start.combine(ev.start.date(), cut_time) + relativedelta(days=1) > order.date_order ) )[:1] @@ -114,7 +113,7 @@ def action_set_planner_calendar_event(self, planner_summary=False): continue event_vals = order._prepare_calendar_event_planner() event_vals["calendar_summary_id"] = event_summary.id - event = self.env["sale.planner.calendar.event"].create(event_vals) + event = self.env["calendar.event"].create(event_vals) order.sale_planner_calendar_event_id = event @api.model_create_multi diff --git a/sale_planner_calendar/models/sale_payment_sheet.py b/sale_planner_calendar/models/sale_payment_sheet.py index 48b1dccf9ba..0669c75480b 100644 --- a/sale_planner_calendar/models/sale_payment_sheet.py +++ b/sale_planner_calendar/models/sale_payment_sheet.py @@ -7,6 +7,4 @@ class SalePaymentSheetLine(models.Model): _inherit = "sale.payment.sheet.line" - sale_planner_calendar_event_id = fields.Many2one( - comodel_name="sale.planner.calendar.event" - ) + sale_planner_calendar_event_id = fields.Many2one(comodel_name="calendar.event") diff --git a/sale_planner_calendar/models/sale_planner_calendar_event.py b/sale_planner_calendar/models/sale_planner_calendar_event.py index 4fca31e02e8..fe0451c0630 100644 --- a/sale_planner_calendar/models/sale_planner_calendar_event.py +++ b/sale_planner_calendar/models/sale_planner_calendar_event.py @@ -7,35 +7,18 @@ from odoo.tools.safe_eval import safe_eval -class SalePlannerCalendarEvent(models.Model): - _name = "sale.planner.calendar.event" - _description = "Sale planner calendar event" +class CalendarEvent(models.Model): + _inherit = "calendar.event" - name = fields.Char(string="Subject") - company_id = fields.Many2one( - comodel_name="res.company", default=lambda self: self.env.company.id - ) - currency_id = fields.Many2one( + sale_planner_currency_id = fields.Many2one( comodel_name="res.currency", - related="partner_id.currency_id", - ) - date = fields.Datetime(default=fields.Datetime.now) - calendar_event_id = fields.Many2one( - comodel_name="calendar.event", - ) - calendar_event_date = fields.Datetime(index=True) - user_id = fields.Many2one( - comodel_name="res.users", - default=lambda self: self.env.user.id, - index=True, - domain="[('share','=',False)]", + related="target_partner_id.currency_id", ) - partner_id = fields.Many2one(comodel_name="res.partner", index=True) sale_ids = fields.One2many( comodel_name="sale.order", inverse_name="sale_planner_calendar_event_id", ) - state = fields.Selection( + sale_planner_state = fields.Selection( [ ("pending", "Pending"), ("done", "Done"), @@ -52,32 +35,35 @@ class SalePlannerCalendarEvent(models.Model): ) comment = fields.Text() sale_order_subtotal = fields.Monetary( - compute="_compute_sale_order_subtotal", currency_field="currency_id" + compute="_compute_sale_order_subtotal", + currency_field="sale_planner_currency_id", ) calendar_summary_id = fields.Many2one( comodel_name="sale.planner.calendar.summary", + copy=False, ) invoice_amount_residual = fields.Monetary( string="Invoice amount due", compute="_compute_invoice_amount_residual", compute_sudo=True, + currency_field="sale_planner_currency_id", ) - off_planning = fields.Boolean() + off_planning = fields.Boolean(copy=False) payment_sheet_line_ids = fields.One2many( comodel_name="sale.payment.sheet.line", inverse_name="sale_planner_calendar_event_id", ) # Helper fields to kanban views - partner_ref = fields.Char(related="partner_id.ref") + partner_ref = fields.Char(related="target_partner_id.ref") partner_name = fields.Char(compute="_compute_partner_name") partner_commercial_name = fields.Char( string="Commercial partner name", - related="partner_id.commercial_partner_id.name", + related="target_partner_id.commercial_partner_id.name", ) - partner_street = fields.Char(related="partner_id.street") + partner_street = fields.Char(related="target_partner_id.street") partner_mobile = fields.Char(compute="_compute_contact") partner_contact_name = fields.Char(compute="_compute_contact") - partner_city = fields.Char(related="partner_id.city") + partner_city = fields.Char(related="target_partner_id.city") sanitized_partner_mobile = fields.Char(compute="_compute_sanitized_partner_mobile") location_url = fields.Char(compute="_compute_location_url") profile_icon = fields.Char(related="calendar_event_profile_id.icon") @@ -96,7 +82,7 @@ def _compute_invoice_amount_residual(self): ( "partner_id", "in", - self.mapped("partner_id.commercial_partner_id").ids, + self.mapped("target_partner_id.commercial_partner_id").ids, ), ], ["amount_residual_signed"], @@ -105,7 +91,7 @@ def _compute_invoice_amount_residual(self): invoice_dic = {g["partner_id"][0]: g["amount_residual_signed"] for g in groups} for rec in self: amount_residual = invoice_dic.get( - rec.partner_id.commercial_partner_id.id, 0.0 + rec.target_partner_id.commercial_partner_id.id, 0.0 ) rec.invoice_amount_residual = amount_residual - sum( rec.payment_sheet_line_ids.filtered( @@ -125,16 +111,18 @@ def _compute_partner_name(self): for event in self: # If more flexibility is needed use event.mapped(field_name)[0] event.partner_name = ( - event.partner_id[field_name] - or event.partner_id.name - or event.partner_id.commercial_partner_id.name + event.target_partner_id[field_name] + or event.target_partner_id.name + or event.target_partner_id.commercial_partner_id.name ) def _compute_contact(self): for rec in self: - contact = rec.partner_id.child_ids.filtered("is_sale_planner_contact")[:1] + contact = rec.target_partner_id.child_ids.filtered( + "is_sale_planner_contact" + )[:1] rec.partner_mobile = (contact.mobile or contact.phone) or ( - rec.partner_id.mobile or rec.partner_id.phone + rec.target_partner_id.mobile or rec.target_partner_id.phone ) rec.partner_contact_name = contact.name @@ -151,9 +139,13 @@ def _compute_location_url(self): # will be taken into account. self.location_url = False for rec in self: - event_location = rec.calendar_event_id.location - partner_latitude = str(rec.partner_id.partner_latitude).replace(",", ".") - partner_longitude = str(rec.partner_id.partner_longitude).replace(",", ".") + event_location = rec.location + partner_latitude = str(rec.target_partner_id.partner_latitude).replace( + ",", "." + ) + partner_longitude = str(rec.target_partner_id.partner_longitude).replace( + ",", "." + ) partner_location = f"{rec.partner_city}+{rec.partner_street}" if event_location: self.location_url = event_location.replace(" ", "+") @@ -187,14 +179,14 @@ def action_open_sale_order(self, new_order=False): .get_param("sale_planner_calendar.create_so_to_commercial_partner", "False") ) partner = ( - self.partner_id + self.target_partner_id if create_so_to_commercial_partner == "False" - else self.partner_id.commercial_partner_id + else self.target_partner_id.commercial_partner_id ) action["context"] = { "default_sale_planner_calendar_event_id": self.id, "default_partner_id": partner.id, - "default_partner_shipping_id": self.partner_id.id, + "default_partner_shipping_id": self.target_partner_id.id, "default_user_id": self.user_id.id, } if len(self.sale_ids) > 1: @@ -211,13 +203,13 @@ def action_open_invoices(self): ctx = safe_eval(action["context"]) ctx.update( { - "default_partner_id": self.partner_id.id, + "default_partner_id": self.target_partner_id.id, } ) action["context"] = ctx domain = safe_eval(action["domain"]) domain.append( - ("partner_id", "=", self.partner_id.commercial_partner_id.id), + ("partner_id", "=", self.target_partner_id.commercial_partner_id.id), ) action["domain"] = domain return action @@ -226,7 +218,7 @@ def action_open_unpaid_invoice(self): domain = [ ("state", "=", "posted"), ("move_type", "in", ["out_invoice", "out_refund"]), - ("partner_id", "=", self.partner_id.commercial_partner_id.id), + ("partner_id", "=", self.target_partner_id.commercial_partner_id.id), ("payment_state", "!=", "paid"), ] unpaid_invoices = self.env["account.move"].search(domain) @@ -238,7 +230,7 @@ def action_open_unpaid_invoice(self): { "invoice_ids": unpaid_invoices.ids, "default_sale_planner_calendar_event_id": self.id, - "default_partner_id": self.partner_id.id, + "default_partner_id": self.target_partner_id.id, } ) action["context"] = ctx @@ -247,8 +239,8 @@ def action_open_unpaid_invoice(self): def action_done(self): self.write( { - "state": "done", - "date": fields.Datetime.now(), + "sale_planner_state": "done", + # "date": fields.Datetime.now(), # "comment": 'Done', } ) @@ -256,18 +248,18 @@ def action_done(self): def action_cancel(self): self.write( { - "state": "cancel", + "sale_planner_state": "cancel", "comment": "Not done", - "date": fields.Datetime.now(), + # "date": fields.Datetime.now(), } ) def action_pending(self): self.write( { - "state": "pending", + "sale_planner_state": "pending", "comment": False, - "date": self.calendar_event_date, + # "date": self.calendar_event_date, } ) diff --git a/sale_planner_calendar/models/sale_planner_calendar_summary.py b/sale_planner_calendar/models/sale_planner_calendar_summary.py index 7e060543cf7..df2c5f0dbf4 100644 --- a/sale_planner_calendar/models/sale_planner_calendar_summary.py +++ b/sale_planner_calendar/models/sale_planner_calendar_summary.py @@ -22,7 +22,7 @@ class SalePlannerCalendarSummary(models.Model): ) date = fields.Date(default=fields.Date.context_today) sale_planner_calendar_event_ids = fields.One2many( - comodel_name="sale.planner.calendar.event", + comodel_name="calendar.event", inverse_name="calendar_summary_id", ) user_id = fields.Many2one( @@ -70,7 +70,7 @@ def _compute_sale_ids(self): @api.depends( "sale_planner_calendar_event_ids", - "sale_planner_calendar_event_ids.state", + "sale_planner_calendar_event_ids.sale_planner_state", "sale_planner_calendar_event_ids.sale_ids", "sale_planner_calendar_event_ids.off_planning", ) @@ -84,7 +84,7 @@ def _compute_event_planner_count(self): payment_amount = 0.0 for event in summary.sale_planner_calendar_event_ids: event_total_count += 1 - if event.state == "done": + if event.sale_planner_state == "done": event_done_count += 1 if event.sale_ids: event_effective_count += 1 @@ -215,53 +215,56 @@ def action_process(self): ), ("user_id", "=", self.user_id.id), ("target_partner_id", "!=", False), + ("calendar_summary_id", "=", False), ] if self.event_type_id: calendar_event_domain.append(("categ_ids", "in", self.event_type_id.ids)) calendar_events = self.env["calendar.event"].search(calendar_event_domain) + calendar_events.calendar_summary_id = self + # + # event_planner_domain = [ + # ( + # "start", + # ">=", + # self._get_datetime_from_date_tz_hour(self.date, "00:00:00"), + # ), + # ( + # "start", + # "<=", + # self._get_datetime_from_date_tz_hour(self.date, "23:59:59"), + # ), + # ("user_id", "=", self.user_id.id), + # "|", + # ("calendar_summary_id", "=", False), + # ("calendar_summary_id", "=", self.id), + # ] + # events_planner = self.env["calendar.event"].search( + # event_planner_domain + # ) + # # We can not do a typical search due to returned virtual ids like this + # # ("calendar_event_id.categ_ids", "in", self.event_type_id.ids) + # if self.event_type_id: + # events_planner = events_planner.filtered( + # lambda p: self.event_type_id.id in p.calendar_event_id.categ_ids.ids + # ) + # + # for calendar_event in calendar_events: + # event_planner = events_planner.filtered( + # lambda r: r.start + # == fields.Datetime.to_datetime(calendar_event.start) + # and r.partner_id == calendar_event.target_partner_id + # and r.user_id == calendar_event.user_id + # ) + # if event_planner: + # if event_planner.calendar_summary_id != self: + # event_planner.calendar_summary_id = self + # event_planner.off_planning = True + # else: + # calendar_event.with_context( + # default_calendar_summary_id=self.id, + # default_date=calendar_event.start, + # )._create_event_planner() - event_planner_domain = [ - ( - "calendar_event_date", - ">=", - self._get_datetime_from_date_tz_hour(self.date, "00:00:00"), - ), - ( - "calendar_event_date", - "<=", - self._get_datetime_from_date_tz_hour(self.date, "23:59:59"), - ), - ("user_id", "=", self.user_id.id), - "|", - ("calendar_summary_id", "=", False), - ("calendar_summary_id", "=", self.id), - ] - events_planner = self.env["sale.planner.calendar.event"].search( - event_planner_domain - ) - # We can not do a typical search due to returned virtual ids like this - # ("calendar_event_id.categ_ids", "in", self.event_type_id.ids) - if self.event_type_id: - events_planner = events_planner.filtered( - lambda p: self.event_type_id.id in p.calendar_event_id.categ_ids.ids - ) - - for calendar_event in calendar_events: - event_planner = events_planner.filtered( - lambda r: r.calendar_event_date - == fields.Datetime.to_datetime(calendar_event.start) - and r.partner_id == calendar_event.target_partner_id - and r.user_id == calendar_event.user_id - ) - if event_planner: - if event_planner.calendar_summary_id != self: - event_planner.calendar_summary_id = self - event_planner.off_planning = True - else: - calendar_event.with_context( - default_calendar_summary_id=self.id, - default_date=calendar_event.start, - )._create_event_planner() # Search sale orders off planning date_from = self._get_datetime_from_date_tz_hour( self.date, self.env.company.sale_planner_order_cut_hour @@ -295,8 +298,7 @@ def _get_datetime_from_date_tz_hour(self, date, hour_float): return time_utc def action_event_planner(self): - if not self.sale_planner_calendar_event_ids: - self.action_process() + self.action_process() action = self.env["ir.actions.act_window"]._for_xml_id( "sale_planner_calendar.action_sale_planner_calendar_event" ) diff --git a/sale_planner_calendar/security/ir.model.access.csv b/sale_planner_calendar/security/ir.model.access.csv index 28a46962e6b..a81a9bb40d4 100644 --- a/sale_planner_calendar/security/ir.model.access.csv +++ b/sale_planner_calendar/security/ir.model.access.csv @@ -1,5 +1,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_sale_planner_calendar_event,access_sale_planner_calendar_event,model_sale_planner_calendar_event,sales_team.group_sale_salesman,1,1,1,1 access_sale_planner_calendar_summary,access_sale_planner_calendar_summary,model_sale_planner_calendar_summary,sales_team.group_sale_salesman,1,1,1,1 access_sale_planner_calendar_issue_type,access_sale_planner_calendar_issue_type,model_sale_planner_calendar_issue_type,sales_team.group_sale_salesman,1,1,1,1 access_sale_planner_calendar_reassign_wiz,access_sale_planner_calendar_reassign_wiz,model_sale_planner_calendar_reassign_wiz,sales_team.group_sale_salesman,1,1,1,1 diff --git a/sale_planner_calendar/static/src/js/sale_planner_calendar_event_sales_kanban_view.esm.js b/sale_planner_calendar/static/src/js/sale_planner_calendar_event_sales_kanban_view.esm.js index e6b9fa0a0e3..124f95ded6b 100644 --- a/sale_planner_calendar/static/src/js/sale_planner_calendar_event_sales_kanban_view.esm.js +++ b/sale_planner_calendar/static/src/js/sale_planner_calendar_event_sales_kanban_view.esm.js @@ -15,7 +15,7 @@ export class SalePlannerCalendarEventKanbanController extends KanbanController { console.log(this); const calendar_summary_id = this.props.context.default_calendar_summary_id; const action = await this.orm.call( - "sale.planner.calendar.event", + "calendar.event", "action_open_sale_order", [false, {new_order: true}], {context: {calendar_summary_id: calendar_summary_id || false}} diff --git a/sale_planner_calendar/static/src/js/sale_planner_calendar_event_sales_list_view.esm.js b/sale_planner_calendar/static/src/js/sale_planner_calendar_event_sales_list_view.esm.js index 310ab58449e..2d0c825dd1c 100644 --- a/sale_planner_calendar/static/src/js/sale_planner_calendar_event_sales_list_view.esm.js +++ b/sale_planner_calendar/static/src/js/sale_planner_calendar_event_sales_list_view.esm.js @@ -15,7 +15,7 @@ export class SalePlannerCalendarEventListController extends ListController { console.log(this); const calendar_summary_id = this.props.context.default_calendar_summary_id; const action = await this.orm.call( - "sale.planner.calendar.event", + "calendar.event", "action_open_sale_order", [false, {new_order: true}], {context: {calendar_summary_id: calendar_summary_id || false}} diff --git a/sale_planner_calendar/tests/test_sale_planner_calendar.py b/sale_planner_calendar/tests/test_sale_planner_calendar.py index a9eb427a9a4..b8a02a1cf5f 100644 --- a/sale_planner_calendar/tests/test_sale_planner_calendar.py +++ b/sale_planner_calendar/tests/test_sale_planner_calendar.py @@ -34,7 +34,7 @@ def setUpClass(cls): cls.AccountInvoiceLine = cls.env["account.move.line"] cls.AccountJournal = cls.env["account.journal"] cls.SaleOrder = cls.env["sale.order"] - cls.SalePlannerCalendarEvent = cls.env["sale.planner.calendar.event"] + cls.SalePlannerCalendarEvent = cls.env["calendar.event"] account_group = cls.env.ref("account.group_account_user") cls.env.user.write({"groups_id": [(4, account_group.id)]}) diff --git a/sale_planner_calendar/views/calendar_view.xml b/sale_planner_calendar/views/calendar_view.xml index b1d0fed4fb5..f29ace0e67e 100644 --- a/sale_planner_calendar/views/calendar_view.xml +++ b/sale_planner_calendar/views/calendar_view.xml @@ -43,7 +43,7 @@ 'choose_unlink_method': True, } [('recurrency', '=', True), - ("is_base_recurrent_event", "=", True), '|', ('recurrence_id.until', '>=', datetime.date.today().strftime("%Y-%m-%d")), ('recurrence_id.until', '=', False)] + ("is_base_recurrent_event", "=", True), ('target_partner_id', '!=', False), '|', ('recurrence_id.until', '>=', datetime.date.today().strftime("%Y-%m-%d")), ('recurrence_id.until', '=', False)] @@ -114,12 +114,9 @@ - -
+
- [('user_id', '=', uid)] + [('user_id', '=', uid), ('target_partner_id', '!=', False)] diff --git a/sale_planner_calendar/views/sale_planner_calendar_event_view.xml b/sale_planner_calendar/views/sale_planner_calendar_event_view.xml index 3e560f8e993..d5657f31abe 100644 --- a/sale_planner_calendar/views/sale_planner_calendar_event_view.xml +++ b/sale_planner_calendar/views/sale_planner_calendar_event_view.xml @@ -3,12 +3,13 @@ sale.planner.calendar.event - sale.planner.calendar.event + calendar.event + 40 - + - + @@ -43,27 +44,23 @@ sale.planner.calendar.event.tree - sale.planner.calendar.event + calendar.event - + - + - - + + + sale.planner.calendar.event.form - sale.planner.calendar.event + calendar.event
@@ -73,7 +70,7 @@ class="oe_stat_button" name="action_done" type="object" - attrs="{'invisible':[('state', 'not in', ['pending'])]}" + attrs="{'invisible':[('sale_planner_state', 'not in', ['pending'])]}" icon="fa-check" > @@ -82,7 +79,7 @@ name="action_cancel" string="Cancel" type="object" - attrs="{'invisible':[('state', 'in', ['cancel', 'done'])]}" + attrs="{'invisible':[('sale_planner_state', 'in', ['cancel', 'done'])]}" icon="fa-close" />
- +
@@ -289,7 +266,7 @@ t-att-class="'me-1 fa ' + record.profile_icon.value" /> @@ -401,8 +378,6 @@
@@ -438,8 +413,6 @@
@@ -502,10 +475,21 @@ Sale planner calendar events - sale.planner.calendar.event + calendar.event tree,form,kanban + + {'search_default_start_today': 1, 'search_default_my_event_planner': 1} + [('target_partner_id', '!=', False)] diff --git a/sale_planner_calendar/views/sale_planner_calendar_summary_view.xml b/sale_planner_calendar/views/sale_planner_calendar_summary_view.xml index f441ef64970..f3747bb9b32 100644 --- a/sale_planner_calendar/views/sale_planner_calendar_summary_view.xml +++ b/sale_planner_calendar/views/sale_planner_calendar_summary_view.xml @@ -43,12 +43,7 @@ - + @@ -61,14 +56,6 @@
-