diff --git a/addons/sale_gift_card/__init__.py b/addons/sale_gift_card/__init__.py deleted file mode 100644 index dc5e6b693d1..00000000000 --- a/addons/sale_gift_card/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from . import models diff --git a/addons/sale_gift_card/__manifest__.py b/addons/sale_gift_card/__manifest__.py deleted file mode 100644 index 328f215e89e..00000000000 --- a/addons/sale_gift_card/__manifest__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -{ - 'name': "Gift Card for sales module", - 'summary': "Use gift card in your sales orders", - 'description': """Integrate gift card mechanism in sales orders.""", - 'category': 'Sales/Sales', - 'version': '1.0', - 'depends': ['gift_card', 'sale'], - 'auto_install': True, - 'data': [ - 'data/gift_card_data.xml', - 'data/mail_template_data.xml', - 'views/sale_order_view.xml', - 'views/templates.xml', - 'security/ir.model.access.csv', - ], - 'license': 'LGPL-3', -} diff --git a/addons/sale_gift_card/data/gift_card_data.xml b/addons/sale_gift_card/data/gift_card_data.xml deleted file mode 100644 index 1830684c64e..00000000000 --- a/addons/sale_gift_card/data/gift_card_data.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/addons/sale_gift_card/data/mail_template_data.xml b/addons/sale_gift_card/data/mail_template_data.xml deleted file mode 100644 index a0008743532..00000000000 --- a/addons/sale_gift_card/data/mail_template_data.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - Gift Card: Send by Email - - Your Gift Card - {{ object.partner_id.id or object.buy_line_id.order_id.partner_id.id }} - -
- Here is your gift card! -
-
- -
-
-

- $ 150.00

-
-
-

- Gift Card Code -

-

4f10-15d6-41b7-b04c-7b3e

-
-
-

Card expires 05/05/2021

-
-
- - Use it right now! - -
-
- -
-
diff --git a/addons/sale_gift_card/i18n/sale_gift_card.pot b/addons/sale_gift_card/i18n/sale_gift_card.pot deleted file mode 100644 index 616156b152d..00000000000 --- a/addons/sale_gift_card/i18n/sale_gift_card.pot +++ /dev/null @@ -1,158 +0,0 @@ -# Translation of Odoo Server. -# This file contains the translation of the following modules: -# * sale_gift_card -# -msgid "" -msgstr "" -"Project-Id-Version: Odoo Server 15.0\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-05 10:54+0000\n" -"PO-Revision-Date: 2021-10-05 10:54+0000\n" -"Last-Translator: \n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: \n" - -#. module: sale_gift_card -#: model:mail.template,body_html:sale_gift_card.mail_template_gift_card -msgid "" -"
\n" -" Here is your gift card!\n" -"
\n" -"
\n" -" \n" -"
\n" -"
\n" -"

\n" -" $ 150.00

\n" -"
\n" -"
\n" -"

\n" -" Gift Card Code\n" -"

\n" -"

4f10-15d6-41b7-b04c-7b3e

\n" -"
\n" -"
\n" -"

Card expires 05/05/2021

