Relink stock moves to drop shipment after amending sale lines
Closes #13647
This commit is contained in:
@@ -30,6 +30,10 @@ def register():
|
||||
party.Replace,
|
||||
party.Erase,
|
||||
module='sale_supply_drop_shipment', type_='wizard')
|
||||
Pool.register(
|
||||
sale.Amendment,
|
||||
module='sale_supply_drop_shipment', type_='model',
|
||||
depends=['sale_amendment'])
|
||||
Pool.register(
|
||||
stock.ShipmentDropSplit,
|
||||
stock.MoveSplit,
|
||||
|
||||
@@ -133,3 +133,21 @@ class Line(metaclass=PoolMeta):
|
||||
move.from_location = self.sale.drop_location
|
||||
moves.append(move)
|
||||
return moves
|
||||
|
||||
|
||||
class Amendment(metaclass=PoolMeta):
|
||||
__name__ = 'sale.amendment'
|
||||
|
||||
@classmethod
|
||||
def _clear_sale(cls, sales):
|
||||
pool = Pool()
|
||||
Shipment = pool.get('stock.shipment.drop')
|
||||
shipments = set()
|
||||
for sale in sales:
|
||||
for shipment in sale.drop_shipments:
|
||||
if shipment.state == 'waiting':
|
||||
shipments.add(shipment)
|
||||
|
||||
super()._clear_sale(sales)
|
||||
|
||||
Shipment.wait(Shipment.browse(list(shipments)))
|
||||
|
||||
@@ -49,6 +49,7 @@ requires.append(get_require_version('trytond'))
|
||||
|
||||
tests_require = [
|
||||
get_require_version('proteus'),
|
||||
get_require_version('trytond_sale_amendment'),
|
||||
get_require_version('trytond_stock_split'),
|
||||
]
|
||||
|
||||
|
||||
@@ -178,6 +178,7 @@ class ShipmentDrop(
|
||||
('draft', 'cancelled'),
|
||||
('waiting', 'cancelled'),
|
||||
('waiting', 'draft'),
|
||||
('waiting', 'waiting'),
|
||||
('cancelled', 'draft'),
|
||||
('shipped', 'done'),
|
||||
('shipped', 'cancelled'),
|
||||
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
=================================================
|
||||
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
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
>>> product_supplier.save()
|
||||
|
||||
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
|
||||
@@ -10,7 +10,7 @@ class SaleSupplyDropShipmentTestCase(
|
||||
PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase):
|
||||
'Test SaleSupplyDropShipment module'
|
||||
module = 'sale_supply_drop_shipment'
|
||||
extras = ['stock_split']
|
||||
extras = ['sale_amendment', 'stock_split']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
|
||||
@@ -10,6 +10,7 @@ depends:
|
||||
sale_supply
|
||||
stock
|
||||
extras_depend:
|
||||
sale_amendment
|
||||
stock_split
|
||||
xml:
|
||||
stock.xml
|
||||
|
||||
Reference in New Issue
Block a user