Skip to content
Permalink
Browse files

purchase_stock

  • Loading branch information...
tivisse committed Oct 9, 2019
1 parent f40acc9 commit bc948a5f5bafb378e0ba4bd3b39d3bd3f2eeeb6b

Large diffs are not rendered by default.

@@ -5,7 +5,6 @@
import time
import unittest


# TODO in master
# The name of this class should be TestReconciliationHelpers
class TestReconciliation(AccountingTestCase):
@@ -41,7 +41,6 @@ def _stock_account_prepare_anglo_saxon_in_lines_vals(self):
continue

for line in move.invoice_line_ids.filtered(lambda line: line.product_id.type == 'product' and line.product_id.valuation == 'real_time'):

# Filter out lines being not eligible for price difference.
if line.product_id.type != 'product' or line.product_id.valuation != 'real_time':
continue
@@ -4,15 +4,16 @@
import time

from .common import TestPurchase
from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest


class TestAveragePrice(TestPurchase):
class TestAveragePrice(TestPurchase, StockAccountMinimalTest):

def test_00_average_price(self):
""" Testcase for average price computation"""

self._load('account', 'test', 'account_minimal_test.xml')
self._load('stock_account', 'test', 'stock_valuation_account.xml')
res_partner_3 = self.env['res.partner'].create({
'name': 'Gemini Partner',
})

# Set a product as using average price.
product_cable_management_box = self.env['product.product'].create({
@@ -29,12 +30,12 @@ def test_00_average_price(self):
})
product_cable_management_box.categ_id.property_cost_method = 'average'
product_cable_management_box.categ_id.property_valuation = 'real_time'
product_cable_management_box.categ_id.property_stock_account_input_categ_id = self.ref('purchase.o_expense')
product_cable_management_box.categ_id.property_stock_account_output_categ_id = self.ref('purchase.o_income')
product_cable_management_box.categ_id.property_stock_account_input_categ_id = self.o_expense
product_cable_management_box.categ_id.property_stock_account_output_categ_id = self.o_income

