本文整理汇总了Python中odoo.tests.common.Form.save方法的典型用法代码示例。如果您正苦于以下问题:Python Form.save方法的具体用法?Python Form.save怎么用?Python Form.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类odoo.tests.common.Form
的用法示例。
在下文中一共展示了Form.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sale_mrp
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_sale_mrp(self):
warehouse0 = self.env.ref('stock.warehouse0')
# In order to test the sale_mrp module in OpenERP, I start by creating a new product 'Slider Mobile'
# I define product category Mobile Products Sellable.
with mute_logger('odoo.tests.common.onchange'):
# Suppress warning on "Changing your cost method" when creating a
# product category
pc = Form(self.env['product.category'])
pc.name = 'Mobile Products Sellable'
product_category_allproductssellable0 = pc.save()
uom_unit = self.env.ref('uom.product_uom_unit')
self.assertIn("seller_ids", self.env['product.template'].fields_get())
# I define product for Slider Mobile.
product = Form(self.env['product.template'])
product.categ_id = product_category_allproductssellable0
product.list_price = 200.0
product.name = 'Slider Mobile'
product.standard_price = 189.0
product.type = 'product'
product.uom_id = uom_unit
product.uom_po_id = uom_unit
product.route_ids.clear()
product.route_ids.add(warehouse0.manufacture_pull_id.route_id)
product.route_ids.add(warehouse0.mto_pull_id.route_id)
product_template_slidermobile0 = product.save()
product_component = Form(self.env['product.product'])
product_component.name = 'Battery'
product_product_bettery = product_component.save()
with Form(self.env['mrp.bom']) as bom:
bom.product_tmpl_id = product_template_slidermobile0
with bom.bom_line_ids.new() as line:
line.product_id = product_product_bettery
line.product_qty = 4
# I create a sale order for product Slider mobile
so_form = Form(self.env['sale.order'])
so_form.partner_id = self.env.ref('base.res_partner_4')
with so_form.order_line.new() as line:
line.product_id = product_template_slidermobile0.product_variant_ids
line.price_unit = 200
line.product_uom_qty = 500.0
line.customer_lead = 7.0
sale_order_so0 = so_form.save()
# I confirm the sale order
sale_order_so0.action_confirm()
# I verify that a manufacturing order has been generated, and that its name and reference are correct
mo = self.env['mrp.production'].search([('origin', 'like', sale_order_so0.name)], limit=1)
self.assertTrue(mo, 'Manufacturing order has not been generated')
示例2: test_required
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_required(self):
f = Form(self.env['test_testing_utilities.a'])
# f1 no default & no value => should fail
with self.assertRaisesRegexp(AssertionError, 'f1 is a required field'):
f.save()
# set f1 and unset f2 => should work
f.f1 = 1
f.f2 = False
r = f.save()
self.assertEqual(
(r.f1, r.f2, r.f3, r.f4),
(1, 0, 0, 0)
)
示例3: test_set
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_set(self):
"""
Checks that we get/set recordsets for m2o & that set correctly
triggers onchange
"""
r1 = self.env['test_testing_utilities.m2o'].create({'name': "A"})
r2 = self.env['test_testing_utilities.m2o'].create({'name': "B"})
f = Form(self.env['test_testing_utilities.c'])
# check that basic manipulations work
f.f2 = r1
self.assertEqual(f.f2, r1)
self.assertEqual(f.name, 'A')
f.f2 = r2
self.assertEqual(f.name, 'B')
# can't set an int to an m2o field
with self.assertRaises(AssertionError):
f.f2 = r1.id
self.assertEqual(f.f2, r2)
self.assertEqual(f.name, 'B')
# can't set a record of the wrong model
temp = self.env['test_testing_utilities.readonly'].create({})
with self.assertRaises(AssertionError):
f.f2 = temp
self.assertEqual(f.f2, r2)
self.assertEqual(f.name, 'B')
r = f.save()
self.assertEqual(r.f2, r2)
示例4: test_o2m_remove
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_o2m_remove(self):
def commands():
return [c[0] for c in f._values['line_ids']]
f = Form(self.env['test_testing_utilities.onchange_count'])
self.assertEqual(f.count, 0)
self.assertEqual(len(f.line_ids), 0)
f.count = 5
self.assertEqual(f.count, 5)
self.assertEqual(len(f.line_ids), 5)
f.count = 2
self.assertEqual(f.count, 2)
self.assertEqual(len(f.line_ids), 2)
f.count = 4
r = f.save()
previous = r.line_ids
self.assertEqual(len(previous), 4)
with Form(r) as f:
f.count = 2
self.assertEqual(commands(), [0, 0, 2, 2, 2, 2], "Should contain 2 creations and 4 deletions")
self.assertEqual(len(r.line_ids), 2)
with Form(r) as f:
f.line_ids.remove(0)
self.assertEqual(commands(), [2, 1])
f.count = 1
self.assertEqual(commands(), [0, 2, 2], "should contain 1 '0' command and 2 deletions")
self.assertEqual(len(r.line_ids), 1)
示例5: test_o2m_editable_list
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_o2m_editable_list(self):
""" Tests the o2m proxy when the list view is editable rather than
delegating to a separate form view
"""
f = Form(self.env['test_testing_utilities.parent'], view='test_testing_utilities.o2m_parent_ed')
custom_tree = self.env.ref('test_testing_utilities.editable_external').id
subs_field = f._view['fields']['subs']
tree_view = subs_field['views']['tree']
self.assertEqual(tree_view['type'], 'tree')
self.assertEqual(
tree_view['view_id'], custom_tree,
'check that the tree view is the one referenced by tree_view_ref'
)
self.assertIs(subs_field['views']['edition'], tree_view, "check that the edition view is the tree view")
self.assertEqual(
subs_field['views']['edition']['view_id'],
custom_tree
)
with f.subs.new() as s:
s.value = 1
with f.subs.new() as s:
s.value = 3
with f.subs.new() as s:
s.value = 7
r = f.save()
self.assertEqual(r.v, 12)
self.assertEqual(
[get(s) for s in r.subs],
[('1', 1, 1), ('3', 3, 3), ('7', 7, 7)]
)
示例6: test_state
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_state(self):
f = Form(self.env['account.invoice'])
f.partner_id = self.env.ref('base.res_partner_12')
with f.invoice_line_ids.new() as l:
l.product_id = self.env.ref('product.product_product_3')
invoice = f.save()
# I check that Initially customer invoice state is "Draft"
self.assertEqual(invoice.state, 'draft')
# I called the "Confirm Draft Invoices" wizard
w = Form(self.env['account.invoice.confirm']).save()
# I clicked on Confirm Invoices Button
w.with_context(
active_model='account.invoice',
active_id=invoice.id,
active_ids=invoice.ids,
type='out_invoice',
).invoice_confirm()
# I check that customer invoice state is "Open"
self.assertEqual(invoice.state, 'open')
# Electronic invoice must be present and have the same name as l10n_it_einvoice_name
self.assertEqual(invoice.l10n_it_einvoice_id.name, invoice.l10n_it_einvoice_name)
示例7: _create_invoice_from_file
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def _create_invoice_from_file(self, attachment):
self = self.with_context(default_journal_id=self.journal_id.id)
invoice_form = Form(self.env['account.invoice'], view='account.invoice_supplier_form')
invoice = invoice_form.save()
attachment.write({'res_model': 'account.invoice', 'res_id': invoice.id})
invoice.message_post(attachment_ids=[attachment.id])
return invoice
示例8: test_defaults
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_defaults(self):
"""
Checks that we can load a default form view and perform trivial
default_get & onchanges & computations
"""
f = Form(self.env['test_testing_utilities.a'])
self.assertEqual(f.id, False, "check that our record is not in db (yet)")
self.assertEqual(f.f2, 42)
self.assertEqual(f.f3, 21)
self.assertEqual(f.f4, 42)
f.f1 = 4
self.assertEqual(f.f2, 42)
self.assertEqual(f.f3, 21)
self.assertEqual(f.f4, 10)
f.f2 = 8
self.assertEqual(f.f3, 4)
self.assertEqual(f.f4, 2)
r = f.save()
self.assertEqual(
(r.f1, r.f2, r.f3, r.f4),
(4, 8, 4, 2),
)
示例9: test_m2m_readonly
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_m2m_readonly(self):
Sub = self.env['test_testing_utilities.sub3']
a = Sub.create({'name': 'a'})
b = Sub.create({'name': 'b'})
r = self.env['test_testing_utilities.g'].create({
'm2m': [(6, 0, a.ids)]
})
f = Form(r)
with self.assertRaises(AssertionError):
f.m2m.add(b)
with self.assertRaises(AssertionError):
f.m2m.remove(id=a.id)
f.save()
self.assertEqual(r.m2m, a)
示例10: create_payment
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def create_payment(self, invoices):
payment_register = Form(self.env['account.payment'].with_context(active_model='account.invoice', active_ids=invoices.ids))
payment_register.payment_date = time.strftime('%Y') + '-07-15'
payment_register.journal_id = self.bank_journal
payment_register.payment_method_id = self.payment_method_check
payment = payment_register.save()
payment.post()
return payment
示例11: _create_product
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def _create_product(self, name, uom_id, routes=()):
p = Form(self.env['product.product'])
p.name = name
p.type = 'product'
p.uom_id = uom_id
p.uom_po_id = uom_id
p.route_ids.clear()
for r in routes:
p.route_ids.add(r)
return p.save()
示例12: test_default_and_onchange
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_default_and_onchange(self):
""" Checks defaults & onchanges impacting m2o fields
"""
Sub = self.env['test_testing_utilities.m2o']
a = Sub.create({'name': "A"})
b = Sub.create({'name': "B"})
f = Form(self.env['test_testing_utilities.d'])
self.assertFalse(
f.f,
"The default value gets overridden by the onchange"
)
f.f2 = "B"
self.assertEqual(
f.f, b,
"The new m2o value should match the second field by name"
)
f.save()
示例13: test_default_and_onchange
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_default_and_onchange(self):
""" Checks defaults & onchanges impacting m2o fields
"""
Sub = self.env['test_testing_utilities.m2o']
a = Sub.create({'name': "A"})
b = Sub.create({'name': "B"})
f = Form(self.env['test_testing_utilities.d'])
self.assertEqual(
f.f, a,
"The default value for the m2o should be the first Sub record"
)
f.f2 = "B"
self.assertEqual(
f.f, b,
"The new m2o value should match the second field by name"
)
f.save()
示例14: test_department_leave
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_department_leave(self):
""" Create a department leave """
self.employee_hrmanager.write({'department_id': self.hr_dept.id})
self.assertFalse(self.env['hr.leave'].search([('employee_id', 'in', self.hr_dept.member_ids.ids)]))
leave_form = Form(self.env['hr.leave'].sudo(self.user_hrmanager), view='hr_holidays.hr_leave_view_form_manager')
leave_form.holiday_status_id = self.holidays_type_1
leave_form.holiday_type = 'department'
leave_form.department_id = self.hr_dept
leave = leave_form.save()
leave.action_approve()
member_ids = self.hr_dept.member_ids.ids
self.assertEqual(self.env['hr.leave'].search_count([('employee_id', 'in', member_ids)]), len(member_ids), "Leave should be created for members of department")
示例15: test_readonly_save
# 需要导入模块: from odoo.tests.common import Form [as 别名]
# 或者: from odoo.tests.common.Form import save [as 别名]
def test_readonly_save(self):
""" Should not save readonly fields unless they're force_save
"""
f = Form(self.env['test_testing_utilities.a'], view='test_testing_utilities.non_normalized_attrs')
f.f1 = '1'
f.f2 = 987
self.assertEqual(f.f5, 987)
self.assertEqual(f.f6, 987)
r = f.save()
self.assertEqual(r.f5, 0)
self.assertEqual(r.f6, 987)