first commit

This commit is contained in:
root
2026-03-14 09:42:12 +00:00
commit 0adbd20c2c
10991 changed files with 1646955 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

View File

@@ -0,0 +1,184 @@
=======================
Sale Gift Card Scenario
=======================
Imports::
>>> from decimal import Decimal
>>> from unittest.mock import patch
>>> from proteus import Model, Report
>>> from trytond.modules.account.tests.tools import create_chart, get_accounts
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.modules.sale_gift_card import sale
>>> from trytond.tests.tools import activate_modules, assertEqual
Patch send_message_transactional::
>>> smtp_calls = patch.object(
... sale, 'send_message_transactional').start()
Activate modules::
>>> config = activate_modules('sale_gift_card', create_company, create_chart)
>>> Account = Model.get('account.account')
>>> AccountConfig = Model.get('account.configuration')
>>> GiftCard = Model.get('sale.gift_card')
>>> Party = Model.get('party.party')
>>> ProductCategory = Model.get('product.category')
>>> ProductTemplate = Model.get('product.template')
>>> ProductUoM = Model.get('product.uom')
>>> Sale = Model.get('sale.sale')
>>> SaleConfig = Model.get('sale.configuration')
>>> Sequence = Model.get('ir.sequence')
>>> SequenceType = Model.get('ir.sequence.type')
Get accounts::
>>> accounts = get_accounts()
Setup gift card accounting::
>>> gift_card_type, = accounts['payable'].type.duplicate(
... {'gift_card': True})
>>> gift_card_revenue = Account(name="Gift Card")
>>> gift_card_revenue.type = gift_card_type
>>> gift_card_revenue.deferral = True
>>> gift_card_revenue.save()
>>> account_config = AccountConfig(1)
>>> account_config.gift_card_account_revenue = gift_card_revenue
>>> account_config.save()
Set gift card sequence::
>>> sale_config = SaleConfig(1)
>>> gift_card_sequence = Sequence(name="Gift Card")
>>> gift_card_sequence.sequence_type, = SequenceType.find([
... ('name', '=', "Gift Card"),
... ])
>>> gift_card_sequence.type = 'hexadecimal timestamp'
>>> gift_card_sequence.save()
>>> sale_config.gift_card_sequence = gift_card_sequence
>>> sale_config.save()
Create gift card product::
>>> unit, = ProductUoM.find([('name', '=', "Unit")])
>>> template = ProductTemplate()
>>> template.name = "Gift Card"
>>> template.type = 'service'
>>> template.default_uom = unit
>>> template.salable = True
>>> template.gift_card = True
>>> template.list_price = Decimal('50')
>>> template.save()
>>> gift_card, = template.products
Create account category::
>>> account_category = ProductCategory(name="Account Category")
>>> account_category.accounting = True
>>> account_category.account_expense = accounts['expense']
>>> account_category.account_revenue = accounts['revenue']
>>> account_category.save()
Create a product::
>>> template = ProductTemplate()
>>> template.name = "Product"
>>> template.default_uom = unit
>>> template.salable = True
>>> template.list_price = Decimal('100')
>>> template.account_category = account_category
>>> template.save()
>>> product, = template.products
Create parties::
>>> customer1 = Party(name='Customer 1')
>>> customer1.save()
>>> customer2 = Party(name='Customer 2')
>>> customer2.save()
Sell 2 gift cards::
>>> sale = Sale()
>>> sale.party = customer1
>>> line = sale.lines.new()
>>> line.product = gift_card
>>> line.quantity = 2
>>> line.gift_card_email = "customer@example.com"
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.state
'processing'
Check gift cards::
>>> cards = GiftCard.find([])
>>> len(cards)
2
>>> card = cards[-1]
>>> assertEqual(card.product, gift_card)
>>> card.value
Decimal('50.00')
>>> bool(card.origin)
True
>>> bool(card.spent_on)
False
>>> smtp_calls.call_count
2
>>> msg, = smtp_calls.call_args[0]
>>> card.number in msg.get_body().get_content()
True
Print gift cards::
>>> gift_card_report = Report('sale.gift_card')
>>> bool(gift_card_report.execute([sale]))
True
Check invoice::
>>> invoice, = sale.invoices
>>> line, = invoice.lines
>>> assertEqual(line.account, gift_card_revenue)
Redeem a gift card to buy a product::
>>> sale = Sale()
>>> sale.party = customer2
>>> line = sale.lines.new()
>>> line.product = product
>>> line.quantity = 1
>>> sale.gift_cards.append(GiftCard(card.id))
>>> sale.save()
>>> sale.total_amount
Decimal('100.00')
>>> sale.click('quote')
>>> len(sale.lines)
2
>>> sale.total_amount
Decimal('50.00')
>>> sale.click('confirm')
>>> sale.state
'processing'
Check gift card::
>>> card.reload()
>>> assertEqual(card.spent_on, sale)
Check the invoice::
>>> invoice, = sale.invoices
>>> len(invoice.lines)
2
>>> invoice.total_amount
Decimal('50.00')
>>> gift_card_line, = [l for l in invoice.lines if l.product == gift_card]
>>> gift_card_line.quantity
-1.0
>>> assertEqual(gift_card_line.account, gift_card_revenue)

