-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] sale_resource_booking (squashed)
[IMP] sale_resource_booking: booking.product_id, Buttons (product variant -> booking -> sale order) [FIX] sale_resource_booking: fix tests [ADD] sale_resource_booking_product_variant [IMP] sale_resource_booking_product_variant: documentation etc. [FIX] sale_resource_booking_product_variant: search Booking Type [FIX] sale_resource_booking_product_variant: text [FIX] sale_resource_booking_product_variant: code is in sale_resource_booking [IMP] sale_resource_booking: Types are connected with product variants. Set defaults on product.attribute form view. [FIX] sale_resource_booking: many2one was missing comodel [FIX] sale_resource_booking: migration [IMP] sale_resource_booking: do not auto-assign combination if timeline is installed [FIX] sale_resource_booking: pre-commit [FIX] sale_resource_booking: a sale order may have multiple lines (sale_product_pack) [IMP] sale_resource_booking: multiple order lines for one booking [IMP] sale_resource_booking: when change type for booking, product gets selected when there is just one [IMP] sale_resource_booking: raise UserError when trying to quote from booking with no product selected sale_resource_booking: confirm sale order with bookings: show updated sale order Return the sale order window action to show the correct status of the sale order sale_resource_booking: add info to sale.order.line A sale order line with a resource booking product and quantity == 1 will have correct resource_booking_id and its partner_id. sale_resource_booking: tiny change to trigger tests [FIX] sale_resource_booking: booking list changed partner_id to partner_ids [FIX] sale_resource_booking: default_partner_ids (not default_partner_id) [FIX] sale_resource_booking: Show the booking button Quote [BUG] sale_resource_booking: create product.product [FIX] sale_resource_booking: product inherit booking type from attribute value [IMP] sale_resource_booking: Auto-assign booking type to product variant
- Loading branch information
1 parent
6b3f08e
commit 15f912a
Showing
21 changed files
with
560 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
sale_resource_booking/migrations/16.0.2.0.0/pre-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from openupgradelib import openupgrade | ||
|
||
xmlids_to_rename = [ | ||
( | ||
"resource_booking_sale.resource_booking_type_form", | ||
"resource_booking_sale.resource_booking_type_view_form", | ||
), | ||
( | ||
"resource_booking_sale.resource_booking_form", | ||
"resource_booking_sale.resource_booking_view_form", | ||
), | ||
] | ||
|
||
|
||
def connect_resource_booking_type_with_product_variant(cr): | ||
openupgrade.logged_query( | ||
cr, | ||
""" | ||
ALTER TABLE product_product | ||
ADD COLUMN resource_booking_type_id int4, | ||
ADD COLUMN resource_booking_type_combination_rel_id int4; | ||
""", | ||
) | ||
openupgrade.logged_query( | ||
cr, | ||
""" | ||
UPDATE product_product p | ||
SET | ||
resource_booking_type_id = t.resource_booking_type_id, | ||
resource_booking_type_combination_rel_id = | ||
t.resource_booking_type_combination_rel_id | ||
FROM product_template as t | ||
WHERE p.product_tmpl_id = t.id | ||
AND (t.resource_booking_type_id > 0 | ||
OR | ||
t.resource_booking_type_combination_rel_id > 0 | ||
); | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate(use_env=False) | ||
def migrate(cr, version): | ||
|
||
openupgrade.rename_xmlids(cr, xmlids_to_rename) | ||
|
||
connect_resource_booking_type_with_product_variant(cr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ProductAttributeValue(models.Model): | ||
_inherit = "product.attribute.value" | ||
|
||
resource_booking_type_ids = fields.Many2many( | ||
comodel_name="resource.booking.type", | ||
relation="resource_booking_type_product_attribute_value_rel", | ||
readonly=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import logging | ||
|
||
from odoo import api, fields, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = "product.product" | ||
|
||
def _default_resource_booking_type_id(self): | ||
return self.product_tmpl_id.resource_booking_type_id | ||
|
||
def _default_resource_booking_type_combination_rel_id(self): | ||
return self.product_tmpl_id.resource_booking_type_combination_rel_id | ||
|
||
def _compute_resource_booking_count(self): | ||
for p in self: | ||
p.resource_booking_count = len(p.resource_booking_ids) | ||
|
||
resource_booking_type_id = fields.Many2one( | ||
"resource.booking.type", | ||
string="Booking type", | ||
index=True, | ||
ondelete="restrict", | ||
help="If set, one pending booking will be generated when sold.", | ||
default=lambda self: self._default_resource_booking_type_id(), | ||
) | ||
resource_booking_type_combination_rel_id = fields.Many2one( | ||
"resource.booking.type.combination.rel", | ||
string="Resource combination", | ||
index=True, | ||
ondelete="restrict", | ||
domain="[('type_id', '=', resource_booking_type_id)]", | ||
help=( | ||
"If set, the booking will be created with this resource combination. " | ||
"Otherwise, the combination will be assigned automatically later, " | ||
"when the requester schedules the booking." | ||
), | ||
default=lambda self: self._default_resource_booking_type_combination_rel_id(), | ||
) | ||
resource_booking_count = fields.Integer( | ||
compute="_compute_resource_booking_count", | ||
string="Booking Count", | ||
) | ||
resource_booking_ids = fields.One2many( | ||
"resource.booking", | ||
"product_id", | ||
string="Bookings", | ||
) | ||
|
||
def action_view_resource_booking(self): | ||
self.ensure_one() | ||
action = self.env["ir.actions.actions"]._for_xml_id( | ||
"resource_booking.resource_booking_action" | ||
) | ||
installed_timeline = self._is_module_installed("resource_booking_timeline") | ||
action["context"] = { | ||
"default_combination_auto_assign": False if installed_timeline else True, | ||
"default_product_id": self.id, | ||
"default_type_id": self.resource_booking_type_id.id, | ||
} | ||
# depends on partner_product_price | ||
if "partner_id" in self._fields: | ||
action["context"]["default_partner_ids"] = [self.partner_id.id] | ||
return action | ||
|
||
@api.constrains("product_template_attribute_value_ids") | ||
def _set_resource_booking_type_id(self): | ||
for product in self: | ||
# Booking Type | ||
v = product.product_template_attribute_value_ids.product_attribute_value_id | ||
if v: | ||
booking_type = ( | ||
self.env["resource.booking.type"] | ||
.search([("product_attribute_value_ids", "in", v.ids)]) | ||
.filtered( | ||
lambda t: len(t.product_attribute_value_ids) == len(v.ids) | ||
and set(t.product_attribute_value_ids.ids) == set(v.ids) | ||
) | ||
) | ||
if booking_type and len(booking_type) == 1: | ||
product.resource_booking_type_id = booking_type.id | ||
|
||
def _is_module_installed(self, module_name): | ||
module = self.env["ir.module.module"].search([("name", "=", module_name)]) | ||
return True if module and module.state == "installed" else False | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,46 @@ | ||
# Copyright 2021 Tecnativa - Jairo Llopis | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
import logging | ||
|
||
from odoo import fields, models | ||
from odoo import api, fields, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
@api.depends( | ||
"product_variant_ids.resource_booking_type_id", | ||
"product_variant_ids.resource_booking_type_combination_rel_id", | ||
) | ||
def _compute_resource_booking_type_and_combination_rel(self): | ||
for tmpl in self: | ||
_type = {v.resource_booking_type_id.id for v in tmpl.product_variant_ids} | ||
combination = { | ||
v.resource_booking_type_combination_rel_id.id | ||
for v in tmpl.product_variant_ids | ||
} | ||
tmpl.resource_booking_type_id = _type.pop() if len(_type) == 1 else None | ||
tmpl.resource_booking_type_combination_rel_id = ( | ||
combination.pop() if len(combination) == 1 else None | ||
) | ||
|
||
def _inverse_resource_booking_type_and_combination_rel(self): | ||
for tmpl in self: | ||
variants = tmpl.product_variant_ids | ||
variants.resource_booking_type_id = tmpl.resource_booking_type_id | ||
variants.resource_booking_type_combination_rel_id = ( | ||
tmpl.resource_booking_type_combination_rel_id | ||
) | ||
|
||
resource_booking_type_id = fields.Many2one( | ||
"resource.booking.type", | ||
string="Booking type", | ||
index=True, | ||
ondelete="restrict", | ||
help="If set, one pending booking will be generated when sold.", | ||
compute="_compute_resource_booking_type_and_combination_rel", | ||
inverse="_inverse_resource_booking_type_and_combination_rel", | ||
store=False, | ||
) | ||
resource_booking_type_combination_rel_id = fields.Many2one( | ||
"resource.booking.type.combination.rel", | ||
string="Resource combination", | ||
index=True, | ||
ondelete="restrict", | ||
domain="[('type_id', '=', resource_booking_type_id)]", | ||
help=( | ||
"If set, the booking will be created with this resource combination. " | ||
"Otherwise, the combination will be assigned automatically later, " | ||
"when the requester schedules the booking." | ||
), | ||
compute="_compute_resource_booking_type_and_combination_rel", | ||
inverse="_inverse_resource_booking_type_and_combination_rel", | ||
store=False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.