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,176 @@
=========================
Sale Opportunity Scenario
=========================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_tax, get_accounts)
>>> from trytond.modules.account_invoice.tests.tools import create_payment_term
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate modules::
>>> config = activate_modules('sale_opportunity', create_company, create_chart)
>>> Sale = Model.get('sale.sale')
>>> Employee = Model.get('company.employee')
>>> Party = Model.get('party.party')
Create employee::
>>> employee_party = Party(name="Employee")
>>> employee_party.save()
>>> employee = Employee(party=employee_party)
>>> employee.save()
Get accounts::
>>> accounts = get_accounts()
>>> revenue = accounts['revenue']
Create tax::
>>> tax = create_tax(Decimal('.10'))
>>> tax.save()
Create party::
>>> Party = Model.get('party.party')
>>> customer = Party(name='Customer')
>>> customer.save()
Create account category::
>>> ProductCategory = Model.get('product.category')
>>> account_category = ProductCategory(name="Account Category")
>>> account_category.accounting = True
>>> account_category.account_revenue = revenue
>>> account_category.customer_taxes.append(tax)
>>> 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()
Create an lead::
>>> Opportunity = Model.get('sale.opportunity')
>>> opportunity = Opportunity()
>>> opportunity.description = 'Opportunity'
>>> opportunity.save()
>>> opportunity.state
'lead'
Convert to opportunity::
>>> opportunity.party = customer
>>> opportunity.address, = customer.addresses
>>> opportunity.payment_term = payment_term
>>> opportunity.amount = Decimal(100)
>>> opportunity.employee = employee
>>> opportunity.click('opportunity')
>>> opportunity.state
'opportunity'
Add a line::
>>> line = opportunity.lines.new()
>>> line.product = product
>>> line.quantity = 10
>>> opportunity.save()
Convert to sale::
>>> sale, = opportunity.click('convert')
>>> opportunity.state
'converted'
>>> assertEqual(sale.origin, opportunity)
Find the sale::
>>> line, = sale.lines
>>> assertEqual(line.product, product)
>>> line.quantity
10.0
>>> assertEqual(line.taxes, [tax])
Quote different quantity::
>>> line.quantity = 9
>>> sale.click('quote')
Check opportunity amount updated::
>>> opportunity.reload()
>>> opportunity.amount
Decimal('90.00')
>>> opportunity.state
'converted'
Add a second quotation::
>>> second_sale = Sale()
>>> second_sale.origin = opportunity
>>> second_sale.party = customer
>>> second_sale.payment_term = payment_term
>>> line = second_sale.lines.new()
>>> line.product = product
>>> line.quantity = 1
>>> second_sale.click('quote')
Check opportunity amount updated::
>>> opportunity.reload()
>>> opportunity.amount
Decimal('100.00')
>>> opportunity.state
'converted'
Cancel second quotation::
>>> second_sale.click('cancel')
>>> second_sale.state
'cancelled'
Check opportunity amount updated::
>>> opportunity.reload()
>>> opportunity.amount
Decimal('90.00')
>>> opportunity.state
'converted'
Won opportunity::
>>> sale.click('confirm')
>>> opportunity.reload()
>>> opportunity.state
'won'
Check opportunity state updated::
>>> opportunity.reload()
>>> opportunity.state
'won'

View File

@@ -0,0 +1,139 @@
===================================
Sale Opportunity Reporting Scenario
===================================
Imports::
>>> import datetime as dt
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
Activate modules::
>>> config = activate_modules('sale_opportunity', create_company)
>>> Employee = Model.get('company.employee')
>>> Opportunity = Model.get('sale.opportunity')
>>> Party = Model.get('party.party')
>>> ProductCategory = Model.get('product.category')
Create employees::
>>> employee1_party = Party(name="Employee 1")
>>> employee1_party.save()
>>> employee1 = Employee(party=employee1_party)
>>> employee1.save()
>>> employee2_party = Party(name="Employee 2")
>>> employee2_party.save()
>>> employee2 = Employee(party=employee2_party)
>>> employee2.save()
Create parties::
>>> customer1 = Party(name="Customer 1")
>>> customer1.save()
>>> customer2 = Party(name="Customer 2")
>>> customer2.save()
Create leads and opportunities::
>>> lead = Opportunity(party=customer1)
>>> lead.amount = Decimal('1000.00')
>>> lead.save()
>>> opportunity = Opportunity(party=customer1)
>>> opportunity.amount = Decimal('2000.00')
>>> opportunity.employee = employee1
>>> opportunity.click('opportunity')
>>> opportunity = Opportunity(party=customer2)
>>> opportunity.amount = Decimal('500.00')
>>> opportunity.employee = employee2
>>> opportunity.end_date = today
>>> opportunity.click('opportunity')
>>> sale, = opportunity.click('convert')
>>> opportunity = Opportunity(party=customer1)
>>> opportunity.amount = Decimal('700.00')
>>> opportunity.employee = employee1
>>> opportunity.click('opportunity')
>>> sale, = opportunity.click('convert')
>>> line = sale.lines.new()
>>> line.quantity = 1
>>> line.unit_price = Decimal('800.00')
>>> sale.invoice_address, = sale.party.addresses
>>> sale.click('quote')
>>> sale.click('confirm')
>>> opportunity = Opportunity(party=customer2)
>>> opportunity.amount = Decimal('200.00')
>>> opportunity.employee = employee2
>>> opportunity.click('opportunity')
>>> opportunity.click('lost')
Check opportunity reporting::
>>> Main = Model.get('sale.opportunity.reporting.main')
>>> context = dict(
... from_date=today,
... to_date=today,
... period='month')
>>> with config.set_context(context=context):
... reports = Main.find([])
>>> report, = reports
>>> report.number
5
>>> report.amount
Decimal('4500.00')
>>> report.converted
2
>>> report.conversion_rate
0.4
>>> report.converted_amount
Decimal('1300.00')
>>> report, = report.time_series
>>> report.number
5
>>> report.amount
Decimal('4500.00')
>>> report.converted
2
>>> report.conversion_rate
0.4
>>> report.converted_amount
Decimal('1300.00')
Check conversion reporting::
>>> Conversion = Model.get('sale.opportunity.reporting.conversion')
>>> with config.set_context(context=context):
... reports = Conversion.find([])
>>> report, = reports
>>> report.number
3
>>> report.converted
2
>>> report.won
1
>>> report.winning_rate
0.3333
>>> report.won_amount
Decimal('800.00')
>>> report.lost
1
>>> len(report.time_series)
1
>>> ConversionEmployee = Model.get(
... 'sale.opportunity.reporting.conversion.employee')
>>> with config.set_context(context=context):
... reports = ConversionEmployee.find([])
>>> len(reports)
2

View File

@@ -0,0 +1,15 @@
# 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.modules.party.tests import PartyCheckReplaceMixin
from trytond.tests.test_tryton import ModuleTestCase
class SaleOpportunityTestCase(
PartyCheckReplaceMixin, CompanyTestMixin, ModuleTestCase):
'Test SaleOpportunity module'
module = 'sale_opportunity'
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)