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,138 @@
========================
Invoice - Stock 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 (
... set_fiscalyear_invoice_sequences)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.modules.currency.tests.tools import get_currency
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules(
... 'account_invoice_stock', create_company, create_chart)
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(
... create_fiscalyear())
>>> fiscalyear.click('create_period')
Get accounts::
>>> accounts = get_accounts()
Create a party::
>>> Party = Model.get('party.party')
>>> party = Party(name="Party")
>>> party.save()
Create an 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 a 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.list_price = Decimal('40')
>>> template.account_category = account_category
>>> template.save()
>>> product, = template.products
Get stock locations::
>>> Location = Model.get('stock.location')
>>> output_loc, = Location.find([('code', '=', 'OUT')])
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
Create a shipment::
>>> Shipment = Model.get('stock.shipment.out')
>>> Move = Model.get('stock.move')
>>> shipment = Shipment()
>>> shipment.customer = party
>>> move = shipment.outgoing_moves.new()
>>> move.product = product
>>> move.quantity = 10
>>> move.from_location = output_loc
>>> move.to_location = customer_loc
>>> move.unit_price = Decimal('40.0000')
>>> move.currency = get_currency()
>>> shipment.click('wait')
>>> shipment.state
'waiting'
>>> move, = shipment.outgoing_moves
Create an invoice for half the quantity with higher price::
>>> Invoice = Model.get('account.invoice')
>>> invoice = Invoice(type='out')
>>> invoice.party = party
>>> line = invoice.lines.new()
>>> line.product = product
>>> line.quantity = 5
>>> line.unit_price = Decimal('50.0000')
>>> line.stock_moves.append(Move(move.id))
>>> invoice.click('post')
>>> invoice.state
'posted'
Check move unit price is not changed::
>>> move.reload()
>>> move.unit_price
Decimal('40.0000')
Ship the products::
>>> shipment.click('assign_force')
>>> shipment.click('pick')
>>> shipment.click('pack')
>>> shipment.click('do')
>>> shipment.state
'done'
Check move unit price has been updated::
>>> move.reload()
>>> move.unit_price
Decimal('50.0000')
Create a second invoice for the remaining quantity cheaper::
>>> invoice = Invoice(type='out')
>>> invoice.party = party
>>> line = invoice.lines.new()
>>> line.product = product
>>> line.quantity = 5
>>> line.unit_price = Decimal('40.0000')
>>> line.stock_moves.append(Move(move.id))
>>> invoice.click('post')
>>> invoice.state
'posted'
Check move unit price has been updated again::
>>> move.reload()
>>> move.unit_price
Decimal('45.0000')

View File

@@ -0,0 +1,130 @@
===================================
Invoice - Stock Correction 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.modules.currency.tests.tools import get_currency
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
Activate modules::
>>> config = activate_modules(
... 'account_invoice_stock', create_company, create_chart)
>>> Invoice = Model.get('account.invoice')
>>> Location = Model.get('stock.location')
>>> Move = Model.get('stock.move')
>>> Party = Model.get('party.party')
>>> ProductCategory = Model.get('product.category')
>>> ProductTemplate = Model.get('product.template')
>>> ProductUom = Model.get('product.uom')
>>> Shipment = Model.get('stock.shipment.in')
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(
... create_fiscalyear(today=today))
>>> fiscalyear.click('create_period')
Get accounts::
>>> accounts = get_accounts()
Create a party::
>>> party = Party(name="Party")
>>> party.save()
Create an 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::
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> template = ProductTemplate()
>>> template.name = 'product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('40')
>>> template.account_category = account_category
>>> template.save()
>>> product, = template.products
Get stock locations::
>>> input_loc, = Location.find([('code', '=', 'IN')])
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
Create a shipment::
>>> shipment = Shipment()
>>> shipment.supplier = party
>>> move = shipment.incoming_moves.new()
>>> move.product = product
>>> move.quantity = 10
>>> move.from_location = supplier_loc
>>> move.to_location = input_loc
>>> move.unit_price = Decimal('40.0000')
>>> move.currency = get_currency()
>>> shipment.click('receive')
>>> shipment.state
'received'
>>> move, = shipment.incoming_moves
Create an invoice::
>>> invoice = Invoice(type='in')
>>> invoice.party = party
>>> invoice.invoice_date = today
>>> line = invoice.lines.new()
>>> line.product = product
>>> line.quantity = 10
>>> line.unit_price = Decimal('40.0000')
>>> line.stock_moves.append(Move(move.id))
>>> invoice.click('post')
>>> invoice.state
'posted'
Check move unit price::
>>> move.reload()
>>> move.unit_price
Decimal('40.0000')
Post a price correction::
>>> invoice = Invoice(type='in')
>>> invoice.party = party
>>> invoice.invoice_date = today
>>> line = invoice.lines.new()
>>> line.product = product
>>> line.quantity = 1
>>> line.unit_price = Decimal('-10.0000')
>>> line.correction = True
>>> line.stock_moves.append(Move(move.id))
>>> invoice.click('post')
>>> invoice.state
'posted'
Check move unit price::
>>> move.reload()
>>> move.unit_price
Decimal('39.0000')

View File

@@ -0,0 +1,12 @@
# 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 ModuleTestCase
class AccountInvoiceStockTestCase(ModuleTestCase):
'Test AccountInvoiceStock module'
module = 'account_invoice_stock'
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)