Skip to content

Commit

Permalink
[IMP] {website_,}event_sale: remove event_ok from product
Browse files Browse the repository at this point in the history
This is now a type of product.

task-2605931

Part-of: odoo#75862
  • Loading branch information
william-andre committed Sep 7, 2021
1 parent fa034b2 commit c8ec3e9
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 64 deletions.
1 change: 0 additions & 1 deletion addons/event_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
'views/event_ticket_views.xml',
'views/event_registration_views.xml',
'views/event_views.xml',
'views/product_views.xml',
'views/sale_order_views.xml',
'data/event_sale_data.xml',
'data/mail_data.xml',
Expand Down
6 changes: 1 addition & 5 deletions addons/event_sale/data/event_sale_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@

<record id="product_product_event" model="product.product">
<field name="list_price">30.0</field>
<field name="event_ok" eval="True"/>
<field name="standard_price">10.0</field>
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="uom_po_id" ref="uom.product_uom_unit"/>
<field name="name">Event Registration</field>
<field name="description_sale" eval="False"/>
<field name="invoice_policy">order</field>
<field name="categ_id" ref="event_sale.product_category_events"/>
<field name="type">service</field>
<field name="detailed_type">event</field>
</record>
</data>
</odoo>



2 changes: 1 addition & 1 deletion addons/event_sale/models/event_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _default_product_id(self):
# product
product_id = fields.Many2one(
'product.product', string='Product', required=True,
domain=[("event_ok", "=", True)], default=_default_product_id)
domain=[("detailed_type", "=", "event")], default=_default_product_id)
price = fields.Float(
string='Price', compute='_compute_price',
digits='Product Price', readonly=False, store=True)
Expand Down
27 changes: 10 additions & 17 deletions addons/event_sale/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,22 @@
class ProductTemplate(models.Model):
_inherit = 'product.template'

event_ok = fields.Boolean(string='Is an Event Ticket', help="If checked this product automatically "
"creates an event registration at the sales order confirmation.")
detailed_type = fields.Selection(selection_add=[
('event', 'Event Ticket'),
], ondelete={'event': 'set default'})

@api.onchange('event_ok')
def _onchange_event_ok(self):
if self.event_ok:
self.type = 'service'
@api.onchange('detailed_type')
def _onchange_type_event(self):
if self.detailed_type == 'event':
self.invoice_policy = 'order'

def _compute_show_service_fields(self):
super()._compute_show_service_fields()
for record in self:
record.show_service_fields |= record.type == 'event'
def _detailed_type_mapping(self):
type_mapping = super()._detailed_type_mapping()
type_mapping['event'] = 'service'
return type_mapping


class Product(models.Model):
_inherit = 'product.product'

event_ticket_ids = fields.One2many('event.event.ticket', 'product_id', string='Event Tickets')

@api.onchange('event_ok')
def _onchange_event_ok(self):
""" Redirection, inheritance mechanism hides the method on the model """
if self.event_ok:
self.type = 'service'
self.invoice_policy = 'order'
7 changes: 6 additions & 1 deletion addons/event_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ class SaleOrderLine(models.Model):
event_ticket_id = fields.Many2one(
'event.event.ticket', string='Event Ticket',
help="Choose an event ticket and it will automatically create a registration for this event ticket.")
event_ok = fields.Boolean(related='product_id.event_ok', readonly=True)
event_ok = fields.Boolean(compute='_compute_event_ok')

@api.depends('product_id.detailed_type')
def _compute_event_ok(self):
for record in self:
record.event_ok = record.product_id.detailed_type == 'event'

