I add a field in account.payment.
bank_id = fields.Many2one('res.bank', string="Bank")
when i clicked the register payment button in account.invoice then it is opened a register payment wizard.
I want to invisible the bank_id based on the condition
journal_id.type not in bank
How it is possible in odoo??
in xml I add a condition like this.
attrs="{'invisible': [('journal_id.type', 'not in', ['bank'])]}"
How to correct the condition??
in this situation you can not apply direct attrs so you have to take one compute boolean field to check the journal type and based on that field make bank_id visible or invisible
in account.payment
from odoo import models, fields, api, _
class account_payment(models.Model):
_inherit = "account.payment"
bank_id = fields.Many2one('res.bank', string="Bank")
check_journal = fields.Boolean(string="Journal Type", compute='_check_journal_type')
#api.depends('journal_id')
def _check_journal_type(self):
if self.journal_id.type == 'bank':
self.check_journal = False
else:
self.check_journal = True
in account.payment view
<field name="check_journal" invisible="1"/>
<field name="bank_id" attrs="{'invisible': [('check_journal', '=', True)]}"/>
Related
I'm using Yup to validate my Formik form, but I have no idea how to validate a radio input in Yup/Formik.
You validate the radio group. The only validation failure that is possible, is if you don't have a default button selected, and the user doesn't select any of the radio buttons.
Given:
<RadioButtonGroup
id="radioGroup"
label="One of these please"
value={values.radioGroup}
error={errors.radioGroup}
touched={touched.radioGroup}
>
<Field
component={RadioButton}
name="radioGroup"
id="radioOption1"
label="Choose this option"
/>
<Field
component={RadioButton}
name="radioGroup"
id="radioOption2"
label="Or choose this one"
/>
</RadioButtonGroup>
Validation code:
radioGroup: Yup.string().required("A radio option is required")
As used in context:
<Formik
...
validationSchema={Yup.object().shape({
radioGroup: Yup.string().required("A radio option is required"),
...
})}
Copied from this larger validation example:
https://gist.github.com/mrtony/c1ba5f8ec4122d2866b292fc36152d34
your radioInputGroup values:
state = {
gender: [
{
id: 0,
type: "woman",
text: interpreter("ImFemale")
}, {
id: 1,
type: "man",
text: interpreter("ImMale")
}
]
}
and your yup validationSchema:
ValidationSchema = Yup.object().shape({
gender: Yup.boolean().required().oneOf([0 , 1]),
});
note: you should to use gender values in .onOf() function.
if you want to show some msg for error message, use this code for yup validationSchema:
ValidationSchema = Yup.object().shape({
gender: Yup.boolean().required().oneOf([0 , 1], 'Selecting the gender field is required'),
});
Theoretically it shouldn't be different from any other value. You're tracking the radio value (or Formik's tracking it for you) somewhere in your state as a string most likely, and you simply need to apply the rules to the value that you're storing.
If you want to make sure the value matches only the presented radio options, you can use oneOf to accomplish that, but otherwise it's no different than any other scalar value.
A model [m] with a many2many field [m2m]
Field [m2m] have attribute [copy=False]
A form view [v] display the [m] and the field [m2m] with widget [many2many_tags]
I have tested that the python object did return a with False on field [m2m]
but the javascript, keep render the tags on web.
model.py
class model(models.Model):
_name = "m"
m2m = fields.Many2many('sale.order', string="SO", copy=False)
XML File
<record ...>
<form>
<group>
<field name="name"/>
<field name="ref"/>
<field name="so_m2m" widget="many2many_tags" options="{'no_create_edit': True}"/>
</group>
</form>
</record>
When I duplicate the current record, the field [m2m] is keeps the old tag from old record which is not expected.
After clicking the save button, the old tag will disappear.
Try one thing here :
Whatever your third table is there, both fields used in many2many relation, from third table keep them as a copy false.
i.e.
m2m = fields.Many2many('sale.order','sale_order_another_table_rel', 'sale_order_field','antother_table_field', string="SO", copy=False)
Into new table :
_name = 'sale.order.another.table.rel'
sale_order_field_id = // copy=false
another_table_field_id = //copy = false
Hopefully work.
I have a react-bootstrap class of a form. The code is something like that:
class MyReactClass extends Component {
// ....
render() {
return (
<div>
<Field name="combobox1" component={ComboBox} options={options} ></Field>
<Field name="textField2" component={My_TextField}></Field>
<Field name="textField3" component={My_TextField}></Field>
<Field name="textField4" component={My_TextField}></Field>
</div>
}
}
export default reduxForm({
form: 'myReactClass ',
}
)(MyReactClass );
I added an initialization to initialize some values:
componentDidMount() {
this.props.initialize({textField2:'blabla'});
}
Now I want that when the user selects a value from the combobox, it'll automatically change the value of textfield3. I have a WORKING onChange function for the combobox, but I can't find a way to change textfield3's value. I tried to use "initialize" again -
this.props.initialize({textField3: this.getUpdatedValue()});
but it initialize the whole form and the form gets cleared and have only the value for textfield3.
I tried to access this.props.textField3 but I got undefined.
How can I update the form's value?
this.props.change('textField3', this.getUpdatedValue()) would work.
Optionally, if you need the user to understand that the value was autofilled but can be manually changed, you can use:
this.props.autofill('textField3', this.getUpdatedValue())
These are described in the docs here.
There's a field of line_ids in the class of 'purchase.requisition' :
'line_ids' : fields.one2many('purchase.requisition.line','requisition_id',
'Products to Purchase',states={'done': [('readonly', True)]}),
And I add a many2one field to 'purchase.order.line' :
'requisition_line_id': fields.many2one('purchase.requisition.line' ,
u'Requisition Line',readonly = True , ondelete = 'restrict' ),
Now , how can I display then name field of 'purchase.requisition' in the view of 'purchase.order.line' ?
You can you fields.related.
Example :
class hr_employee(osv.osv):
_name = "hr.employee"
_columns = {
'address_id': fields.many2one('res.partner.address', 'Working Address'),
'city': fields.related('address_id', 'city', type='char', string='City'),
}
Then after add moduel_view.xml at appropriate place.
<field name="city" />
Here you see an example of fields.related.
Now similar try to fix your problem.
I hope this will be helpful for you.
Goto View Inheritance It will help you a lot.
I am using MVC3 Webgrid. I have model which has column of type bool. Based on the value of this column I need to render a column, with hyper link. If the bool column value is true then I have to render Record, else Edit.
Could you kindly give the syntax for these in Razor .
Thank you
You can use an if statement when you create the column, like so:
grid.Column("Conditional Cell Sample", format: #<text>#if(true == true) { #Html.ActionLink("Go here", "Home") } else { #Html.ActionLink("Or here", "Away") }</text>)
Simply replace true == true with your condition, and the content of if and else to be what you need.
Ref: http://lottemae.wordpress.com/2011/11/17/using-conditional-statements-in-an-mvc-3-webgrid-column-using-razor/