first commit
This commit is contained in:
2
modules/sale_complaint/tests/__init__.py
Normal file
2
modules/sale_complaint/tests/__init__.py
Normal 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.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
277
modules/sale_complaint/tests/scenario_sale_complaint.rst
Normal file
277
modules/sale_complaint/tests/scenario_sale_complaint.rst
Normal file
@@ -0,0 +1,277 @@
|
||||
=======================
|
||||
Sale Complaint Scenario
|
||||
=======================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... create_payment_term, set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('sale_complaint', create_company, create_chart)
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create complaint type::
|
||||
|
||||
>>> Type = Model.get('sale.complaint.type')
|
||||
>>> IrModel = Model.get('ir.model')
|
||||
>>> sale_type = Type(name='Sale')
|
||||
>>> sale_type.origin, = IrModel.find([('name', '=', 'sale.sale')])
|
||||
>>> sale_type.save()
|
||||
>>> sale_line_type = Type(name='Sale Line')
|
||||
>>> sale_line_type.origin, = IrModel.find([('name', '=', 'sale.line')])
|
||||
>>> sale_line_type.save()
|
||||
>>> invoice_type = Type(name='Invoice')
|
||||
>>> invoice_type.origin, = IrModel.find(
|
||||
... [('name', '=', 'account.invoice')])
|
||||
>>> invoice_type.save()
|
||||
>>> invoice_line_type = Type(name='Invoice Line')
|
||||
>>> invoice_line_type.origin, = IrModel.find(
|
||||
... [('name', '=', 'account.invoice.line')])
|
||||
>>> invoice_line_type.save()
|
||||
|
||||
Create account category::
|
||||
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = expense
|
||||
>>> account_category.account_revenue = revenue
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Create payment term::
|
||||
|
||||
>>> payment_term = create_payment_term()
|
||||
>>> payment_term.save()
|
||||
|
||||
Sale 5 products::
|
||||
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale.invoice_method = 'order'
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 3
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 2
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('50.00')
|
||||
|
||||
Post the invoice::
|
||||
|
||||
>>> invoice, = sale.invoices
|
||||
>>> invoice.click('post')
|
||||
|
||||
Create a complaint to return the sale::
|
||||
|
||||
>>> Complaint = Model.get('sale.complaint')
|
||||
>>> complaint = Complaint()
|
||||
>>> complaint.customer = customer
|
||||
>>> complaint.type = sale_type
|
||||
>>> complaint.origin = sale
|
||||
>>> action = complaint.actions.new()
|
||||
>>> action.action = 'sale_return'
|
||||
>>> action.amount
|
||||
Decimal('50.00')
|
||||
>>> complaint.save()
|
||||
>>> complaint.state
|
||||
'draft'
|
||||
>>> complaint.click('wait')
|
||||
>>> complaint.state
|
||||
'waiting'
|
||||
>>> complaint.click('approve')
|
||||
>>> complaint.state
|
||||
'done'
|
||||
>>> action, = complaint.actions
|
||||
>>> return_sale = action.result
|
||||
>>> len(return_sale.lines)
|
||||
2
|
||||
>>> sum(l.quantity for l in return_sale.lines)
|
||||
-5.0
|
||||
|
||||
Create a complaint to return partially the sale::
|
||||
|
||||
>>> Complaint = Model.get('sale.complaint')
|
||||
>>> complaint = Complaint()
|
||||
>>> complaint.customer = customer
|
||||
>>> complaint.type = sale_type
|
||||
>>> complaint.origin = sale
|
||||
>>> action = complaint.actions.new()
|
||||
>>> action.action = 'sale_return'
|
||||
>>> sale_line = action.sale_lines.new()
|
||||
>>> sale_line.line = sale.lines[0]
|
||||
>>> sale_line.quantity = 1
|
||||
>>> sale_line.unit_price = Decimal('5')
|
||||
>>> sale_line = action.sale_lines.new()
|
||||
>>> sale_line.line = sale.lines[1]
|
||||
>>> action.amount
|
||||
Decimal('25.00')
|
||||
>>> complaint.save()
|
||||
>>> complaint.state
|
||||
'draft'
|
||||
>>> complaint.click('wait')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ComplaintSimilarWarning: ...
|
||||
>>> config.skip_warning = True
|
||||
>>> complaint.click('wait')
|
||||
>>> complaint.state
|
||||
'waiting'
|
||||
>>> complaint.click('approve')
|
||||
>>> complaint.state
|
||||
'done'
|
||||
>>> action, = complaint.actions
|
||||
>>> return_sale = action.result
|
||||
>>> len(return_sale.lines)
|
||||
2
|
||||
>>> sum(l.quantity for l in return_sale.lines)
|
||||
-3.0
|
||||
>>> return_sale.total_amount
|
||||
Decimal('-25.00')
|
||||
|
||||
Create a complaint to return a sale line::
|
||||
|
||||
>>> complaint = Complaint()
|
||||
>>> complaint.customer = customer
|
||||
>>> complaint.type = sale_line_type
|
||||
>>> complaint.origin = sale.lines[0]
|
||||
>>> action = complaint.actions.new()
|
||||
>>> action.action = 'sale_return'
|
||||
>>> action.quantity = 1
|
||||
>>> action.amount
|
||||
Decimal('10.00')
|
||||
>>> complaint.click('wait')
|
||||
>>> complaint.click('approve')
|
||||
>>> complaint.state
|
||||
'done'
|
||||
>>> action, = complaint.actions
|
||||
>>> return_sale = action.result
|
||||
>>> return_line, = return_sale.lines
|
||||
>>> return_line.quantity
|
||||
-1.0
|
||||
|
||||
Create a complaint to credit the invoice::
|
||||
|
||||
>>> complaint = Complaint()
|
||||
>>> complaint.customer = customer
|
||||
>>> complaint.type = invoice_type
|
||||
>>> complaint.origin = invoice
|
||||
>>> action = complaint.actions.new()
|
||||
>>> action.action = 'credit_note'
|
||||
>>> action.amount
|
||||
Decimal('50.00')
|
||||
>>> complaint.click('wait')
|
||||
>>> complaint.click('approve')
|
||||
>>> complaint.state
|
||||
'done'
|
||||
>>> action, = complaint.actions
|
||||
>>> credit_note = action.result
|
||||
>>> credit_note.type
|
||||
'out'
|
||||
>>> len(credit_note.lines)
|
||||
4
|
||||
>>> sum(l.quantity for l in credit_note.lines)
|
||||
0.0
|
||||
>>> credit_note.total_amount
|
||||
Decimal('-50.00')
|
||||
|
||||
Create a complaint to credit partially the invoice::
|
||||
|
||||
>>> complaint = Complaint()
|
||||
>>> complaint.customer = customer
|
||||
>>> complaint.type = invoice_type
|
||||
>>> complaint.origin = invoice
|
||||
>>> action = complaint.actions.new()
|
||||
>>> action.action = 'credit_note'
|
||||
>>> invoice_line = action.invoice_lines.new()
|
||||
>>> invoice_line.line = invoice.lines[0]
|
||||
>>> invoice_line.quantity = 1
|
||||
>>> invoice_line.unit_price = Decimal('5')
|
||||
>>> invoice_line = action.invoice_lines.new()
|
||||
>>> invoice_line.line = invoice.lines[1]
|
||||
>>> invoice_line.quantity = 1
|
||||
>>> action.amount
|
||||
Decimal('15.00')
|
||||
>>> complaint.click('wait')
|
||||
>>> complaint.click('approve')
|
||||
>>> complaint.state
|
||||
'done'
|
||||
>>> action, = complaint.actions
|
||||
>>> credit_note = action.result
|
||||
>>> credit_note.type
|
||||
'out'
|
||||
>>> len(credit_note.lines)
|
||||
4
|
||||
>>> sum(l.quantity for l in credit_note.lines)
|
||||
0.0
|
||||
>>> credit_note.total_amount
|
||||
Decimal('-15.00')
|
||||
|
||||
Create a complaint to credit a invoice line::
|
||||
|
||||
>>> complaint = Complaint()
|
||||
>>> complaint.customer = customer
|
||||
>>> complaint.type = invoice_line_type
|
||||
>>> complaint.origin = invoice.lines[0]
|
||||
>>> action = complaint.actions.new()
|
||||
>>> action.action = 'credit_note'
|
||||
>>> action.quantity = 1
|
||||
>>> action.amount
|
||||
Decimal('10.00')
|
||||
>>> complaint.click('wait')
|
||||
>>> complaint.click('approve')
|
||||
>>> complaint.state
|
||||
'done'
|
||||
>>> action, = complaint.actions
|
||||
>>> credit_note = action.result
|
||||
>>> credit_note.type
|
||||
'out'
|
||||
>>> len(credit_note.lines)
|
||||
2
|
||||
>>> sum(l.quantity for l in credit_note.lines)
|
||||
0.0
|
||||
@@ -0,0 +1,122 @@
|
||||
=============================================
|
||||
Sale Complaint with Promotion Coupon Scenario
|
||||
=============================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> 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_complaint', 'sale_promotion_coupon'],
|
||||
... create_company, create_chart)
|
||||
|
||||
>>> Complaint = Model.get('sale.complaint')
|
||||
>>> IrModel = Model.get('ir.model')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> Promotion = Model.get('sale.promotion')
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> Type = Model.get('sale.complaint.type')
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create complaint type::
|
||||
|
||||
>>> sale_type = Type(name='Sale')
|
||||
>>> sale_type.origin, = IrModel.find([('name', '=', 'sale.sale')])
|
||||
>>> sale_type.save()
|
||||
|
||||
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.list_price = Decimal('10')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Create Promotion with coupon::
|
||||
|
||||
>>> promotion = Promotion(name="50%")
|
||||
>>> promotion.formula = '0.5 * unit_price'
|
||||
>>> coupon = promotion.coupons.new()
|
||||
>>> coupon.number_of_use = 1
|
||||
>>> coupon.per_party = False
|
||||
>>> promotion.save()
|
||||
>>> coupon, = promotion.coupons
|
||||
|
||||
Sale 1 product::
|
||||
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 1
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.state
|
||||
'processing'
|
||||
|
||||
Fill a complaint for the sale::
|
||||
|
||||
>>> complaint = Complaint()
|
||||
>>> complaint.customer = customer
|
||||
>>> complaint.type = sale_type
|
||||
>>> complaint.origin = sale
|
||||
>>> complaint.save()
|
||||
|
||||
Resolve complaint with a coupon::
|
||||
|
||||
>>> action = complaint.actions.new(action='promotion_coupon')
|
||||
>>> action.promotion_coupon = coupon
|
||||
>>> action.promotion_coupon_number = "DISC50"
|
||||
>>> action.promotion_coupon_duration = dt.timedelta(days=30)
|
||||
>>> complaint.click('wait')
|
||||
>>> complaint.click('approve')
|
||||
>>> complaint.state
|
||||
'done'
|
||||
|
||||
>>> action, = complaint.actions
|
||||
>>> coupon_number = action.result
|
||||
>>> coupon_number.number
|
||||
'DISC50'
|
||||
>>> assertEqual(coupon_number.coupon, coupon)
|
||||
>>> assertEqual(
|
||||
... coupon_number.end_date - coupon_number.start_date, dt.timedelta(days=30))
|
||||
14
modules/sale_complaint/tests/test_module.py
Normal file
14
modules/sale_complaint/tests/test_module.py
Normal 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 SaleComplaintTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Sale Complaint module'
|
||||
module = 'sale_complaint'
|
||||
extras = ['sale_promotion_coupon']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/sale_complaint/tests/test_scenario.py
Normal file
8
modules/sale_complaint/tests/test_scenario.py
Normal 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)
|
||||
Reference in New Issue
Block a user