# I create a draft Purchase Order for first incoming shipment for 10 pieces at 60€
purchase_order_1 = self.env['purchase.order'].create({
'partner_id': self.env.ref('base.res_partner_3').id,
'partner_id': res_partner_3.id,
'order_line': [(0, 0, {
'name': 'Average Ice Cream',
'product_id': product_cable_management_box.id,
@@ -61,7 +62,7 @@ def test_00_average_price(self):

# I create a draft Purchase Order for second incoming shipment for 30 pieces at 80€
purchase_order_2 = self.env['purchase.order'].create({
'partner_id': self.env.ref('base.res_partner_3').id,
'partner_id': res_partner_3.id,
'order_line': [(0, 0, {
'name': product_cable_management_box.name,
'product_id': product_cable_management_box.id,
@@ -105,7 +106,7 @@ def test_00_average_price(self):

# Make a new purchase order with 500 g Average Ice Cream at a price of 0.2€/g
purchase_order_3 = self.env['purchase.order'].create({
'partner_id': self.env.ref('base.res_partner_3').id,
'partner_id': res_partner_3.id,
'order_line': [(0, 0, {
'name': product_cable_management_box.name,
'product_id': product_cable_management_box.id,
@@ -10,9 +10,9 @@ class TestCreatePicking(common.TestProductCommon):

def setUp(self):
super(TestCreatePicking, self).setUp()
self.partner_id = self.env.ref('base.res_partner_1')
self.product_id_1 = self.env.ref('product.product_product_8')
self.product_id_2 = self.env.ref('product.product_product_11')
self.partner_id = self.env['res.partner'].create({'name': 'Wood Corner Partner'})
self.product_id_1 = self.env['product.product'].create({'name': 'Large Desk'})
self.product_id_2 = self.env['product.product'].create({'name': 'Conference Chair'})
res_users_purchase_user = self.env.ref('purchase.group_purchase_user')

Users = self.env['res.users'].with_context({'no_reset_password': True, 'mail_create_nosubscribe': True})
@@ -3,15 +3,16 @@
import time

from .common import TestPurchase
from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest


class TestFifoPrice(TestPurchase):
class TestFifoPrice(TestPurchase, StockAccountMinimalTest):

def test_00_test_fifo(self):
""" Test product cost price with fifo removal strategy."""

self._load('account', 'test', 'account_minimal_test.xml')
self._load('stock_account', 'test', 'stock_valuation_account.xml')
res_partner_3 = self.env['res.partner'].create({
'name': 'Gemini Partner',
})

# Set a product as using fifo price
product_cable_management_box = self.env['product.product'].create({
@@ -28,12 +29,12 @@ def test_00_test_fifo(self):
})
product_cable_management_box.categ_id.property_cost_method = 'fifo'
product_cable_management_box.categ_id.property_valuation = 'real_time'
product_cable_management_box.categ_id.property_stock_account_input_categ_id = self.ref('purchase.o_expense')
product_cable_management_box.categ_id.property_stock_account_output_categ_id = self.ref('purchase.o_income')
product_cable_management_box.categ_id.property_stock_account_input_categ_id = self.o_expense
product_cable_management_box.categ_id.property_stock_account_output_categ_id = self.o_income

# I create a draft Purchase Order for first in move for 10 kg at 50 euro
purchase_order_1 = self.env['purchase.order'].create({
'partner_id': self.env.ref('base.res_partner_3').id,
'partner_id': res_partner_3.id,
'order_line': [(0, 0, {
'name': 'FIFO Ice Cream',
'product_id': product_cable_management_box.id,
@@ -60,7 +61,7 @@ def test_00_test_fifo(self):

# I create a draft Purchase Order for second shipment for 30 kg at 80 euro
purchase_order_2 = self.env['purchase.order'].create({
'partner_id': self.env.ref('base.res_partner_3').id,
'partner_id': res_partner_3.id,
'order_line': [(0, 0, {
'name': 'FIFO Ice Cream',
'product_id': product_cable_management_box.id,
@@ -140,7 +141,7 @@ def test_00_test_fifo(self):

# Create PO for 30000 g at 0.150$/g and 10 kg at 150$/kg
purchase_order_usd = self.env['purchase.order'].create({
'partner_id': self.env.ref('base.res_partner_3').id,
'partner_id': res_partner_3.id,
'currency_id': NewUSD.id,
'order_line': [(0, 0, {
'name': 'FIFO Ice Cream',
@@ -222,8 +223,8 @@ def test_00_test_fifo(self):
})
product_fifo_negative.categ_id.property_cost_method = 'fifo'
product_fifo_negative.categ_id.property_valuation = 'real_time'
product_fifo_negative.categ_id.property_stock_account_input_categ_id = self.ref('purchase.o_expense')
product_fifo_negative.categ_id.property_stock_account_output_categ_id = self.ref('purchase.o_income')
product_fifo_negative.categ_id.property_stock_account_input_categ_id = self.o_expense
product_fifo_negative.categ_id.property_stock_account_output_categ_id = self.o_income

# Create outpicking.create delivery order of 100 kg.
outgoing_shipment_neg = self.env['stock.picking'].create({
@@ -276,7 +277,7 @@ def test_00_test_fifo(self):

# Receive purchase order with 50 kg Ice Cream at 50€/kg
purchase_order_neg = self.env['purchase.order'].create({
'partner_id': self.env.ref('base.res_partner_3').id,
'partner_id': res_partner_3.id,
'order_line': [(0, 0, {
'name': 'FIFO Ice Cream',
'product_id': product_fifo_negative.id,
@@ -295,7 +296,7 @@ def test_00_test_fifo(self):

# Receive purchase order with 600 kg FIFO Ice Cream at 80 euro/kg
purchase_order_neg2 = self.env['purchase.order'].create({
'partner_id': self.env.ref('base.res_partner_3').id,
'partner_id': res_partner_3.id,
'order_line': [(0, 0, {
'name': product_cable_management_box.name,
'product_id': product_fifo_negative.id,
@@ -4,14 +4,16 @@

from .common import TestPurchase
from odoo.tests.common import Form
from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest

class TestFifoReturns(TestPurchase):

class TestFifoReturns(TestPurchase, StockAccountMinimalTest):

def test_fifo_returns(self):
"""Test to create product and purchase order to test the FIFO returns of the product"""

self._load('account', 'test', 'account_minimal_test.xml')
self._load('stock_account', 'test', 'stock_valuation_account.xml')
res_partner_3 = self.env['res.partner'].create({
'name': 'Gemini Partner',
})

# Set a product as using fifo price
product_fiforet_icecream = self.env['product.product'].create({
@@ -26,12 +28,12 @@ def test_fifo_returns(self):
})
product_fiforet_icecream.categ_id.property_cost_method = 'fifo'
product_fiforet_icecream.categ_id.property_valuation = 'real_time'
product_fiforet_icecream.categ_id.property_stock_account_input_categ_id = self.ref('purchase.o_expense')
product_fiforet_icecream.categ_id.property_stock_account_output_categ_id = self.ref('purchase.o_income')
product_fiforet_icecream.categ_id.property_stock_account_input_categ_id = self.o_expense
product_fiforet_icecream.categ_id.property_stock_account_output_categ_id = self.o_income

# I create a draft Purchase Order for first in move for 10 kg at 50 euro
purchase_order_1 = self.env['purchase.order'].create({
'partner_id': self.ref('base.res_partner_3'),
'partner_id': res_partner_3.id,
'order_line': [(0, 0, {
'name': 'FIFO Ice Cream',
'product_id': product_fiforet_icecream.id,
@@ -44,7 +46,7 @@ def test_fifo_returns(self):

# Create a draft Purchase Order for second shipment for 30kg at 80€/kg
purchase_order_2 = self.env['purchase.order'].create({
'partner_id': self.ref('base.res_partner_3'),
'partner_id': res_partner_3.id,
'order_line': [(0, 0, {
'name': 'FIFO Ice Cream',
'product_id': product_fiforet_icecream.id,
@@ -83,7 +83,8 @@ def test_onchange_product_id(self):
po_line._onchange_quantity()
self.assertEqual(1200, po_line.price_unit, "Unit price should be 1200 for one Dozen")

product_ipad = self.env.ref('product.product_product_4')
# product_ipad = self.env.ref('product.product_product_4')
product_ipad = self.env['product.product'].create({'name': 'Conference Chair'})
po_line2 = self.po_line_model.create({
'name': product_ipad.name,
'product_id': product_ipad.id,
@@ -11,19 +11,32 @@ def test_00_delete_order(self):
''' Testcase for deleting purchase order with purchase user group'''

# In order to test delete process on purchase order,tried to delete a confirmed order and check Error Message.
purchase_order_1 = self.env.ref('purchase.purchase_order_1').with_user(self.res_users_purchase_user)
partner = self.env['res.partner'].create({'name': 'My Partner'})

purchase_order = self.env['purchase.order'].create({
'partner_id': partner.id,
'state': 'purchase',
})
purchase_order_1 = purchase_order.with_user(self.res_users_purchase_user)
with self.assertRaises(UserError):
purchase_order_1.unlink()

# Delete 'cancelled' purchase order with user group
purchase_order_7 = self.env.ref('purchase.purchase_order_7').with_user(self.res_users_purchase_user)
purchase_order_7.button_cancel()
self.assertEqual(purchase_order_7.state, 'cancel', 'PO is cancelled!')
purchase_order_7.unlink()
purchase_order = self.env['purchase.order'].create({
'partner_id': partner.id,
'state': 'purchase',
})
purchase_order_2 = purchase_order.with_user(self.res_users_purchase_user)
purchase_order_2.button_cancel()
self.assertEqual(purchase_order_2.state, 'cancel', 'PO is cancelled!')
purchase_order_2.unlink()

# Delete 'draft' purchase order with user group
purchase_order_5 = self.env.ref('purchase.purchase_order_5').with_user(self.res_users_purchase_user)
self.assertEqual(purchase_order_5.state, 'draft', 'PO in draft state!')
purchase_order_5.button_cancel()
self.assertEqual(purchase_order_5.state, 'cancel', 'PO is cancelled!')
purchase_order_5.unlink()
purchase_order = self.env['purchase.order'].create({
'partner_id': partner.id,
'state': 'draft',
})
purchase_order_3 = purchase_order.with_user(self.res_users_purchase_user)
purchase_order_3.button_cancel()
self.assertEqual(purchase_order_3.state, 'cancel', 'PO is cancelled!')
purchase_order_3.unlink()
@@ -16,9 +16,9 @@ def setUp(self):
# Useful models
self.PurchaseOrder = self.env['purchase.order']
self.PurchaseOrderLine = self.env['purchase.order.line']
self.partner_id = self.env.ref('base.res_partner_1')
self.product_id_1 = self.env.ref('product.product_product_8')
self.product_id_2 = self.env.ref('product.product_product_11')
self.partner_id = self.env['res.partner'].create({'name': 'Wood Corner Partner'})
self.product_id_1 = self.env['product.product'].create({'name': 'Large Desk'})
self.product_id_2 = self.env['product.product'].create({'name': 'Conference Chair'})

(self.product_id_1 | self.product_id_2).write({'purchase_method': 'purchase'})
self.po_vals = {
@@ -7,7 +7,11 @@ def test_00_cancel_purchase_order_flow(self):
""" Test cancel purchase order with group user."""

# In order to test the cancel flow,start it from canceling confirmed purchase order.
po_edit_with_user = self.env.ref('purchase.purchase_order_5').with_user(self.res_users_purchase_user)
purchase_order = self.env['purchase.order'].create({
'partner_id': self.env['res.partner'].create({'name': 'My Partner'}).id,
'state': 'draft',
})
po_edit_with_user = purchase_order.with_user(self.res_users_purchase_user)

# Confirm the purchase order.
po_edit_with_user.button_confirm()
@@ -17,8 +17,16 @@ def setUp(self):
super(TestStockValuation, self).setUp()
self.supplier_location = self.env.ref('stock.stock_location_suppliers')
self.stock_location = self.env.ref('stock.stock_location_stock')
self.partner_id = self.env.ref('base.res_partner_1')
self.product1 = self.env.ref('product.product_product_8')
self.partner_id = self.env['res.partner'].create({
'name': 'Wood Corner Partner',
'company_id': self.env.user.company_id.id,
})
self.product1 = self.env['product.product'].create({
'name': 'Large Desk',
'standard_price': 1299.0,
'list_price': 1799.0,
'type': 'product',
})
Account = self.env['account.account']
self.stock_input_account = Account.create({
'name': 'Stock Input',
@@ -290,8 +298,8 @@ def setUp(self):
super(TestStockValuationWithCOA, self).setUp()
self.supplier_location = self.env.ref('stock.stock_location_suppliers')
self.stock_location = self.env.ref('stock.stock_location_stock')
self.partner_id = self.env.ref('base.res_partner_1')
self.product1 = self.env.ref('product.product_product_8')
self.partner_id = self.env['res.partner'].create({'name': 'Wood Corner Partner'})
self.product1 = self.env['product.product'].create({'name': 'Large Desk'})

cat = self.env['product.category'].create({
'name': 'cat',
@@ -519,6 +527,7 @@ def test_average_realtime_anglo_saxon_valuation_multicurrency_same_date(self):
"""
company = self.env.user.company_id
company.anglo_saxon_accounting = True
company.currency_id = self.usd_currency

date_po = '2019-01-01'

@@ -580,12 +589,13 @@ def test_average_realtime_anglo_saxon_valuation_multicurrency_same_date(self):
})]
})

inv.post()
inv.with_context(caca=True).post()

move_lines = inv.line_ids
self.assertEqual(len(move_lines), 2)

payable_line = move_lines.filtered(lambda l: l.account_id.internal_type == 'payable')

self.assertEqual(payable_line.amount_currency, -100.0)
self.assertAlmostEqual(payable_line.balance, -66.67)

@@ -602,6 +612,7 @@ def test_realtime_anglo_saxon_valuation_multicurrency_different_dates(self):
"""
company = self.env.user.company_id
company.anglo_saxon_accounting = True
company.currency_id = self.usd_currency
self.product1.product_tmpl_id.categ_id.property_cost_method = 'average'
self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'

@@ -776,6 +787,7 @@ def test_average_realtime_with_delivery_anglo_saxon_valuation_multicurrency_diff
"""
company = self.env.user.company_id
company.anglo_saxon_accounting = True
company.currency_id = self.usd_currency
self.product1.product_tmpl_id.categ_id.property_cost_method = 'average'
self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'

@@ -935,6 +947,7 @@ def test_average_realtime_with_two_delivery_anglo_saxon_valuation_multicurrency_
"""
company = self.env.user.company_id
company.anglo_saxon_accounting = True
company.currency_id = self.usd_currency
exchange_diff_journal = company.currency_exchange_journal_id.exists()

date_po = '2019-01-01'
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.addons.account.tests.account_test_classes import AccountingTestCase


# YTI: If it works, could be moved into account_test_classes IMO
class StockAccountMinimalTest(AccountingTestCase):

@classmethod
def setUpClass(cls):
super(StockAccountMinimalTest, cls).setUpClass()

# Properties: Stock valuation account and journal
cls.env['ir.property'].create([{
'name': 'property_stock_valuation_account_id',
'fields_id': cls.env['ir.model.fields'].search([('model', '=', 'product.category'), ('name', '=', 'property_stock_valuation_account_id')], limit=1).id,
'value': 'account.account,%s' % (cls.stk.id),
'company_id': cls.env.ref('base.main_company').id,
}, {
'name': 'property_stock_valuation_journal',
'fields_id': cls.env['ir.model.fields'].search([('model', '=', 'product.category'), ('name', '=', 'property_stock_journal')], limit=1).id,
'value': 'account.journal,%s' % (cls.miscellaneous_journal.id),
'company_id': cls.env.ref('base.main_company').id,
}])

0 comments on commit bc948a5

Please sign in to comment.
You can’t perform that action at this time.