0
votes

These are required for website in a Signup Form (2 requirements):

I have added a field zone_id in model res.users and Signup Form (website) which will select a zone. I want to show another field value zone_status (a selection field) with the name of the zone, like below:

Zone1 - Active

Zone2 - Active

Zone3 - InActive

etc.

How can it be done? And also I need guide to show Many2one field rows to select from list as normally in Odoo's own UI. It shows automatically, but not in website page/form. Currently, I have it as Text, how to modify it to behave/show as Many2one field:

<div class="form-group field-zone_id">
   <label for="zone_id">Your Zone</label>
   <input type="text" name="zone_id" id="zone_id" class="form-control form-control-sm"/>
</div>
1

1 Answers

1
votes

For your first question you can overwrite the name_get method in the model that you have a m2o relation with and configure the concatenation string as you like. See the bellow example

def name_get(self):
    return [(record.id, record.name) for record in self]

Fleet module example link

@api.depends('name', 'brand_id')
def name_get(self):
    res = []
    for record in self:
        name = record.name
        if record.brand_id.name:
            name = record.brand_id.name + '/' + name
        res.append((record.id, name))
    return res

or make a new computed field with your string. See the below example from odoo product category link

class ProductCategory(models.Model):
    _name = "product.category"
    #...
    _rec_name = 'complete_name'
    _order = 'complete_name'

    name = fields.Char('Name', index=True, required=True)
    complete_name = fields.Char(
        'Complete Name', compute='_compute_complete_name',
        store=True)

    #...

    @api.depends('name', 'parent_id.complete_name')
    def _compute_complete_name(self):
        for category in self:
            if category.parent_id:
                category.complete_name = '%s / %s' % (category.parent_id.complete_name, category.name)
            else:
                category.complete_name = category.

For the second question you can read the data like so. See the below example form website_sale module link

<div t-attf-class="form-group #{error.get('country_id') and 'o_has_error' or ''} col-lg-6 div_country">
    <label class="col-form-label" for="country_id">Country</label>
    <select id="country_id" name="country_id" t-attf-class="form-control #{error.get('country_id') and 'is-invalid' or ''}">
        <option value="">Country...</option>
        <t t-foreach="countries" t-as="c">
            <option t-att-value="c.id" t-att-selected="c.id == (country and country.id or -1)">
                <t t-esc="c.name" />
            </option>
        </t>
    </select>
</div>