I have the documents as parent-child relationship:
https://gist.github.com/shadow-fox/fb525a7efe66622230e61d6253b6cfa9
How to sort the parent (type_s:product)s based on the grandchildren (type_s:vendor) field value ?
parent = type_s: product
children = type_s: sku
grandchildren = type_s:storage type_s:vendor
<doc>
<field name="id">10</field>
<field name="type_s">product</field>
<field name="BRAND_s">Nike</field>
<!-- nesting skus in product -->
<doc>
<field name="id">11</field>
<field name="type_s">sku</field>
<field name="COLOR_s">Red</field>
<field name="SIZE_s">XL</field>
<!-- nesting locations into sku -->
<doc>
<field name="id">13</field>
<field name="type_s">storage</field>
<field name="STATE_s">CA</field>
<field name="QTY_i">10</field>
</doc>
<doc>
<field name="id">14</field>
<field name="type_s">storage</field>
<field name="STATE_s">NY</field>
<field name="QTY_i">0</field>
</doc>
<doc>
<field name="id">15</field>
<field name="type_s">vendor</field>
<field name="NAME_s">Bob</field>
<field name="PRICE_i">20</field>
</doc>
<doc>
<field name="id">16</field>
<field name="type_s">vendor</field>
<field name="NAME_s">Alice</field>
<field name="PRICE_i">22</field>
</doc>
</doc>
<doc>
<field name="id">12</field>
<field name="type_s">sku</field>
<field name="COLOR_s">Blue</field>
<field name="SIZE_s">XL</field>
<!-- nesting locations into sku -->
<doc>
<field name="id">17</field>
<field name="type_s">storage</field>
<field name="STATE_s">CA</field>
<field name="QTY_i">0</field>
</doc>
<doc>
<field name="id">18</field>
<field name="type_s">storage</field>
<field name="STATE_s">NY</field>
<field name="QTY_i">100</field>
</doc>
<doc>
<field name="id">19</field>
<field name="type_s">vendor</field>
<field name="NAME_s">Bob</field>
<field name="PRICE_i">25</field>
</doc>
<doc>
<field name="id">20</field>
<field name="type_s">vendor</field>
<field name="NAME_s">Alice</field>
<field name="PRICE_i">28</field>
</doc>
</doc>
<!-- nesting vendors into product -->
</doc>
The query:
{!parent which=type_s:product}
+COLOR_s:Blue
+{!parent which=type_s:sku v='+QTY_i:[10 TO *] +STATE_s:CA'}
The result:
[
{
"id": "21",
"type_s": "product",
"BRAND_s": "Nike",
"_version_": 1726713699507372000
},
{
"id": "32",
"type_s": "product",
"BRAND_s": "Puma",
"_version_": 1726713699562946600
}
]
I want the results to be sorted by the matched type_s:sku document's type_s:vendor AND NAME_s:Alice's PRICE_i field in descending.
I have tried:
{!parent which=type_s:product score=max v=’+type_s:sku +{!func}PRICE_i’} desc
{!parent which=type_s:product score=max v='{!parent which=type_s:sku v='type_s:vendor AND NAME_s:Alice'}+{!func}PRICE_i' asc
However it gives "error in sort".
If I remember correctly, Solr treats all child levels in a similar fashion.
Also I create a variable:
childq={!parent which=type_s:product score=max v='+type_s:(vendor) +{!func}QTY_i'}
And then sort the products on the basis of this childq using sort=$childq desc.
In cases of debug, you can also use this value in fl; this will show if it is giving you the correct value.
fl=*,$childq
"q":"{!parent which=type_s:product}\n+COLOR_s:Red \n+{!parent which=type_s:sku v='+QTY_i:[10 TO *] +STATE_s:CA'}",
"fl":"*,$childq",
"sort":"$childq desc",
"_":"1646831710752",
"childq":"{!parent which=type_s:product score=max v='+type_s:(vendor) +{!func}QTY_i'}"}},
Related
[![enter image description here][1]][1]I have a problem with adding a new field to the sale order view of odoo12. I have created a new module. I hope that you can help me.
Below the code of my view form
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml"></field>
<field name="payment_term_id" position="after">
<field name="additional_note"/>
</field>
</record>
</odoo>```
when i try to install the new module i have the following error:
File "src\lxml\etree.pyx", line 3557, in lxml.etree._Validator.assert_
AssertionError: Element odoo has extra content: record, line 3
[1]: https://i.stack.imgur.com/e1DOw.png
The problem is in the <field name="arch" type="xml"></field> line: the <field> tag is closed, and your additional_note field is declared outside of it.
Try this code instead:
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<!-- Leave the 'arch' field open -->
<field name="arch" type="xml">
<!-- Put your custom field and its position inside the 'arch' field.
Use 'xpath' tag to create a more precise positioning -->
<xpath expr="//group/group/field[#name='payment_term_id']" position="after">
<field name="additional_note"/>
</xpath>
<!-- Now, close the 'arch' field -->
</field>
</record>
</odoo>
The view is not correctly defined, you can refer to account_analytic_view.
The view definition should be (according to the provided link):
<odoo>
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<data>
<field name="payment_term_id" position="after">
<field name="additional_note"/>
</field>
</data>
</field>
</record>
</odoo>
I'm trying to add multi field to timesheet module to work as a tasks manage app i did inheritance to account.analytic.line the problem is in the view i got that error "AssertionError: Element odoo has extra content: record, line 4"
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="todo_timesheet_line_tree" model="ir.ui.view">
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
<field name="model">account.analytic.line</field>
<field name="arch" type="xml"/>
<field name="task_id" position="after">
<field name="priority"/>
</field>
<field name="company_id" groups="base.group_multi_company" position="before">
<field name="gov_department"/>
<field name="priority"/>
<field name="date_deadline"/>
</field>
</record>
</odoo>
from odoo import models, fields, api
class TodoTask(models.Model):
_inherit = 'account.analytic.line'
startdate=fields.Date('start Date', required=True, index=True, default=fields.Date.context_today)
date_deadline=fields.Date('Deadline', required=True, index=True, default=fields.Date.context_today)
priority = fields.Selection(selection=[('1', 'فوري'), ('2','هام جدا' ),('3','اقل اهمية')])
is_done = fields.Boolean ('Done?')
gov_department = fields.Many2one('govauthority','الجهة الحكومية')
class govauthority(models.Model):
govname = fields.Char('GOV_Department', size=25, required=True)
The error is in this line
<field name="arch" type="xml" />
You closed the tag while you really should not. Within this tag the actual XML body should be.
<record id="todo_timesheet_line_tree" model="ir.ui.view">
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />
<field name="model">account.analytic.line</field>
<field name="arch" type="xml">
<field name="task_id" position="after">
<field name="priority" />
</field>
<field name="company_id" groups="base.group_multi_company" position="before">
<field name="gov_department" />
<field name="priority" />
<field name="date_deadline" />
</field>
</field>
</record>
I am using Odoo 10-e. I am working on a sample module.
I have 5 models (customer, product, order, order details, movement)
Customer :
class Customer(models.Model):
_name ="amgl.customer"
…… all other fields related to customer
product_ids = fields.Many2many('amgl.products', string='Products')
Products :
class Products(models.Model):
_name ="amgl.products"
…… all other fields related to product
customer_ids = fields.Many2many('amgl.customer', string='Customers')
Order :
class Order(models.Model):
_name ="amgl.order"
order_line = fields.One2many('amgl.order_line', 'order_id', string='Order Lines')
…… all other fields related to Order
Order Details :
class OrderLine(models.Model):
_name = 'amgl.order_line'
order_id = fields.Many2one('amgl.order', string='Orders')
products = fields.Many2one('amgl.products', string="Products")
…… all other fields related to order details
Movement
class Movement(models.Model):
_name = 'amgl.metal_movement'
customer = fields.Many2one("amgl.customer", string="Customer", required=True)
order_lines = fields.One2many('amgl.order_line','metal_movement_id')
…… all other fields related to movement
What i am trying to do is, i am creating a movement form in which user will select a customer from customer drop down first then user will add order_lines and in that he will be able to add products i want to filter products which are associated with above selected customer . How can i do that ? I have been trying since last month.
Movement View
<odoo>
<data>
<record id="action_metal_movement" model="ir.actions.act_window">
<field name="name">Metal Movement Request</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">metal.movement</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create
</p><p>
<!-- More details about what a user can do with this object will be OK -->
</p>
</field>
</record>
<record id="form_metal_movement" model="ir.ui.view">
<field name="name">Metal Movement Request </field>
<field name="model">metal.movement</field>
<field name="arch" type="xml">
<form string="Metal Movement">
<sheet>
<group>
<group string="Metal Movement Request">
<field name="date_create" string="Date Created"/>
<field name="reference"/>
<field name="metal_movement_type"/>
<field name="first_approve"/>
<field name="second_approve" domain="[('id', '!=', first_approve)]"/>
<field name="customer"/>
<field name="sepcial_instruction" widget="html"/>
</group>
<group string="Metal Movement From">
<group colspan="6">
<field name="custodian"/>
<field name="mmf_name"/>
<field name="mmf_account_number"/>
<field name="mmf_account_type"/>
</group>
<group string="Metal Movement To" colspan="6">
<field name="mmt_name"/>
<field name="mmt_address" attrs="{'invisible':[('metal_movement_type', '=', 'IT')]}"/>
<field name="mmt_account_number" />
<field name="mmt_company" attrs="{'invisible':[('metal_movement_type','not in',('AC','IPPU','IT'))]}"/>
<field name="pickup_date" string="Pick up Datetime" attrs="{'invisible':[('metal_movement_type','not in',('AC','IPPU'))]}"/>
</group>
</group>
<group string="Metals To Be Moved" colspan="12">
<field name="order_lines">
<tree editable="bottom">
<field name="quantity" string="Quantity"/>
<field name="products" domain="[('customer_ids','in', parent.customer)]" string="Product Name"/>
<field name="weight" string="Weight"/>
<field name="total_weight" string="Total Weight"/>
</tree>
</field>
</group>
</group>
</sheet>
</form>
</field>
</record>
</data>
</odoo>
Thank you for updation of question.
First add customer in product field context.
<field name="order_lines">
<tree editable="bottom">
<field name="quantity" string="Quantity"/>
<field name="products" context="{'customer_id':parent.customer}" string="Product Name"/>
<field name="weight" string="Weight"/>
<field name="total_weight" string="Total Weight"/>
</tree>
</field>
Then in product's model write it's name_get method like this.
#api.multi
def name_get(self):
if self.env.context('customer_id',False):
customer = self.env['amgl.customer'].browse(self.env.context('customer_id',False))
for product in customer.product_ids:
res.append((product.id,product.name))
else:
res=super(product_product,self).name_get()
return res
Thats it.
Get an error: Odoo Warning - Insufficient fields for Calendar View! and the calendar, of course,never shows up.
I'm missing something but don't know what;
I have this view fragment:
<record model="ir.actions.act_window" id="action_soft_apps_event">
<field name="name">Applications</field>
<field name="res_model">soft.app</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="arch" type="xml">
<calendar string="App Releases" color="dev_id" date_start="release" date_delay="1">
<field name="name"/>
<field name="desc"/>
<field name="downloads"/>
<field name="valid"/>
</calendar>
</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Register a new App</p>
</field>
</record>
And the model is the following:
class soft_app(osv.osv):
"""Apps"""
_name = 'soft.app'
_columns = {
'name': fields.char('Name', size=32, required=True, help='This is the name of the application'),
'desc': fields.text('Description', help='A brief description of the application'),
'dev_id': fields.many2one('soft.dev','Developer',required=True, help='The app\'s developer'),
'release': fields.datetime('Release Date', help='The date that the app was released'),
'downloads': fields.integer('Download Count', help='Total amount of downloads'),
'user_ids': fields.many2many('soft.user','soft_user_app_rel','app_id','user_id','Users Downloaded', help='Users that have downloaded the app'),
'os_ids': fields.many2many('soft.os','soft_os_app_rel','app_id','os_id','Operating Systems', help='Operating systems survey data'),
'valid': fields.boolean('Is Valid', help='Checks if the app is validated')
}
soft_app()
I think you have to create separate calendar view and action
Like:
Calendar view
<record id="view_invoice_line_calendar" model="ir.ui.view">
<field name="name">account.invoice.calendar</field>
<field name="model">account.invoice</field>
<field name="arch" type="xml">
<calendar string="Invoices" color="journal_id" date_start="date_invoice">
<field name="partner_id"/>
<field name="amount_total"/>
</calendar>
</field>
</record>
Action
<record id="action_invoice_tree" model="ir.actions.act_window">
<field name="name">Invoices</field>
<field name="res_model">account.invoice</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="view_id" ref="invoice_tree"/>
<field name="context">{'type':'out_invoice'}</field>
<field name="search_view_id" ref="view_account_invoice_filter"/>
</record>
how do i can search multiple index content in spring data solr showcase?
just now i only can search "name".
for example how do i can search "companyNo"?.
thanks in advance
sample xml of indexed in solr:
<?xml version="1.0" encoding="UTF-8"?>
<add>
<doc>
<field name="id">1051879H_15082014_00003457</field>
<field name="name">BEST MEGALINK SDN. BHD.</field>
<field name="entityName"></field>
<field name="companyNo">1051879-H</field>
<field name="noticeType">RMAT_N_C</field>
<field name="noticeDate">15/08/2014</field>
<field name="repNames"></field>
<field name="repNames"></field>
<field name="repNames"></field>
<field name="repICs"></field>
<field name="repICs"></field>
<field name="repICs"></field>
<field name="format">PDF</field>
<field name="folder">15082014</field>
<field name="pages">2</field>
</doc>
</add>
Other fields which need to be searched, needs to be added as part of schema.xml.
For example, the fields like the following needs to be added as part schema.xml:
<field name="entityName" type="text_string" indexed="true" stored="true"/>
<field name="companyNo" type="text_string" indexed="true" stored="true"/>
<field name="noticeType" type="text_string" indexed="true" stored="true"/>