Skip to Content
Menu
This question has been flagged
1 Reply
5220 Views
Initially, I immediately wrote the data to the database, but I need to record everything only after the user clicks the save button, now I try to return the data in the view edit form, but I don’t know how to do it correctly. I have a button when this button is clicked, this function starts and I need to return the user’s data from it (so that he can check \ add) and then just save it to the database.

 

@api.multi
def get_form_fields(self):
html = requests.get(self.form_url)

soup = BeautifulSoup(html.text, 'html.parser')

form_inputs = soup.find_all('input')
form_selects = soup.find_all('select')

fields_lines = []

#Find all inputs on page
for i in form_inputs:
vals_inputs = {}
vals_inputs['form_field_name'] = i.get('name')
vals_inputs['form_bot'] = self.id
try:
type_field = i.get('type')
if type_field == 'hidden':
vals_inputs['hidden_field'] = True
except:
pass

fields_lines.append((0, 0, vals_inputs))
# self.env['model.forms_bot_fileds'].create(vals_inputs)

#find all select fields on page
for i in form_selects:

vals_slects = {}
vals_slects['form_field_name'] = i.get('name')
vals_slects['form_bot'] = self.id

fields_lines.append((0, 0, vals_slects))

# self.env['model.forms_bot_fileds'].create(vals_slects)
How can I do that

https://ibb.co/gy1gtKW

i need to fill Form Fields from the code above 
Avatar
Discard
Author Best Answer


I found the solution in  odoo models.py in the write method description

""" write(vals)

Updates all records in the current set with the provided values.

:param dict vals: fields to update and the value to set on them e.g::

{'foo': 1, 'bar': "Qux"}

will set the field ``foo`` to ``1`` and the field ``bar`` to
``"Qux"`` if those are valid (otherwise it will trigger an error).

:raise AccessError: * if user has no write rights on the requested object
* if user tries to bypass access rules for write on the requested object
:raise ValidateError: if user tries to enter invalid value for a field that is not in selection
:raise UserError: if a loop would be created in a hierarchy of objects a result of the operation (such as setting an object as its own parent)

* For numeric fields (:class:`~odoo.fields.Integer`,
:class:`~odoo.fields.Float`) the value should be of the
corresponding type
* For :class:`~odoo.fields.Boolean`, the value should be a
:class:`python:bool`
* For :class:`~odoo.fields.Selection`, the value should match the
selection values (generally :class:`python:str`, sometimes
:class:`python:int`)
* For :class:`~odoo.fields.Many2one`, the value should be the
database identifier of the record to set
* Other non-relational fields use a string for value

.. danger::

for historical and compatibility reasons,
:class:`~odoo.fields.Date` and
:class:`~odoo.fields.Datetime` fields use strings as values
(written and read) rather than :class:`~python:datetime.date` or
:class:`~python:datetime.datetime`. These date strings are
UTC-only and formatted according to
:const:`odoo.tools.misc.DEFAULT_SERVER_DATE_FORMAT` and
:const:`odoo.tools.misc.DEFAULT_SERVER_DATETIME_FORMAT`
* .. _openerp/models/relationals/format:

:class:`~odoo.fields.One2many` and
:class:`~odoo.fields.Many2many` use a special "commands" format to
manipulate the set of records stored in/associated with the field.

This format is a list of triplets executed sequentially, where each
triplet is a command to execute on the set of records. Not all
commands apply in all situations. Possible commands are:

``(0, _, values)``
adds a new record created from the provided ``value`` dict.
``(1, id, values)``
updates an existing record of id ``id`` with the values in
``values``. Can not be used in :meth:`~.create`.
``(2, id, _)``
removes the record of id ``id`` from the set, then deletes it
(from the database). Can not be used in :meth:`~.create`.
``(3, id, _)``
removes the record of id ``id`` from the set, but does not
delete it. Can not be used on
:class:`~odoo.fields.One2many`. Can not be used in
:meth:`~.create`.
``(4, id, _)``
adds an existing record of id ``id`` to the set. Can not be
used on :class:`~odoo.fields.One2many`.
``(5, _, _)``
removes all records from the set, equivalent to using the
command ``3`` on every record explicitly. Can not be used on
:class:`~odoo.fields.One2many`. Can not be used in
:meth:`~.create`.
``(6, _, ids)``
replaces all existing records in the set by the ``ids`` list,
equivalent to using the command ``5`` followed by a command
``4`` for each ``id`` in ``ids``.

.. note:: Values marked as ``_`` in the list above are ignored and
can be anything, generally ``0`` or ``False``.
"""

i have field with one2many relation and it was enough to write self.my_one2Many_field = fields_lines


Avatar
Discard
Related Posts Replies Views Activity
2
Sep 23
6554
3
Oct 18
17038
4
Dec 23
11965
1
Nov 18
4946
5
Aug 24
42974