Open form with manageable products - odoo-8

In Bill Of Materials we can make product from other products. as you can see in picture 1 there is Test Product made from 2 other product.
in Sale Order line I made button that opens this form with Product Price and Qty
But the goal is to open form where i can manage products that Test Product are build from and change qty and price there.
<record id="view_order_line_form_view" model="ir.ui.view">
<field name="name">sale.order.line.forma</field>
<field name="model">sale.order.line</field>
<field name="arch" type="xml">
<form string="Sales Order Lines">
<field name="product_id" />
<field name="product_uom_qty" string="Qty" placeholder="Qty"/>
<field name="price_unit" string="Price"/>
</form>
</field>
</record>
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
#api.multi
def button_details(self):
context = self.env.context.copy()
context['view_buttons'] = True
view_id = self.env.ref('cfg.view_order_line_form_view').id
view = {
'name': _('Details'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'sale.order.line',
'views' : [(view_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
'readonly': True,
'res_id': self.id,
'context': context
}
return view

Related

How do I a add time stamps to Redux-From?

below is my attempt to add a timestamp to when user submits form.
renderTimeStamp = ({ input, label }) => {
return (
{label}
<input {Date.now()} />
);
};
<Field
name="timestamp"
component={this.renderTimeStamp}
placeholder={moment().format()}
label="Time Stamp"
/>

Odoo 11: Domain on many2many field not working

<record model="ir.actions.act_window" id="action_purchase_orders">
<field name="name">Purchase Orders</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('id', 'in', purchase_order_ids.ids)]</field> <------- This is not working.
</record>
<record id="purchase.form" model="ir.ui.view">
<field name="name">purchase.form</field>
<field name="model">purchase.form</field>
<field name="arch" type="xml">
<form string="Purchase Form">
<sheet>
<div class="oe_button_box" name="button_box">
<button type="action" name="%(action_purchase_orders)d" class="oe_stat_button" icon="fa-list-alt"
attrs="{'invisible':[('purchase_order_count', '=', 0)]}">
<field name="purchase_order_count" invisible="1"/>
<field name="purchase_order_ids" string="Purchase Orders" widget="statinfo" help="Purchase orders"/>
</button>
...
class PurchaseForm(models.Model):
_name = 'purchase.form'
#api.depends('purchase_order_ids')
def _purchase_order_count(self):
for pp in self:
pp.purchase_order_count = len(pp.purchase_order_ids)
purchase_order_ids = fields.Many2many('purchase.order', 'purchase_form_purchase_order_rel', 'purchase_form_id', 'purchase_order_id', 'Purchase Orders', states=READONLY_STATES)
purchase_order_count = fields.Integer(compute='_purchase_order_count', string='# of Purchase Orders')
Error:
Uncaught Error: NameError: name 'purchase_order_ids' is not defined
http://localhost:8069/web/content/801-4161526/web.assets_backend.js:144
Traceback:
Error: NameError: name 'purchase_order_ids' is not defined
at PY_ensurepy (http://localhost:8069/web/content/801-4161526/web.assets_backend.js:144:65)
at Object.py.evaluate (http://localhost:8069/web/content/801-4161526/web.assets_backend.js:259:8)
at Object.py.evaluate (http://localhost:8069/web/content/801-4161526/web.assets_backend.js:267:99)
at Object.py.evaluate (http://localhost:8069/web/content/801-4161526/web.assets_backend.js:268:194)
at Object.py.eval (http://localhost:8069/web/content/801-4161526/web.assets_backend.js:272:284)
at http://localhost:8069/web/content/801-4161526/web.assets_backend.js:377:110
at iterator (http://localhost:8069/web/content/800-e6de2a4/web.assets_common.js:14:183)
at Function.<anonymous> (http://localhost:8069/web/content/800-e6de2a4/web.assets_common.js:17:8)
at _.(anonymous function) [as reduce] (http://localhost:8069/web/content/800-e6de2a4/web.assets_common.js:69:526)
at eval_contexts (http://localhost:8069/web/content/801-4161526/web.assets_backend.js:375:136)
You cannot do that in the action_purchase_orders view action, you cannot use a field in the right side of domain tuples, because there will be no context to supply that value. To get it done you will need to change your button to be of type object and using a python method associated return the action dict with the desired domain values evaluated so the domain only contain values for their right side tuples. Like(see the new type and name for the button):
<button type="object" name="action_purchase_orders" class="oe_stat_button" icon="fa-list-alt" attrs="{'invisible':[('purchase_order_count', '=', 0)]}">
<field name="purchase_order_count" invisible="1"/>
<field name="purchase_order_ids" string="Purchase Orders" widget="statinfo" help="Purchase orders"/>
</button>
In your purchase.form model define the method action_purchase_orders, like:
#api.multi
def action_purchase_orders(self):
self.ensure_one()
return {
'name': _('Purchase Orders'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'purchase.order',
'target': 'new',
'domain': [('id', 'in', self.purchase_order_ids.ids)]
'context': self.env.context.copy(),
}
Add relation to purchase.order
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
purchase_form_ids = fields.Many2many('purchase.form', 'purchase_form_purchase_order_rel', 'purchase_order_id', 'purchase_form_id', 'Purchase Orders')
and change action view to
<record model="ir.actions.act_window" id="action_purchase_orders">
<field name="name">Purchase Orders</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('id', 'in', purchase_form_ids.ids)]</field>
</record>

How to edit filters and fields that appear in add custom filter option in a module in Odoo 10

I'm new to odoo, I need to delete some fields that appear when click add a custom filter in a fleet module in odoo 10, and how to add custom filters and delete existing ones?
Thank you for any help.
You can use field_get() to change field attribute "selectable", which is used in search_menu.js in web module to decide what fields to show when clicking "Add Custom Filter. Try this:
selectable_fields = ['field1',...]
#api.model
def fields_get(self, allfields=None, attributes=None):
res = super(YourModel, self).fields_get(allfields, attributes=attributes)
not_selectable_fields = set(self._fields.keys()) - set(self.selectable_fields)
for field in not_selectable_fields:
res[field]['selectable'] = False
return res
Related code in search_menu.js:
get_fields: function () {
if (!this._fields_def) {
this._fields_def = data_manager.load_fields(this.searchview.dataset).then(function (data) {
var fields = {
id: { string: 'ID', type: 'id', searchable: true }
};
_.each(data, function(field_def, field_name) {
if (field_def.selectable !== false && field_name !== 'id') {
fields[field_name] = field_def;
}
});
return fields;
});
}
return this._fields_def;
},
Add this filter to your code.
For example: To add filter in Sale Order Line.
<record id="inherit_so_line_filter_view" model="ir.ui.view">
<field name="name">sale.order.list.available</field>
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale.view_sales_order_line_filter"/>
<field name="arch" type="xml">
<search>
<filter string="Pending" domain="[('remian_qty','>',0)]" name = "qty_available"/>
<filter string="Lost" domain="[('remian_qty','=',0)]" name = "qty_lost"/>
</search>
</field>
</record>
For example: To add filter using xpath in Sale Order.
<record id="view_sale_order_inherit_search" model="ir.ui.view">
<field name="name">sale.order.search.filter</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.sale_order_view_search_inherit_quotation"/>
<field name="arch" type="xml">
<xpath expr="//search" position="inside">
<filter string="Total < 1000" name="total_under_1000" domain="[('amount_total', '<', 1000)]"/>
<filter string="Total >= 1000" name="total_above_1000" domain="[('amount_total', '>=', 1000)]"/>
</xpath>
</field>
</record>
Inherit the existing filter like this:
<record id="any_id_name" model="ir.ui.view">
<field name="name">model.nameinsearchview</field>
<field name="model">model.name</field>
<field name="inherit_id" ref="external_id/>
<field name="arch" type="xml">
<filter name="that_field_name_in_exisiting_filter_view" position="replace">
</filter>
</field>
</record>
that's it. Now this will replace the existing code.

defaultValue in AOR-dependent-input

I want to set defaultValue for field in aor-dependent-input,
I already set defaultValue for ReferenceInput, but how can I set defaultValue for DependentInput using SubGenreInput
Here is my code:
<Create {...propsEdit} title=" " actions="">
<SimpleForm redirect={"/caregiver/" + cid}>
{/*<ReferenceArrayInput>*/}
<DisabledInput source="user" defaultValue={cid} label="Caregiver ID"/>
<ReferenceInput label="Centre" source="centre" defaultValue={this.props.record.student.centre.id} reference="centre" sort={{ field: 'name', order: 'ASC' }} allowEmpty>
<SelectInput optionText="name" />
</ReferenceInput>
<DependentInput dependsOn="centre">
<SubGenreInput source="current_group" optionText="label" optionValue="id" type="classgroup"/>
</DependentInput>
<DependentInput dependsOn="current_group" defaultValue={this.props.record.student.id}>
<SubGenreInput source="student_id" optionText="fullname" optionValue="id" type="student"/>
</DependentInput>
{/*</ReferenceArrayInput>*/}
<RadioButtonGroupInput source="account_type" defaultValue={10} choices={[
{ id: 10, name: 'Caregiver' },
{ id: 20, name: 'Guardian' },
]} optionText="name" optionValue="id" />
<TextInput source="relationship" label="Relationship"/>
</SimpleForm>
Interface:
https://i.stack.imgur.com/wFHKC.png
// I'm not allow to post the images :(
This is a known issue which will be addressed by version 1.3.0 of admin-on-rest. In the mean time you can use this workaround:
<DependentInput source="appointmentTimeslot" dependsOn="planned" defaultValue={1}>
<ReferenceInput source="appointmentTimeslot" reference="timeslots" allowEmpty={true} >
<SelectInput optionText="name" optionValue="id" />
</ReferenceInput>
</DependentInput>
Note that we specified source on both the DependentInput component and its child. The defaultValue, however, is specified on the DependentInput component only.
This workaround won't work if you pass multiple children to the DependentInput component.

Independent "Submit" button for tabbed form in Create

I already made 2 types of create page:
Create single record.
Import multiple records from xlsx file.
Now I want to implement 2 independent buttons:
Save
Import
meaning that when I click on button 1, only button 1 works.
Here is my code:
<Create {...this.props}>
<TabbedForm toolbar="">
<FormTab label="Single record">
<ReferenceInput label="Centre" source="centre" reference="centre" sort={{ field: 'name', order: 'ASC' }} allowEmpty>
<SelectInput optionText="name" />
</ReferenceInput>
<TextInput source="fullname" />
<TextInput source="serial " />
<TextInput source="birthday" />
<TextInput source="join_date" />
<TextInput source="remark" />
<SaveButton label="Save" redirect="show" submitOnEnter={true} />
</FormTab>
<FormTab label="Import from xlsx">
<ReferenceInput label="Centre" source="centre_import" reference="centre" sort={{ field: 'name', order: 'ASC' }} allowEmpty>
<SelectInput optionText="name" />
</ReferenceInput>
<label id="customLabel">
<input id="upload" ref={(input) => { this.textInput = input; }} type="file" hidden
onClick={(event)=> {
event.target.value = null;
}}
onChange={
(event) => {
this.fileName.textContent = event.target.files[0].name;
}
}
/>
<FlatButton primary label="Select file" icon={<ActionFile />} onClick={() => {
this.textInput.click();
}}/>
<span id="fileName" ref={(span) => { this.fileName = span; }}></span>
</label>
<SaveButton label="Import" redirect={false} submitOnEnter={true} />
</FormTab>
</TabbedForm>
</Create>
The easiest way would be to keep a single button here. You may add a text inside the importation tab explaining that clicking on save will import the file.
However, you still have to deal with the redirection. To do so, you'll have to implement a custom SaveButton:
Copy the code of the default SaveButton into a SaveOrImportButton file.
Update its mapStateToProps function and use redux-form getFormValues selector to inspect the form values and determine whether its an importation.
Use this knowledge to customize the button:
You may update the label to Import if the user selected a file. The label will update immediately after the file field gets dirty.
You can change the redirect value at L22.
Use this button inside a Toolbar component and pass this component to the toolbar prop of the Create component.

Resources