@api.depends('state', 'event_id')
def _compute_product_uom_readonly(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var FormController = require('web.FormController');

/**
* This controller is overridden to allow configuring sale_order_lines through a popup
* window when a product with 'event_ok' is selected.
* window when a product with 'detailed_type' == 'event' is selected.
*
* This allows keeping an editable list view for sales order and remove the noise of
* those 2 fields ('event_id' + 'event_ticket_id')
Expand Down
4 changes: 2 additions & 2 deletions addons/event_sale/static/src/js/event_configurator_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ ProductConfiguratorWidget.include({
return this._rpc({
model: 'product.product',
method: 'read',
args: [productId, ['event_ok']],
args: [productId, ['detailed_type']],
}).then(function (result) {
if (Array.isArray(result) && result.length && result[0].event_ok) {
if (Array.isArray(result) && result.length && result[0].detailed_type === 'event') {
self._openEventConfigurator({
default_product_id: productId
},
Expand Down
14 changes: 7 additions & 7 deletions addons/event_sale/static/tests/event_configurator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ odoo.define('event.configurator.tests', function (require) {
'product.product': {
fields: {
id: {type: 'integer'},
event_ok: {type: 'boolean'},
detailed_type: {type: 'selection'},
rent_ok: {type: 'boolean'}//sale_rental purposes
},
records: [{
id: 1,
display_name: "Customizable Event",
event_ok: true,
detailed_type: 'event',
rent_ok: false//sale_rental purposes
}, {
id: 2,
display_name: "Desk",
event_ok: false,
detailed_type: 'service',
rent_ok: false//sale_rental purposes
}]
},
Expand Down Expand Up @@ -85,9 +85,9 @@ odoo.define('event.configurator.tests', function (require) {
data: this.data,
arch: getArch(),
mockRPC: function (route, params) {
if (params.method === 'read' && params.args[1][0] === 'event_ok') {
if (params.method === 'read' && params.args[1][0] === 'detailed_type') {
assert.ok(true);
return Promise.resolve([{event_ok: false}]);
return Promise.resolve([{detailed_type: 'service'}]);
}
return this._super.apply(this, arguments);
},
Expand All @@ -114,9 +114,9 @@ odoo.define('event.configurator.tests', function (require) {
data: this.data,
arch: getArch(),
mockRPC: function (route, params) {
if (params.method === 'read' && params.args[1][0] === 'event_ok') {
if (params.method === 'read' && params.args[1][0] === 'detailed_type') {
assert.ok(true);
return Promise.resolve([{event_ok: true}]);
return Promise.resolve([{detailed_type: 'event'}]);
}
return this._super.apply(this, arguments);
},
Expand Down
3 changes: 1 addition & 2 deletions addons/event_sale/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def setUpClass(cls):
'name': 'Test Registration Product',
'description_sale': 'Mighty Description',
'list_price': 10,
'event_ok': True,
'standard_price': 30.0,
'type': 'service',
'detailed_type': 'event',
})
3 changes: 1 addition & 2 deletions addons/event_sale/tests/test_event_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def setUpClass(cls):

product = cls.env['product.product'].create({
'name': 'Event',
'type': 'service',
'event_ok': True,
'detailed_type': 'event',
})

cls.user_salesperson = mail_new_test_user(cls.env, login='user_salesman', groups='sales_team.group_sale_salesman')
Expand Down
5 changes: 2 additions & 3 deletions addons/event_sale/views/event_ticket_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<attribute name="string">Sales End</attribute>
</field>
<field name="name" position="after">
<field name="product_id" context="{'default_event_ok': 1}"/>
<field name="product_id" context="{'default_detailed_type': 'event'}"/>
</field>
<field name="description" position="after">
<field name="price"/>
Expand All @@ -57,7 +57,7 @@
<field name="inherit_id" ref="event.event_event_ticket_view_form_from_event"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="product_id" context="{'default_event_ok':1}"/>
<field name="product_id" context="{'default_detailed_type': 'event'}"/>
</field>
<field name="description" position="after">
<field name="price"/>
Expand Down Expand Up @@ -98,4 +98,3 @@
</field>
</record>
</data></odoo>

15 changes: 0 additions & 15 deletions addons/event_sale/views/product_views.xml

This file was deleted.

6 changes: 2 additions & 4 deletions addons/test_event_full/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ def setUpClass(cls):
'name': 'Test Registration Product',
'description_sale': 'Mighty Description',
'list_price': 10,
'event_ok': True,
'standard_price': 30.0,
'type': 'service',
'detailed_type': 'event',
})

cls.website = cls.env['website'].search([
Expand Down Expand Up @@ -138,9 +137,8 @@ def setUp(self):
'default_code': 'EVENT_REG',
'description_sale': 'Mighty Description',
'list_price': 10,
'event_ok': True,
'standard_price': 30.0,
'type': 'service',
'detailed_type': 'event',
})

self.event_tag_category_1 = self.env['event.tag.category'].create({
Expand Down
4 changes: 2 additions & 2 deletions addons/website_event_sale/models/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def _onchange_event_sale_warning(self):
msg = ''
if self.applied_on == '3_global' or self.applied_on == '2_product_category':
msg = _("A pricelist item with a positive min. quantity will not be applied to the event tickets products.")
elif ((self.applied_on == '1_product' and self.product_tmpl_id.event_ok) or
(self.applied_on == '0_product_variant' and self.product_id.event_ok)):
elif ((self.applied_on == '1_product' and self.product_tmpl_id.type == 'event') or
(self.applied_on == '0_product_variant' and self.product_id.type == 'event')):
msg = _("A pricelist item with a positive min. quantity cannot be applied to this event tickets product.")
if msg:
return {'warning':
Expand Down
2 changes: 1 addition & 1 deletion addons/website_event_sale/models/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class Website(models.Model):

def sale_product_domain(self):
# remove product event from the website content grid and list view (not removed in detail view)
return ['&'] + super(Website, self).sale_product_domain() + [('event_ok', '=', False)]
return ['&'] + super(Website, self).sale_product_domain() + [('type', '!=', 'event')]

0 comments on commit c8ec3e9

Please sign in to comment.