Skip to content

Commit

Permalink
[IMP] {website_sale_,}gift_card: remove is_gift_card from product
Browse files Browse the repository at this point in the history
This is now a new type

task-2605931

Part-of: odoo#75862
  • Loading branch information
william-andre committed Sep 7, 2021
1 parent c8ec3e9 commit 1a89580
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 23 deletions.
5 changes: 2 additions & 3 deletions addons/gift_card/data/gift_card_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<record id="pay_with_gift_card_product" model="product.product">
<field name="name">Gift Card</field>
<field name="list_price">0</field>
<field name="type">service</field>
<field name="detailed_type">service</field>
<field name="purchase_ok" eval="False"/>
<field name="sale_ok" eval="False"/>
<field name="image_1920" type="base64" file="gift_card/static/img/gift_card.png"/>
Expand All @@ -15,9 +15,8 @@
<record id="gift_card_product_50" model="product.product">
<field name="name">Gift Card</field>
<field name="list_price">50</field>
<field name="type">service</field>
<field name="detailed_type">gift</field>
<field name="purchase_ok" eval="False"/>
<field name="is_gift_card" eval="True"/>
<field name="image_1920" type="base64" file="gift_card/static/img/gift_card.png"/>
</record>
</data>
Expand Down
9 changes: 8 additions & 1 deletion addons/gift_card/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
class ProductTemplate(models.Model):
_inherit = "product.template"

is_gift_card = fields.Boolean(default=False, help="This product is converted into a gift card when purchased.")
detailed_type = fields.Selection(selection_add=[
('gift', 'Gift Card'),
], ondelete={'gift': 'set default'})

def _detailed_type_mapping(self):
type_mapping = super()._detailed_type_mapping()
type_mapping['gift'] = 'service'
return type_mapping

@api.ondelete(at_uninstall=False)
def _unlink_gift_card_product(self):
Expand Down
2 changes: 1 addition & 1 deletion addons/sale_gift_card/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _constrains_state(self):

# create and send gift card when order become confirmed
for record in self.filtered(lambda so: so.state == 'sale'):
for gift_card_order_line in record.order_line.filtered(lambda ol: ol.product_id.is_gift_card):
for gift_card_order_line in record.order_line.filtered(lambda ol: ol.product_id.detailed_type == 'gift'):
gift_card_order_line._create_gift_cards()
record.sudo()._send_gift_card_mail()

Expand Down
2 changes: 1 addition & 1 deletion addons/sale_gift_card/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def setUpClass(cls):
})
cls.product_gift_card = cls.env['product.product'].create({
'name': 'Gift Card 50',
'detailed_type': 'gift',
'list_price': 50,
'sale_ok': True,
'taxes_id': False,
'is_gift_card': True
})
2 changes: 2 additions & 0 deletions addons/sale_gift_card/tests/test_buy_gift_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from odoo import Command
from odoo.addons.sale_gift_card.tests.common import TestSaleGiftCardCommon
from odoo.tests.common import tagged

@tagged('-at_install', 'post_install')
class TestBuyGiftCard(TestSaleGiftCardCommon):

def test_buying_simple_gift_card(self):
Expand Down
2 changes: 2 additions & 0 deletions addons/sale_gift_card/tests/test_pay_with_gift_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from odoo import Command
from odoo.addons.sale_gift_card.tests.common import TestSaleGiftCardCommon
from odoo.exceptions import UserError
from odoo.tests.common import tagged

@tagged('-at_install', 'post_install')
class TestPayWithGiftCard(TestSaleGiftCardCommon):

def test_paying_with_single_gift_card(self):
Expand Down
1 change: 0 additions & 1 deletion addons/website_sale_gift_card/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'data': [
'views/template.xml',
'views/gift_card_views.xml',
'views/product_views.xml',
'views/gift_card_menus.xml',
],
'demo': [
Expand Down
16 changes: 0 additions & 16 deletions addons/website_sale_gift_card/views/product_views.xml

This file was deleted.

0 comments on commit 1a89580

Please sign in to comment.