first commit
This commit is contained in:
2
modules/sale_supply_drop_shipment/tests/__init__.py
Normal file
2
modules/sale_supply_drop_shipment/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.
@@ -0,0 +1,303 @@
|
||||
==================================
|
||||
Sale Supply Drop Shipment Scenario
|
||||
==================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> 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, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules([
|
||||
... 'sale_supply_drop_shipment',
|
||||
... 'sale',
|
||||
... 'purchase',
|
||||
... ],
|
||||
... create_company, create_chart)
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(today=today))
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
>>> 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_expense = expense
|
||||
>>> account_category.account_revenue = revenue
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductSupplier = Model.get('purchase.product_supplier')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.purchasable = True
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.supply_on_sale = 'always'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
>>> product.cost_price = Decimal('4')
|
||||
>>> product.save()
|
||||
>>> product_supplier = ProductSupplier()
|
||||
>>> product_supplier.template = template
|
||||
>>> product_supplier.party = supplier
|
||||
>>> product_supplier.drop_shipment = True
|
||||
>>> product_supplier.lead_time = dt.timedelta(0)
|
||||
>>> product_supplier.save()
|
||||
|
||||
Create payment term::
|
||||
|
||||
>>> payment_term = create_payment_term()
|
||||
>>> payment_term.save()
|
||||
|
||||
Sale 250 products::
|
||||
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 250
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.state
|
||||
'processing'
|
||||
>>> sale.shipments
|
||||
[]
|
||||
>>> sale.drop_shipments
|
||||
[]
|
||||
|
||||
Create Purchase from Request::
|
||||
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> PurchaseRequest = Model.get('purchase.request')
|
||||
>>> purchase_request, = PurchaseRequest.find()
|
||||
>>> purchase_request.quantity
|
||||
250.0
|
||||
>>> create_purchase = Wizard('purchase.request.create_purchase',
|
||||
... [purchase_request])
|
||||
>>> purchase, = Purchase.find()
|
||||
>>> assertEqual(purchase.customer, customer)
|
||||
>>> assertEqual(purchase.delivery_address, sale.shipment_address)
|
||||
>>> purchase.payment_term = payment_term
|
||||
>>> purchase_line, = purchase.lines
|
||||
>>> purchase_line.unit_price = Decimal('3.0000')
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
|
||||
>>> sale.reload()
|
||||
>>> sale.shipments
|
||||
[]
|
||||
>>> shipment, = sale.drop_shipments
|
||||
|
||||
Receiving only 100 products::
|
||||
|
||||
>>> move, = shipment.supplier_moves
|
||||
>>> move.quantity = 100
|
||||
>>> move.unit_price
|
||||
Decimal('3.0000')
|
||||
>>> move.cost_price
|
||||
Decimal('3.0000')
|
||||
>>> shipment.click('ship')
|
||||
>>> move, = shipment.customer_moves
|
||||
>>> move.unit_price
|
||||
Decimal('10.0000')
|
||||
>>> move.cost_price
|
||||
>>> sale.reload()
|
||||
>>> sale.shipments
|
||||
[]
|
||||
>>> len(sale.drop_shipments)
|
||||
2
|
||||
>>> shipment, = [s for s in sale.drop_shipments
|
||||
... if s.state == 'shipped']
|
||||
|
||||
>>> shipment.click('do')
|
||||
>>> shipment.state
|
||||
'done'
|
||||
>>> move, = shipment.customer_moves
|
||||
>>> move.cost_price
|
||||
Decimal('3.0000')
|
||||
>>> sale.reload()
|
||||
>>> sale.shipments
|
||||
[]
|
||||
>>> len(sale.drop_shipments)
|
||||
2
|
||||
|
||||
The purchase is now waiting for his new drop shipment::
|
||||
|
||||
>>> purchase.reload()
|
||||
>>> purchase.shipment_state
|
||||
'partially shipped'
|
||||
>>> len(purchase.drop_shipments)
|
||||
2
|
||||
>>> shipment, = [s for s in purchase.drop_shipments
|
||||
... if s.state == 'waiting']
|
||||
>>> move, = shipment.customer_moves
|
||||
>>> move.quantity
|
||||
150.0
|
||||
>>> move, = shipment.supplier_moves
|
||||
>>> move.quantity
|
||||
150.0
|
||||
|
||||
Let's cancel the shipment and handle the issue on the purchase.
|
||||
As a consequence the sale order is now in exception::
|
||||
|
||||
>>> shipment.click('cancel')
|
||||
|
||||
>>> purchase.reload()
|
||||
>>> purchase.shipment_state
|
||||
'exception'
|
||||
>>> handle_exception = purchase.click('handle_shipment_exception')
|
||||
>>> handle_exception.form.ignore_moves.extend(
|
||||
... handle_exception.form.ignore_moves.find())
|
||||
>>> handle_exception.execute('handle')
|
||||
>>> purchase.reload()
|
||||
>>> purchase.shipment_state
|
||||
'received'
|
||||
|
||||
>>> sale.reload()
|
||||
>>> sale.shipment_state
|
||||
'exception'
|
||||
|
||||
Receive purchase invoice at different price::
|
||||
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> invoice_line, = invoice.lines
|
||||
>>> invoice_line.unit_price = Decimal('4.0000')
|
||||
>>> invoice.invoice_date = today
|
||||
>>> invoice.click('post')
|
||||
|
||||
|
||||
>>> recompute = Wizard('product.recompute_cost_price', [product])
|
||||
>>> recompute.execute('recompute')
|
||||
|
||||
>>> shipment, = [s for s in purchase.drop_shipments
|
||||
... if s.state == 'done']
|
||||
>>> move, = shipment.supplier_moves
|
||||
>>> move.cost_price
|
||||
Decimal('4.0000')
|
||||
>>> move, = shipment.customer_moves
|
||||
>>> move.cost_price
|
||||
Decimal('4.0000')
|
||||
|
||||
Cancelling the workflow on the purchase step::
|
||||
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 125
|
||||
>>> sale.save()
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.state
|
||||
'processing'
|
||||
>>> sale.shipments
|
||||
[]
|
||||
>>> sale.drop_shipments
|
||||
[]
|
||||
|
||||
>>> purchase_request, = PurchaseRequest.find([('purchase_line', '=', None)])
|
||||
>>> purchase_request.quantity
|
||||
125.0
|
||||
>>> create_purchase = Wizard('purchase.request.create_purchase',
|
||||
... [purchase_request])
|
||||
>>> purchase, = Purchase.find([('state', '=', 'draft')])
|
||||
>>> purchase.click('cancel')
|
||||
>>> purchase_request.state
|
||||
'exception'
|
||||
|
||||
Let's reset the purchase request and create a new purchase::
|
||||
|
||||
>>> handle_exception = purchase_request.click(
|
||||
... 'handle_purchase_cancellation_exception')
|
||||
>>> handle_exception.execute('reset')
|
||||
>>> purchase_request.state
|
||||
'draft'
|
||||
|
||||
>>> create_purchase = Wizard('purchase.request.create_purchase',
|
||||
... [purchase_request])
|
||||
>>> purchase, = Purchase.find([('state', '=', 'draft')])
|
||||
>>> purchase_request.state
|
||||
'purchased'
|
||||
|
||||
Let's cancel it again and cancel the request in order to manage the process on
|
||||
the sale::
|
||||
|
||||
>>> purchase.click('cancel')
|
||||
>>> purchase_request.reload()
|
||||
>>> purchase_request.state
|
||||
'exception'
|
||||
>>> handle_exception = purchase_request.click(
|
||||
... 'handle_purchase_cancellation_exception')
|
||||
>>> handle_exception.execute('cancel_request')
|
||||
>>> purchase_request.state
|
||||
'cancelled'
|
||||
|
||||
The sale is then in exception::
|
||||
|
||||
>>> sale.reload()
|
||||
>>> sale.shipment_state
|
||||
'exception'
|
||||
>>> handle_exception = sale.click('handle_shipment_exception')
|
||||
>>> handle_exception.form.recreate_moves.extend(
|
||||
... handle_exception.form.recreate_moves.find())
|
||||
>>> handle_exception.execute('handle')
|
||||
>>> sale.reload()
|
||||
>>> sale.shipment_state
|
||||
'waiting'
|
||||
|
||||
The sale just created a new outgoing shipment for the sale and we can deliver
|
||||
from stock::
|
||||
|
||||
>>> shipment, = sale.shipments
|
||||
|
||||
>>> shipment.click('assign_force')
|
||||
>>> shipment.click('pick')
|
||||
>>> shipment.click('pack')
|
||||
>>> shipment.click('do')
|
||||
|
||||
>>> sale.reload()
|
||||
>>> sale.shipment_state
|
||||
'sent'
|
||||
@@ -0,0 +1,117 @@
|
||||
=================================================
|
||||
Sale Supply Drop Shipment with Amendment Scenario
|
||||
=================================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> 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
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules([
|
||||
... 'sale_supply_drop_shipment',
|
||||
... 'sale_amendment',
|
||||
... ],
|
||||
... create_company, create_chart)
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductSupplier = Model.get('purchase.product_supplier')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> PurchaseRequest = Model.get('purchase.request')
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> Shipment = Model.get('stock.shipment.drop')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> supplier = Party(name="Supplier")
|
||||
>>> supplier.save()
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> customer.save()
|
||||
|
||||
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 product::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', "Unit")])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.purchasable = True
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10.000')
|
||||
>>> template.supply_on_sale = 'always'
|
||||
>>> template.account_category = account_category
|
||||
>>> product_supplier = template.product_suppliers.new()
|
||||
>>> product_supplier.party = supplier
|
||||
>>> product_supplier.drop_shipment = True
|
||||
>>> supplier_price = product_supplier.prices.new()
|
||||
>>> supplier_price.unit_price = Decimal('5.0000')
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
>>> product.cost_price = Decimal('5.0000')
|
||||
|
||||
Sale 5 products::
|
||||
|
||||
>>> sale = Sale(party=customer)
|
||||
>>> line = sale.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 5
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.state
|
||||
'processing'
|
||||
|
||||
Create purchase::
|
||||
|
||||
>>> purchase_request, = PurchaseRequest.find()
|
||||
>>> create_purchase = Wizard(
|
||||
... 'purchase.request.create_purchase', [purchase_request])
|
||||
>>> purchase, = Purchase.find()
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
|
||||
>>> shipment, = Shipment.find()
|
||||
>>> shipment.state
|
||||
'waiting'
|
||||
|
||||
Add an amendment::
|
||||
|
||||
>>> amendment = sale.amendments.new()
|
||||
>>> line = amendment.lines.new()
|
||||
>>> line.action = 'line'
|
||||
>>> line.line, = sale.lines
|
||||
>>> line.quantity = 4
|
||||
>>> amendment.click('validate_amendment')
|
||||
>>> amendment.state
|
||||
'validated'
|
||||
|
||||
Check drop shipment::
|
||||
|
||||
>>> supplier_move, = shipment.supplier_moves
|
||||
>>> supplier_move.quantity
|
||||
5.0
|
||||
>>> customer_move, = shipment.customer_moves
|
||||
>>> customer_move.quantity
|
||||
5.0
|
||||
@@ -0,0 +1,144 @@
|
||||
=============================================
|
||||
Sale Supply Drop Shipment on Invoice Scenario
|
||||
=============================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> 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
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... 'sale_supply_drop_shipment', create_company, create_chart)
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> PaymentMethod = Model.get('account.invoice.payment.method')
|
||||
>>> cash_journal, = Journal.find([('type', '=', 'cash')])
|
||||
>>> cash_journal.save()
|
||||
>>> payment_method = PaymentMethod()
|
||||
>>> payment_method.name = 'Cash'
|
||||
>>> payment_method.journal = cash_journal
|
||||
>>> payment_method.credit_account = accounts['cash']
|
||||
>>> payment_method.debit_account = accounts['cash']
|
||||
>>> payment_method.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
>>> 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_expense = accounts['expense']
|
||||
>>> account_category.account_revenue = accounts['revenue']
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductSupplier = Model.get('purchase.product_supplier')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.purchasable = True
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.supply_on_sale = 'always'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
>>> product_supplier = ProductSupplier()
|
||||
>>> product_supplier.template = template
|
||||
>>> product_supplier.party = supplier
|
||||
>>> product_supplier.drop_shipment = True
|
||||
>>> product_supplier.lead_time = datetime.timedelta(0)
|
||||
>>> product_supplier.save()
|
||||
|
||||
Sale 5 products with shipment method on invoice::
|
||||
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.shipment_method = 'invoice'
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 5
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.click('process')
|
||||
>>> sale.state
|
||||
'processing'
|
||||
>>> len(sale.shipments)
|
||||
0
|
||||
>>> len(sale.drop_shipments)
|
||||
0
|
||||
>>> invoice, = sale.invoices
|
||||
>>> sale_line, = sale.lines
|
||||
>>> sale_line.purchase_request
|
||||
|
||||
Pay for 3 products::
|
||||
|
||||
>>> invoice_line, = invoice.lines
|
||||
>>> invoice_line.quantity = 3
|
||||
>>> invoice.click('post')
|
||||
>>> pay = invoice.click('pay')
|
||||
>>> pay.form.payment_method = payment_method
|
||||
>>> pay.execute('choice')
|
||||
|
||||
Not yet a purchase request::
|
||||
|
||||
>>> sale.reload()
|
||||
>>> len(sale.shipments)
|
||||
0
|
||||
>>> len(sale.drop_shipments)
|
||||
0
|
||||
>>> sale_line.reload()
|
||||
>>> sale_line.purchase_request
|
||||
|
||||
Pay for remaining products::
|
||||
|
||||
>>> sale.reload()
|
||||
>>> _, invoice = sale.invoices
|
||||
>>> invoice.click('post')
|
||||
>>> pay = invoice.click('pay')
|
||||
>>> pay.form.payment_method = payment_method
|
||||
>>> pay.execute('choice')
|
||||
|
||||
Check drop shipment::
|
||||
|
||||
>>> sale.reload()
|
||||
>>> sale_line, = sale.lines
|
||||
>>> bool(sale_line.purchase_request)
|
||||
True
|
||||
>>> len(sale.shipments)
|
||||
0
|
||||
>>> len(sale.drop_shipments)
|
||||
0
|
||||
@@ -0,0 +1,138 @@
|
||||
==================================
|
||||
Sale Supply Drop Shipment Scenario
|
||||
==================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> 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_supply_drop_shipment',
|
||||
... 'sale',
|
||||
... 'purchase',
|
||||
... ],
|
||||
... 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')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
>>> 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_expense = expense
|
||||
>>> account_category.account_revenue = revenue
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductSupplier = Model.get('purchase.product_supplier')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.purchasable = True
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.supply_on_sale = 'always'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
>>> product_supplier = ProductSupplier()
|
||||
>>> product_supplier.template = template
|
||||
>>> product_supplier.party = supplier
|
||||
>>> product_supplier.drop_shipment = True
|
||||
>>> product_supplier.lead_time = dt.timedelta(0)
|
||||
>>> supplier_price = product_supplier.prices.new()
|
||||
>>> supplier_price.unit_price = Decimal('5.0000')
|
||||
>>> product_supplier.save()
|
||||
|
||||
Create payment term::
|
||||
|
||||
>>> payment_term = create_payment_term()
|
||||
>>> payment_term.save()
|
||||
|
||||
Sale 250 products::
|
||||
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 250
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.click('process')
|
||||
|
||||
Create Purchase from Request::
|
||||
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> PurchaseRequest = Model.get('purchase.request')
|
||||
>>> purchase_request, = PurchaseRequest.find()
|
||||
>>> purchase_request.quantity
|
||||
250.0
|
||||
>>> create_purchase = Wizard('purchase.request.create_purchase',
|
||||
... [purchase_request])
|
||||
>>> purchase, = Purchase.find()
|
||||
>>> purchase.payment_term = payment_term
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.click('process')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
|
||||
>>> sale.reload()
|
||||
>>> shipment, = sale.drop_shipments
|
||||
|
||||
The supplier sends more than expected::
|
||||
|
||||
>>> move, = shipment.supplier_moves
|
||||
>>> move.quantity = 300
|
||||
>>> shipment.click('ship')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
MoveOriginWarning: ...
|
||||
>>> config.skip_warning = True
|
||||
>>> shipment.click('ship')
|
||||
>>> shipment.state
|
||||
'shipped'
|
||||
|
||||
Another move has been created to synchronize supplier and customer quantities::
|
||||
|
||||
>>> len(shipment.customer_moves)
|
||||
2
|
||||
>>> sum(m.quantity for m in shipment.customer_moves)
|
||||
300.0
|
||||
@@ -0,0 +1,137 @@
|
||||
========================================
|
||||
Sale Supply Drop Shipment Split Scenario
|
||||
========================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> 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_supply_drop_shipment',
|
||||
... 'stock_split',
|
||||
... ],
|
||||
... create_company, create_chart)
|
||||
|
||||
>>> Move = Model.get('stock.move')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductSupplier = Model.get('purchase.product_supplier')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> PurchaseRequest = Model.get('purchase.request')
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> Shipment = Model.get('stock.shipment.drop')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> supplier = Party(name="Supplier")
|
||||
>>> supplier.save()
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> customer.save()
|
||||
|
||||
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 product::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', "Unit")])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.purchasable = True
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10.000')
|
||||
>>> template.supply_on_sale = 'always'
|
||||
>>> template.account_category = account_category
|
||||
>>> product_supplier = template.product_suppliers.new()
|
||||
>>> product_supplier.party = supplier
|
||||
>>> product_supplier.drop_shipment = True
|
||||
>>> supplier_price = product_supplier.prices.new()
|
||||
>>> supplier_price.unit_price = Decimal('5.0000')
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Sale 5 products::
|
||||
|
||||
>>> sale = Sale(party=customer)
|
||||
>>> line = sale.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 5
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.state
|
||||
'processing'
|
||||
|
||||
Create purchase request::
|
||||
|
||||
>>> purchase_request, = PurchaseRequest.find()
|
||||
>>> create_purchase = Wizard(
|
||||
... 'purchase.request.create_purchase', [purchase_request])
|
||||
>>> purchase, = Purchase.find()
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
|
||||
Split supplier move of drop shipment::
|
||||
|
||||
>>> shipment, = Shipment.find()
|
||||
>>> move, = shipment.supplier_moves
|
||||
>>> split = move.click('split_wizard')
|
||||
>>> split.form.quantity = 2
|
||||
>>> split.form.count = 1
|
||||
>>> split.execute('split')
|
||||
|
||||
>>> shipment.reload()
|
||||
>>> len(shipment.supplier_moves)
|
||||
2
|
||||
>>> len(shipment.customer_moves)
|
||||
2
|
||||
>>> for move in shipment.supplier_moves:
|
||||
... assertEqual(move.quantity, sum(m.quantity for m in move.moves_drop))
|
||||
|
||||
Split drop shipment::
|
||||
|
||||
>>> shipment.click('draft')
|
||||
>>> split = shipment.click('split_wizard')
|
||||
>>> split.form.moves.append(Move(shipment.supplier_moves[0].id))
|
||||
>>> split.execute('split')
|
||||
|
||||
>>> shipment2, = Shipment.find([('id', '!=', shipment.id)])
|
||||
|
||||
>>> Shipment.click([shipment, shipment2], 'wait')
|
||||
|
||||
>>> len(shipment.supplier_moves)
|
||||
1
|
||||
>>> len(shipment.customer_moves)
|
||||
1
|
||||
>>> assertEqual(
|
||||
... sum(m.quantity for m in shipment.supplier_moves),
|
||||
... sum(m.quantity for m in shipment.customer_moves))
|
||||
|
||||
>>> len(shipment2.supplier_moves)
|
||||
1
|
||||
>>> len(shipment2.customer_moves)
|
||||
1
|
||||
>>> assertEqual(
|
||||
... sum(m.quantity for m in shipment2.supplier_moves),
|
||||
... sum(m.quantity for m in shipment2.customer_moves))
|
||||
18
modules/sale_supply_drop_shipment/tests/test_module.py
Normal file
18
modules/sale_supply_drop_shipment/tests/test_module.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# 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, PartyCompanyCheckEraseMixin)
|
||||
from trytond.modules.party.tests import PartyCheckReplaceMixin
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class SaleSupplyDropShipmentTestCase(
|
||||
PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin,
|
||||
ModuleTestCase):
|
||||
'Test SaleSupplyDropShipment module'
|
||||
module = 'sale_supply_drop_shipment'
|
||||
extras = ['sale_amendment', 'stock_split']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/sale_supply_drop_shipment/tests/test_scenario.py
Normal file
8
modules/sale_supply_drop_shipment/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