View File

@@ -0,0 +1,123 @@
=============================
Sale Gift Card Goods Scenario
=============================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.account.tests.tools import create_chart, get_accounts
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate modules::
>>> config = activate_modules('sale_gift_card', create_company, create_chart)
>>> Account = Model.get('account.account')
>>> AccountConfig = Model.get('account.configuration')
>>> GiftCard = Model.get('sale.gift_card')
>>> Party = Model.get('party.party')
>>> ProductCategory = Model.get('product.category')
>>> ProductTemplate = Model.get('product.template')
>>> ProductUoM = Model.get('product.uom')
>>> Sale = Model.get('sale.sale')
Get accounts::
>>> accounts = get_accounts()
Setup gift card accounting::
>>> gift_card_type, = accounts['payable'].type.duplicate(
... {'gift_card': True})
>>> gift_card_revenue = Account(name="Gift Card")
>>> gift_card_revenue.type = gift_card_type
>>> gift_card_revenue.deferral = True
>>> gift_card_revenue.save()
>>> account_config = AccountConfig(1)
>>> account_config.gift_card_account_revenue = gift_card_revenue
>>> account_config.save()
Create gift card product::
>>> unit, = ProductUoM.find([('name', '=', "Unit")])
>>> template = ProductTemplate()
>>> template.name = "Gift Card"
>>> template.type = 'goods'
>>> template.default_uom = unit
>>> template.salable = True
>>> template.gift_card = True
>>> template.list_price = Decimal('20')
>>> template.save()
>>> gift_card, = template.products
Create account category::
>>> account_category = ProductCategory(name="Account Category")
>>> account_category.accounting = True
>>> account_category.account_expense = accounts['expense']
>>> account_category.account_revenue = accounts['revenue']
>>> account_category.save()
Create a product::
>>> template = ProductTemplate()
>>> template.name = "Product"
>>> template.default_uom = unit
>>> template.salable = True
>>> template.list_price = Decimal('100')
>>> template.account_category = account_category
>>> template.save()
>>> product, = template.products
Create parties::
>>> customer1 = Party(name='Customer 1')
>>> customer1.save()
>>> customer2 = Party(name='Customer 2')
>>> customer2.save()
Sell 1 gift cards::
>>> sale = Sale()
>>> sale.party = customer1
>>> line = sale.lines.new()
>>> line.product = gift_card
>>> line.quantity = 1
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.state
'processing'
Check gift cards::
>>> cards = GiftCard.find([])
>>> len(cards)
0
Check invoice::
>>> invoice, = sale.invoices
>>> line, = invoice.lines
>>> assertEqual(line.account, gift_card_revenue)
Ship the gift card::
>>> shipment, = sale.shipments
>>> shipment.click('assign_force')
>>> shipment.click('pick')
>>> shipment.click('pack')
>>> shipment.click('do')
Traceback (most recent call last):
...
MoveGiftCardValidationError: ...
>>> move, = shipment.outgoing_moves
>>> gift_card = move.gift_cards.new(product=gift_card)
>>> gift_card.number = "1234"
>>> gift_card.value
Decimal('20.00')
>>> move.save()
>>> shipment.click('do')

View File

