Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] Added test for this module #144

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
72 changes: 72 additions & 0 deletions purchase_stock_ux/test/test_purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests.common import SingleTransactionCase
from odoo.tests import Form, tagged
from odoo.exceptions import AccessError


@tagged('post_install', '-at_install')
class TestPurchaseOrder(SingleTransactionCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
# Create a users
group_purchase_user = cls.env.ref('purchase.group_purchase_user')
group_employee = cls.env.ref('base.group_user')
group_system = cls.env.ref('base.group_system')

cls.purchase_user = cls.env['res.users'].with_context(
no_reset_password=True
).create({
'name': 'Purchase user',
'login': 'purchaseUser',
'email': '[email protected]',
'groups_id': [(6, 0, [group_purchase_user.id, group_employee.id])],
})

cls.vendor = cls.env['res.partner'].create({
'name': 'Supplier',
'email': '[email protected]',
})
cls.product = cls.env['product.product'].create({
'name': "Product",
'standard_price': 200.0,
'list_price': 180.0,
'type': 'product',
})

def test_create_purchase_order(self):
"""Check a purchase user can create a vendor bill from a purchase order but not post it"""
purchase_order_form = Form(self.env['purchase.order'].with_user(self.purchase_user))
purchase_order_form.partner_id = self.vendor
with purchase_order_form.order_line.new() as line:
line.name = self.product.name
line.product_id = self.product
line.product_qty = 4
line.price_unit = 5

purchase_order = purchase_order_form.save()

# purchase_order.order_line.qty_received = 4
# purchase_order.action_create_invoice()
# invoice = purchase_order.invoice_ids
# with self.assertRaises(AccessError):
# invoice.action_post()


def test_force_delivery_status_with_user_allowed(self):
cls.purchase_user.write({'groups_id': [(4, group_system.id)]})
purchase_order.write({'force_delivered_status' : 'received'})
self.assertEqual(purchase_order.delivery_status, 'received')

def test_force_delivery_status_without_user_allowed(self):
cls.purchase_user.write({'groups_id': [(3, group_system.id)]})
with self.assertRaises(AccessError):
purchase_order.write({'force_delivered_status' : 'received'})
# self.assertEqual(purchase_order.delivery_status, 'received')

def test_confirm_order(self):
purchase_order.internal_note = 'lo que sea'
purchase_order.button_confirm()
self.assertEqual(purchase_order.picking_ids.note, purchase_order.internal_note)
Empty file.