Files
odoo_source/addons/stock_dropshipping/tests/test_procurement_exception.py
T
Denis Ledoux 5ccc32fcf7 [IMP] tests: common.Form, can't write on invisible fields
In the web client, in a real use case, it's not possible
to write on fields which are invisible,
as it's not possible to write on fields which are readonly.

This is a first step in the goal to change the behavior
of the `groups=` attribute in the back-end views,
to remove them for the view instead of making them invisible.

This is mainly to reduce the diff of the revision that will introduce
the mentioned above behavior change.

As nodes with `groups=` will be removed from the view
when the user doesn't have the group, it's no longer possible
to set a value on a field having a `groups=` the user doesn't have
in the `Form` test class, as the field will no longer be at all in the
view.
However, these unit tests shouldn't have been able to set values
on invisible fields in the first place.
This revision therefore aims to correct the unit tests setting value
on fields which were invisible because the user executing the
test was not part of the required group(s) for these fields
to be visible in the view.

closes odoo/odoo#94337

Related: odoo/enterprise#28936
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
2022-07-08 14:33:47 +02:00

72 lines
3.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import common, Form
class TestProcurementException(common.TransactionCase):
def test_00_procurement_exception(self):
# Required for `partner_invoice_id` to be visible in the view
self.env.user.groups_id += self.env.ref('account.group_delivery_invoice_address')
# Required for `route_id` to be visible in the view
self.env.user.groups_id += self.env.ref('stock.group_adv_location')
res_partner_2 = self.env['res.partner'].create({'name': 'My Test Partner'})
res_partner_address = self.env['res.partner'].create({
'name': 'My Test Partner Address',
'parent_id': res_partner_2.id,
})
# I create a product with no supplier define for it.
product_form = Form(self.env['product.product'])
product_form.name = 'product with no seller'
# <field name="list_price" position="attributes">
# <attribute name="attrs">{'readonly': [('product_variant_count', '&gt;', 1)]}</attribute>
# <attribute name="invisible">1</attribute>
# </field>
# <field name="list_price" position="after">
# <field name="lst_price" class="oe_inline" widget='monetary' options="{'currency_field': 'currency_id', 'field_digits': True}"/>
# </field>
# @api.onchange('lst_price')
# def _set_product_lst_price(self):
# ...
# product.write({'list_price': value})
product_form.lst_price = 20.00
product_form.categ_id = self.env.ref('product.product_category_1')
product_with_no_seller = product_form.save()
product_with_no_seller.standard_price = 70.0
# I create a sales order with this product with route dropship.
so_form = Form(self.env['sale.order'])
so_form.partner_id = res_partner_2
so_form.partner_invoice_id = res_partner_address
so_form.partner_shipping_id = res_partner_address
so_form.payment_term_id = self.env.ref('account.account_payment_term_end_following_month')
with so_form.order_line.new() as line:
line.product_id = product_with_no_seller
line.product_uom_qty = 3
line.route_id = self.env.ref('stock_dropshipping.route_drop_shipping')
sale_order_route_dropship01 = so_form.save()
# I confirm the sales order, but it will raise an error
with self.assertRaises(Exception):
sale_order_route_dropship01.action_confirm()
# I set the at least one supplier on the product.
with Form(product_with_no_seller) as f:
with f.seller_ids.new() as seller:
seller.delay = 1
seller.partner_id = res_partner_2
seller.min_qty = 2.0
# I confirm the sales order, no error this time
sale_order_route_dropship01.action_confirm()
# I check a purchase quotation was created.
purchase = self.env['purchase.order.line'].search([
('sale_line_id', '=', sale_order_route_dropship01.order_line.ids[0])]).order_id
self.assertTrue(purchase, 'No Purchase Quotation is created')