@@ -0,0 +1,214 @@
=============================
Sale Point Gift Card Scenario
=============================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model, Report
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, get_accounts)
>>> from trytond.modules.account_invoice.tests.tools import (
... set_fiscalyear_invoice_sequences)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate modules::
>>> config = activate_modules(
... ['sale_gift_card', 'sale_point'], create_company, create_chart)
>>> Account = Model.get('account.account')
>>> AccountConfig = Model.get('account.configuration')
>>> GiftCard = Model.get('sale.gift_card')
>>> Journal = Model.get('account.journal')
>>> Location = Model.get('stock.location')
>>> POS = Model.get('sale.point')
>>> PaymentMethod = Model.get('sale.point.payment.method')
>>> ProductCategory = Model.get('product.category')
>>> ProductTemplate = Model.get('product.template')
>>> ProductUoM = Model.get('product.uom')
>>> Sale = Model.get('sale.point.sale')
>>> SaleConfig = Model.get('sale.configuration')
>>> Sequence = Model.get('ir.sequence')
>>> SequenceStrict = Model.get('ir.sequence.strict')
>>> SequenceType = Model.get('ir.sequence.type')
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
>>> fiscalyear.click('create_period')
Get accounts::
>>> accounts = get_accounts()
Setup gift card accounting::
>>> gift_card_type, = accounts['payable'].type.duplicate(
... {'gift_card': True})
>>> gift_card_revenue = Account(name="Gift Card")
>>> gift_card_revenue.type = gift_card_type
>>> gift_card_revenue.deferral = True
>>> gift_card_revenue.save()
>>> account_config = AccountConfig(1)
>>> account_config.gift_card_account_revenue = gift_card_revenue
>>> account_config.save()
Set gift card sequence::
>>> sale_config = SaleConfig(1)
>>> gift_card_sequence = Sequence(name="Gift Card")
>>> gift_card_sequence.sequence_type, = SequenceType.find([
... ('name', '=', "Gift Card"),
... ])
>>> gift_card_sequence.type = 'hexadecimal timestamp'
>>> gift_card_sequence.save()
>>> sale_config.gift_card_sequence = gift_card_sequence
>>> sale_config.save()
Create gift card product::
>>> unit, = ProductUoM.find([('name', '=', "Unit")])
>>> template = ProductTemplate()
>>> template.name = "Gift Card"
>>> template.type = 'service'
>>> template.default_uom = unit
>>> template.salable = True
>>> template.gift_card = True
>>> template.list_price = Decimal('50')
>>> template.save()
>>> gift_card_product, = template.products
Create account category::
>>> account_category = ProductCategory(name="Account Category")
>>> account_category.accounting = True
>>> account_category.account_revenue = accounts['revenue']
>>> account_category.save()
Create product::
>>> unit, = ProductUoM.find([('name', '=', 'Unit')])
>>> template = ProductTemplate()
>>> template.name = 'product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.salable = True
>>> template.account_category = account_category
>>> template.gross_price = Decimal('50.0000')
>>> template.save()
>>> product, = template.products
Get journal::
>>> journal_revenue, = Journal.find([('type', '=', 'revenue')], limit=1)
Get stock locations::
>>> storage_loc, = Location.find([('code', '=', 'STO')])
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
Create POS::
>>> pos = POS(name="POS")
>>> pos.journal = journal_revenue
>>> pos.sequence = SequenceStrict(name="POS", company=pos.company)
>>> pos.sequence.sequence_type, = SequenceType.find(
... [('name', '=', "POS")], limit=1)
>>> pos.sequence.save()
>>> pos.storage_location = storage_loc
>>> pos.customer_location = customer_loc
>>> pos.save()
Create a payment method::
>>> payment_method = PaymentMethod(name="Cash")
>>> payment_method.account = accounts['cash']
>>> payment_method.save()
Make a sale::
>>> sale = Sale(point=pos)
>>> line = sale.lines.new()
>>> line.product = product
>>> line.quantity = 10
>>> sale.save()
>>> sale.total
Decimal('500.00')
Overpay::
>>> payment = sale.click('pay')
>>> payment.form.method = payment_method
>>> payment.form.amount = Decimal('600.00')
>>> payment.execute('pay')
>>> payment.form.amount
Decimal('-100.00')
Return change with a gift card::
>>> payment.execute('gift_card')
>>> payment.form.product = gift_card_product
>>> payment.form.amount
Decimal('100.00')
>>> payment.execute('add_gift_card')
>>> sale.state
'done'
Check gift card::
>>> gift_card, = GiftCard.find([])
>>> gift_card.value
Decimal('100.00')
>>> assertEqual(gift_card.currency, sale.currency)
Print gift card::
>>> gift_card_report = Report('sale.gift_card')
>>> bool(gift_card_report.execute([sale]))
True
Post sale::
>>> sale.click('post')
>>> sale.state
'posted'
Make a second sale and pay with gift card::
>>> sale = Sale(point=pos)
>>> line = sale.lines.new()
>>> line.product = product
>>> line.quantity = 5
>>> sale.gift_cards.append(GiftCard(gift_card.id))
>>> sale.save()
>>> sale.total
Decimal('150.00')
Pay::
>>> payment = sale.click('pay')
>>> payment.form.method = payment_method
>>> payment.execute('pay')
>>> sale.state
'done'
>>> sale.total
Decimal('150.00')
Check gift card::
>>> gift_card.reload()
>>> assertEqual(gift_card.spent_on, sale)
Post sale::
>>> sale.click('post')
>>> sale.state
'posted'

View File

@@ -0,0 +1,14 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.modules.company.tests import CompanyTestMixin
from trytond.tests.test_tryton import ModuleTestCase
class SaleGiftCardTestCase(CompanyTestMixin, ModuleTestCase):
'Test Sale Gift Card module'
module = 'sale_gift_card'
extras = ['sale_point']
del ModuleTestCase

View File

@@ -0,0 +1,8 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.tests.test_tryton import load_doc_tests
def load_tests(*args, **kwargs):
return load_doc_tests(__name__, __file__, *args, **kwargs)