\n" -"
\n" -"
\n" -" \n" -" Use it right now!\n" -" \n" -"
\n" -" " -msgstr "" - -#. module: sale_gift_card -#: model_terms:ir.ui.view,arch_db:sale_gift_card.sale_purchased_gift_card -msgid " Copy" -msgstr "" - -#. module: sale_gift_card -#: model:ir.model.fields,field_description:sale_gift_card.field_sale_order_line__generated_gift_card_ids -msgid "Bought Gift Card" -msgstr "" - -#. module: sale_gift_card -#: model:ir.model.fields,field_description:sale_gift_card.field_gift_card__buy_line_id -msgid "Buy Line" -msgstr "" - -#. module: sale_gift_card -#: model_terms:ir.ui.view,arch_db:sale_gift_card.used_gift_card -msgid "Code:" -msgstr "" - -#. module: sale_gift_card -#: model:ir.model.fields,help:sale_gift_card.field_sale_order_line__gift_card_id -msgid "Deducted from this Gift Card" -msgstr "" - -#. module: sale_gift_card -#: model_terms:ir.ui.view,arch_db:sale_gift_card.used_gift_card -msgid "Expired Date:" -msgstr "" - -#. module: sale_gift_card -#: model_terms:ir.ui.view,arch_db:sale_gift_card.sale_purchased_gift_card -msgid "Gift #" -msgstr "" - -#. module: sale_gift_card -#: model:ir.model,name:sale_gift_card.model_gift_card -#: model:ir.model.fields,field_description:sale_gift_card.field_sale_order_line__gift_card_id -msgid "Gift Card" -msgstr "" - -#. module: sale_gift_card -#: model_terms:ir.ui.view,arch_db:sale_gift_card.sale_purchased_gift_card -msgid "Gift Card Code" -msgstr "" - -#. module: sale_gift_card -#: model:ir.model.fields,field_description:sale_gift_card.field_sale_order__gift_card_count -msgid "Gift Card Count" -msgstr "" - -#. module: sale_gift_card -#: code:addons/sale_gift_card/models/sale_order.py:0 -#, python-format -msgid "Gift Card already used." -msgstr "" - -#. module: sale_gift_card -#: code:addons/sale_gift_card/models/sale_order.py:0 -#, python-format -msgid "Gift Card are restricted for another user." -msgstr "" - -#. module: sale_gift_card -#: model:mail.template,name:sale_gift_card.mail_template_gift_card -msgid "Gift Card: Send by Email" -msgstr "" - -#. module: sale_gift_card -#: model:ir.actions.act_window,name:sale_gift_card.gift_card_sale_order_action -#: model_terms:ir.ui.view,arch_db:sale_gift_card.sale_order_view_extend_gift_card_form -msgid "Gift Cards" -msgstr "" - -#. module: sale_gift_card -#: code:addons/sale_gift_card/models/sale_order.py:0 -#, python-format -msgid "Invalid or Expired Gift Card." -msgstr "" - -#. module: sale_gift_card -#: model:ir.model.fields,field_description:sale_gift_card.field_gift_card__redeem_line_ids -msgid "Redeems" -msgstr "" - -#. module: sale_gift_card -#: model:ir.model.fields,help:sale_gift_card.field_gift_card__buy_line_id -msgid "Sale Order line where this gift card has been bought." -msgstr "" - -#. module: sale_gift_card -#: model:ir.model,name:sale_gift_card.model_sale_order -msgid "Sales Order" -msgstr "" - -#. module: sale_gift_card -#: model:ir.model,name:sale_gift_card.model_sale_order_line -msgid "Sales Order Line" -msgstr "" - -#. module: sale_gift_card -#: model_terms:ir.ui.view,arch_db:sale_gift_card.sale_purchased_gift_card -msgid "" -"You will find below your gift cards code. An email has been sent with it. " -"You can use it starting right now." -msgstr "" - -#. module: sale_gift_card -#: model:mail.template,subject:sale_gift_card.mail_template_gift_card -msgid "Your Gift Card" -msgstr "" diff --git a/addons/sale_gift_card/models/__init__.py b/addons/sale_gift_card/models/__init__.py deleted file mode 100644 index 733bcda9ea8..00000000000 --- a/addons/sale_gift_card/models/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from . import gift_card -from . import sale_order diff --git a/addons/sale_gift_card/models/gift_card.py b/addons/sale_gift_card/models/gift_card.py deleted file mode 100644 index 8bc5568b741..00000000000 --- a/addons/sale_gift_card/models/gift_card.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import api, fields, models - - -class GiftCard(models.Model): - _inherit = "gift.card" - - buy_line_id = fields.Many2one("sale.order.line", copy=False, readonly=True, - help="Sale Order line where this gift card has been bought.") - redeem_line_ids = fields.One2many('sale.order.line', 'gift_card_id', string="Redeems") - - @api.depends("redeem_line_ids") - def _compute_balance(self): - super()._compute_balance() - for record in self: - confirmed_line = record.redeem_line_ids.filtered(lambda l: l.state in ('sale', 'done')) - balance = record.balance - if confirmed_line: - balance -= sum(confirmed_line.mapped( - lambda line: line.currency_id._convert(line.price_unit, record.currency_id, record.env.company, line.create_date) * -1 - )) - record.balance = balance diff --git a/addons/sale_gift_card/models/sale_order.py b/addons/sale_gift_card/models/sale_order.py deleted file mode 100644 index 5237ce90425..00000000000 --- a/addons/sale_gift_card/models/sale_order.py +++ /dev/null @@ -1,103 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import _, api, fields, models - - -class SaleOrder(models.Model): - _inherit = "sale.order" - - gift_card_count = fields.Integer(compute="_compute_gift_card_count") - - @api.depends("order_line.generated_gift_card_ids") - def _compute_gift_card_count(self): - for record in self: - record.gift_card_count = len(record.order_line.mapped("generated_gift_card_ids")) - - @api.constrains('state') - def _constrains_state(self): - # release gift card amount when order state become canceled - for record in self.filtered(lambda so: so.state == 'cancel'): - record.order_line.filtered(lambda ol: ol.gift_card_id).unlink() - - # 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.detailed_type == 'gift'): - gift_card_order_line._create_gift_cards() - record.sudo()._send_gift_card_mail() - - def _pay_with_gift_card(self, gift_card): - error = False - - if not gift_card.can_be_used(): - error = _('Invalid or Expired Gift Card.') - elif gift_card in self.order_line.mapped("gift_card_id"): - error = _('Gift Card already used.') - elif gift_card.partner_id and gift_card.partner_id != self.env.user.partner_id: - error = _('Gift Card are restricted for another user.') - - amount = min(self.amount_total, gift_card.balance_converted(self.currency_id)) - if not error and amount > 0: - pay_gift_card_id = self.env.ref('gift_card.pay_with_gift_card_product') - gift_card.redeem_line_ids.filtered(lambda redeem: redeem.state != "sale").unlink() - self.env["sale.order.line"].create({ - 'product_id': pay_gift_card_id.id, - 'price_unit': - amount, - 'gift_card_id': gift_card.id, - 'order_id': self.id - }) - return error - - def _send_gift_card_mail(self): - template = self.env.ref('sale_gift_card.mail_template_gift_card', raise_if_not_found=False) - if template and self.gift_card_count: - for gift in self.order_line.mapped("generated_gift_card_ids"): - template.send_mail(gift.id, force_send=True, email_layout_xmlid='mail.mail_notification_light') - - def _recompute_gift_card_lines(self): - for record in self: - lines_to_remove = self.env['sale.order.line'] - lines_to_update = [] - - gift_payment_lines = record.order_line.filtered('gift_card_id') - to_pay = sum((self.order_line - gift_payment_lines).mapped('price_total')) - - # consume older gift card first - for gift_card_line in gift_payment_lines.sorted(lambda line: line.gift_card_id.expired_date): - amount = min(to_pay, gift_card_line.gift_card_id.balance_converted(record.currency_id)) - if amount: - to_pay -= amount - if gift_card_line.price_unit != -amount or gift_card_line.product_uom_qty != 1: - lines_to_update.append( - fields.Command.update(gift_card_line.id, {'price_unit': -amount, 'product_uom_qty': 1}) - ) - else: - lines_to_remove += gift_card_line - lines_to_remove.unlink() - record.update({'order_line': lines_to_update}) - - -class SaleOrderLine(models.Model): - _inherit = "sale.order.line" - - generated_gift_card_ids = fields.One2many('gift.card', "buy_line_id", string="Bought Gift Card") - gift_card_id = fields.Many2one('gift.card', help="Deducted from this Gift Card", copy=False) - - def _is_not_sellable_line(self): - return self.gift_card_id or super()._is_not_sellable_line() - - def _create_gift_cards(self): - return self.env['gift.card'].create( - [self._build_gift_card() for _ in range(int(self.product_uom_qty))] - ) - - def _build_gift_card(self): - return { - 'initial_amount': self.order_id.currency_id._convert( - self.price_unit, - self.order_id.env.company.currency_id, - self.order_id.env.company, - fields.Date.today() - ), - 'buy_line_id': self.id, - } diff --git a/addons/sale_gift_card/security/ir.model.access.csv b/addons/sale_gift_card/security/ir.model.access.csv deleted file mode 100644 index 99bb48e912b..00000000000 --- a/addons/sale_gift_card/security/ir.model.access.csv +++ /dev/null @@ -1,3 +0,0 @@ -id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink -access_gift_card_sales,Gift Card Program Salesman,model_gift_card,sales_team.group_sale_salesman,1,0,0,0 -access_gift_card_manager,Gift Card Program Sale Manager,model_gift_card,sales_team.group_sale_manager,1,1,1,1 diff --git a/addons/sale_gift_card/tests/__init__.py b/addons/sale_gift_card/tests/__init__.py deleted file mode 100644 index f068a01afad..00000000000 --- a/addons/sale_gift_card/tests/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from . import test_buy_gift_card -from . import test_pay_with_gift_card diff --git a/addons/sale_gift_card/tests/common.py b/addons/sale_gift_card/tests/common.py deleted file mode 100644 index dd138295c36..00000000000 --- a/addons/sale_gift_card/tests/common.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo.addons.sale.tests.test_sale_product_attribute_value_config import TestSaleProductAttributeValueCommon - - -class TestSaleGiftCardCommon(TestSaleProductAttributeValueCommon): - - @classmethod - def setUpClass(cls): - super().setUpClass() - - # set currency to not rely on demo data and avoid possible race condition - cls.currency_ratio = 1.0 - pricelist = cls.env.ref("product.list0") - pricelist.currency_id = cls._setup_currency(cls.currency_ratio) - - - # create partner for sale order. - cls.fatima = cls.env['res.partner'].create({ - 'name': 'Fatima Kalai', - 'email': 'fatima.kalai@example.com', - }) - - cls.empty_order = cls.env['sale.order'].create({ - 'partner_id': cls.fatima.id - }) - - cls.uom_unit = cls.env.ref('uom.product_uom_unit') - - # Taxes - cls.tax_15pc_excl = cls.env['account.tax'].create({ - 'name': "Tax 15%", - 'amount_type': 'percent', - 'amount': 15, - 'type_tax_use': 'sale', - }) - - #products - cls.product_A = cls.env['product.product'].create({ - 'name': 'Product A', - 'list_price': 100, - 'sale_ok': True, - 'taxes_id': [(6, 0, [cls.tax_15pc_excl.id])], - }) - 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, - }) diff --git a/addons/sale_gift_card/tests/test_buy_gift_card.py b/addons/sale_gift_card/tests/test_buy_gift_card.py deleted file mode 100644 index b426e844da4..00000000000 --- a/addons/sale_gift_card/tests/test_buy_gift_card.py +++ /dev/null @@ -1,62 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -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): - order = self.empty_order - order.write({'order_line': [ - (0, False, { - 'product_id': self.product_A.id, - 'name': 'Ordinary Product A', - 'product_uom': self.uom_unit.id, - 'product_uom_qty': 1.0, - }), - (0, False, { - 'product_id': self.product_gift_card.id, - 'name': 'Gift Card Product', - 'product_uom': self.uom_unit.id, - 'product_uom_qty': 1.0, - }) - ]}) - self.assertEqual(len(order.order_line.ids), 2) - self.assertEqual(order.gift_card_count, 0) - self.assertEqual(len(order.order_line.mapped('generated_gift_card_ids')), 0) - order.action_confirm() - # After Confirmation - self.assertEqual(order.gift_card_count, 1) - self.assertEqual(len(order.order_line.mapped('generated_gift_card_ids')), 1) - - def test_buying_multiple_gift_card(self): - order = self.empty_order - order.write({'order_line': [ - Command.create({ - 'product_id': self.product_A.id, - 'name': 'Ordinary Product A', - 'product_uom': self.uom_unit.id, - 'product_uom_qty': 1.0, - }), - Command.create({ - 'product_id': self.product_gift_card.id, - 'name': 'Gift Card Product', - 'product_uom': self.uom_unit.id, - 'product_uom_qty': 1.0, - }), - Command.create({ - 'product_id': self.product_gift_card.id, - 'name': 'Gift Card Product', - 'product_uom': self.uom_unit.id, - 'product_uom_qty': 1.0, - }) - ]}) - self.assertEqual(order.gift_card_count, 0) - self.assertEqual(len(order.order_line.mapped('generated_gift_card_ids')), 0) - order.action_confirm() - # After Confirmation - self.assertEqual(order.gift_card_count, 2) - self.assertEqual(len(order.order_line.mapped('generated_gift_card_ids')), 2) diff --git a/addons/sale_gift_card/tests/test_pay_with_gift_card.py b/addons/sale_gift_card/tests/test_pay_with_gift_card.py deleted file mode 100644 index e0d16065288..00000000000 --- a/addons/sale_gift_card/tests/test_pay_with_gift_card.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -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): - gift_card = self.env['gift.card'].create({ - 'initial_amount': 100, - }) - order = self.empty_order - order.write({'order_line': [ - Command.create({ - 'product_id': self.product_A.id, - 'name': 'Ordinary Product A', - 'product_uom': self.uom_unit.id, - 'product_uom_qty': 1.0, - }) - ]}) - before_gift_card_payment = order.amount_total - self.assertNotEqual(before_gift_card_payment, 0) - order._pay_with_gift_card(gift_card) - order.action_confirm() - self.assertEqual(before_gift_card_payment - order.amount_total, gift_card.initial_amount - gift_card.balance) - - def test_paying_with_multiple_gift_card(self): - gift_card_1 = self.env['gift.card'].create({ - 'initial_amount': 100, - }) - gift_card_2 = self.env['gift.card'].create({ - 'initial_amount': 100, - }) - order = self.empty_order - order.write({'order_line': [ - Command.create({ - 'product_id': self.product_A.id, - 'name': 'Ordinary Product A', - 'product_uom': self.uom_unit.id, - 'product_uom_qty': 20.0, - }) - ]}) - before_gift_card_payment = order.amount_total - order._pay_with_gift_card(gift_card_1) - order._pay_with_gift_card(gift_card_2) - self.assertEqual(order.amount_total, before_gift_card_payment - 200) - - def test_unlink_gift_card_product(self): - with self.assertRaises(UserError): - # try to delete several product including pay_with_gift_card_product - self.env['product.template'].search([('purchase_ok', '=', False), ('sale_ok', '=', False)]).unlink() diff --git a/addons/sale_gift_card/views/sale_order_view.xml b/addons/sale_gift_card/views/sale_order_view.xml deleted file mode 100644 index 4c5afdab155..00000000000 --- a/addons/sale_gift_card/views/sale_order_view.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - Gift Cards - gift.card - tree,form - [('buy_line_id.order_id', '=', active_id)] - - - - sale.order.view.form.inherit.gift.card - sale.order - - - - - - - - - - gift.card.form Website - gift.card - - - - - - - - - - - - - - - - - diff --git a/addons/sale_gift_card/views/templates.xml b/addons/sale_gift_card/views/templates.xml deleted file mode 100644 index 45f0e65051b..00000000000 --- a/addons/sale_gift_card/views/templates.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - -