Odoo 11 Qweb Report empty page - python-3.x

I am trying to create a qweb report for Odoo 11 but without any success. 0 byte pdf I am getting, I edit the report to qweb-html and then only white page. Please help me to solve the issue. Below is my code. I am a beginner and trying to create this report after reading different posts and different modules.
Below is my code in 4 seprate files.
1st file
from odoo import models, fields, api
class TrueReportFields(models.TransientModel):
_name = 'true.report'
#api.multi
def print_true_report(self):
sales = self.env['sale.order'].sudo().search(
[('state', 'in', ('sale', 'done'))])
total_sale = total_cost = 0
for sale in sales:
total_sale += sale.amount_total
for lines in sale.order_line:
total_cost += lines.product_id.standard_price * lines.product_uom_qty
purchases = self.env['purchase.order'].sudo().search(
[('state', 'not in', ('draft', 'canceled'))])
total_purchase = 0
for purchase in purchases:
total_purchase += purchase.amount_total
pos_sales = self.env['pos.order'].sudo().search(
[('state', 'not in', ['cancel', 'draft'])])
total_pos_sale = total_pos_cost = 0
for pos in pos_sales:
total_pos_sale += pos.amount_total
for posl in pos.lines:
total_pos_cost += posl.product_id.standard_price * posl.qty
datas = {
'ids': self,
'model': 'true.report',
'total_sale': total_sale,
'total_cost': total_cost,
'total_purchase': total_purchase,
'total_pos_sale': total_pos_sale,
'total_pos_cost': total_pos_cost
}
return self.env.ref('true_report.action_true_report').report_action(self, data=datas)
2nd file
from odoo import api, models
class TrueReport(models.AbstractModel):
_name = 'report.true_report.report_details'
#api.model
def get_report_values(self, docids, data=None):
return {
'doc_ids': data.get('ids'),
'doc_model': data.get('model'),
'total_sale': data['total_sale'],
'total_cost': data['total_cost'],
'total_purchase': data['total_purchase'],
'total_pos_sale': data['total_pos_sale'],
'total_pos_cost': data['total_pos_cost']
}
xml views
<odoo>
<data>
<record id="view_true_report" model="ir.ui.view">
<field name="name">product.detail.form</field>
<field name="model">true.report</field>
<field name="arch" type="xml">
<form string="True Details">
<!--<group>
<group>
<field name="start_date"/>
</group>
<group>
<field name="end_date"/>
</group>
</group>-->
<footer>
<button string='Print' name="print_true_report" type="object" default_focus="1"
class="oe_highlight"/>
<button string="Cancel" class="btn-default" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="open_true_report_action" model="ir.actions.act_window">
<field name="name">Top Sold Products</field>
<field name="res_model">true.report</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="view_id" ref="view_true_report"/>
</record>
<menuitem
id="menu_true_report"
name="True Report"
parent="sale.menu_sale_report"
sequence="4"
action="true_report.open_true_report_action"/>
<report
id="action_true_report"
string="True PDF Report"
model="true.report"
report_type="qweb-pdf"
file="true_report.report_details"
name="true_report.report_details"
/>
</data>
</odoo>
xml templates
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_details_documents">
<t t-call="web.html_container">
<t t-set="o" t-value="doc.with_context({'lang':doc.partner_id.lang})" />
<!--<t t-foreach="docs" t-as="o">-->
<!--<t t-foreach="docs" t-as="o">-->
<t t-call="web.external_layout">
<div class="page">
<div class="row">
<div class="oe_structure"/>
<div style="text-align: center;">
<span style="font-size: 25px;">True Report Details</span>
</div>
<!--<div class="row mt32 mb32">
<div class="col-xs-4">
<p>
<t>
<strong>From Date :</strong>
<span t-esc="o.start_date"/>
<br/>
</t>
<t>
<strong>To Date :</strong>
<span t-esc="o.end_date"/>
</t>
</p>
</div>
</div>-->
<table class="table table-condensed">
<thead>
<tr>
<th>Total Sales</th>
<th class="text-right">Total Cost</th>
<th>Total Purchase</th>
<th>Pos Sale</th>
<th>Pos Cost</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span t-esc="o.total_sale"/>
</td>
<!-- <td class="text-right" style="white-space: text-nowrap;">
<span t-esc="o.total_cost"/>
</td>
<td>
<span t-esc="o.total_purchase"/>
</td>
<td>
<span t-esc="o.total_pos_sale"/>
</td>
<td>
<span t-esc="o.total_pos_cost"/>
</td>-->
</tr>
</tbody>
</table>
</div>
</div>
</t>
<!--</t>-->
</t>
</template>
<template id="report_details">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="true_report.report_details_documents" t-lang="o.company_id.partner_id.lang"/>
</t>
</t>
</template>
</odoo>
Please help me to solve the issue. I will be a great help.
Thanks in advance.

you can try
<t t-call="web.external_layout"> instead of <t t-call="web.html_container">

Related

How to implement one2many field on odoo 15 website form

I have a custom module and i want to create a website form for my module. In the backend form the is a section where user enters service details through a one2many field. The form is to be made available to portal users on the website.How do i implement one2many field on the website so that the information can be recorded in backend??This is my backend form view
This is my website form.I've been able to do first part of form and need help with many2one
<template id="online_request_form">
<t t-call="portal.portal_layout">
<t t-set="breadcrumbs_searchbar" t-value="True"/>
<t t-call="portal.portal_searchbar">
<t t-set="title">Service Request</t>
</t>
<div id="wrap" class="oe_structure oe_empty">
<section class="s_website_form" data-vcss="001" data-snippet="s_website_form">
<div class="container">
<form action="/submit/request" method="post" enctype="multipart/form-data" class="o_mark_required" data-mark="*" data-model_name="" data-success-page="">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<table style="border:0px; width:100%%; background-color:#D6EEEE; margin-top:5%%;">
<group>
<tr>
<td>
<group>
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 50%%" for="studio1">
<span class="s_website_form_label_content">Agency</span>
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-sm">
<select name="agency" t-attf-class="form-control s_website_form_input" required="1">
<option value=""><i>Please Select</i></option>
<t t-foreach="agencies or []" t-as="agency">
<option t-att-value="agency.id">
<t t-esc="agency.name" />
</option>
</t>
</select>
</div>
</group>
<group>
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 50%%" for="studio1">
<span class="s_website_form_label_content">Agent</span>
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-sm">
<select name="agent" t-attf-class="form-control s_website_form_input" required="1">
<option value=""><i>Please Select</i></option>
<t t-foreach="agents or []" t-as="agent">
<option t-att-value="agent.id">
<t t-esc="agent.name" />
</option>
</t>
</select>
</div>
</group>
</td>
<td>
<group>
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 50%%" for="studio1">
<span class="s_website_form_label_content"> IMDG Code / Un No.</span>
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-sm">
<input id="imdg_code" type="text" class="form-control s_website_form_input" name="imdg_code" required="1"/>
</div>
</group>
<group>
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 50%%" for="studio1">
<span class="s_website_form_label_content">Phone</span>
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-sm">
<input id="phone" type="text" class="form-control s_website_form_input" name="phone" required="1"/>
</div>
</group>
</td>
</tr>
</group>
<tr>
<td>
<group>
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 50%%" for="studio1">
<span class="s_website_form_label_content">Email</span>
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-sm">
<input id="email" type="text" class="form-control s_website_form_input" name="email" required="1"/>
</div>
</group>
</td>
</tr>
</table>
<div style="width:200px; margin-top:2%%;" class="form-group col-12 s_website_form_submit" data-name="Submit Button">
<div class="s_website_form_label"/>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</section>
</div>
</t>
</template>
The template for website form.
#http.route('/service_requests', type='http', auth="user", website=True)
def service_request(self):
products = request.env['product.template'].sudo().search([])
agencies = request.env['res.partner'].sudo().search([])
agents = request.env['res.users'].sudo().search([])
values = {}
values.update({
'products': products,
'agencies': agencies,
'agents':agents,
'page_name': 'new_request',
})
return request.render("service_request.online_request_form", values)
Corresponding controller

Conditional Rendering with Vue and Prime Vue Library

I have a diagram that is composed of inputs and outputs. Using Primevue I am rendering a table with data for the inputs or outputs. However inputs and outputs should render different columns (not simultaneously it either displays input data or out put data)
I am wondering how I can render different columns on the table depending on what the API is returning. Instead of having to create two different tables. Is it possible to have a ternary operator in the ?
Here is a sample of the table component:
<DataTable
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown"
:value="cardListData[0]"
:loading="isLoading"
:sortOrder="-1"
:paginator="true"
v-model:filters="filters"
:rows="rowsPerPage"
:rowsPerPageOptions="[10, 20, 50]"
responsiveLayout="stack"
:globalFilterFields="['date', 'lotNumber']"
>
<template #header>
<div class="flex justify-content-between">
<Button
type="button"
icon="pi pi-filter-slash"
:label="$t('Clear')"
class="p-button-outlined"
#click="clearFilter()"
/>
<span class="p-input-icon-left">
<i class="pi pi-search" />
<InputText v-model="filters['global'].value" :placeholder="$t('Keyword Search')" />
</span>
</div>
</template>
<template #empty> {{ $t('No data found')}}. </template>
<template #loading> {{ $t('Loading data. Please wait')}}. </template>
<Column field="date" :header="$t('Date')" :sortable="true">
<template #body="slotProps">
<div class="detail">
{{ slotProps.data.date ? formatDate(slotProps.data.date): 'N/A' }}
</div>
</template>
</Column>
<Column field="name" :header="$t('Name')" :sortable="true">
<template #body="slotProps">
<div class="detail">
{{ slotProps.data.name ? slotProps.data.name: 'N/A' }}
</div>
</template>
</Column>
<Column field="provider" :header="$t('Supplier')" :sortable="true">
<template #body="slotProps">
<div class="detail">
{{ slotProps.data.provider ? slotProps.data.provider: 'N/A' }}
</div>
</template>
</Column>
<Column field="quantity" :header="$t('Quantity')" :sortable="true">
<template #body="slotProps">
<div class="detail">
{{ slotProps.data.quantity ? slotProps.data.quantity +' g' : 'No Value' }}
</div>
</template>
</Column>
<Column field="type" :header="$t('Type')" :sortable="true">
<template #body="slotProps">
<div class="detail">
{{ slotProps.data.type ? slotProps.data.type : 'No Value' }}
</div>
</template>
</Column>
</DataTable>
Sure, you can use conditional rendering on <Column> like this:
<Column v-if="yourCondition">...</Column>
<Column v-else>...</Column>

ValueError at / save_data/

Cannot assign "'Electronic'": "Product.category" must be a "Category" instance.
File/models.py:
from django.db import models
# Create your models here.
class Category(models.Model):
name = models.CharField(max_length=150, db_index=True)
def __str__(self):
return self.name
class SubCategory(models.Model):
name = models.CharField(max_length=150, db_index=True)
category = models.ForeignKey(Category, related_name='souscatégories', on_delete=models.CASCADE)
def __str__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length=100, db_index=True)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
subcategory = models.ForeignKey(SubCategory, on_delete=models.CASCADE)
def __str__(self):
return self.
and business logic code is there....
File/views.py
# from django.urls import reverse_lazy
# from django.views.generic import ListView, CreateView
from django.shortcuts import render
from .models import Product, Category, SubCategory
# Create your views here.
def home(request):
if request.method == "POST":
name = request.POST['name']
subcategory = request.POST['subcategory']
category = request.POST['category']
ins = Product(name=name, subcategory=subcategory, category=category)
ins.save()
data = Product.objects.all()
return render(request, 'mysiteapp/index.html', {'data': data})
and templates is there....
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Hello, world!</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="/">Product List </a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<!-- Table -->
<table class="table table-dark">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Product</th>
<th scope="col">Subcategory</th>
<th scope="col">Category</th>
</tr>
</thead>
{% for p in data%}
<tbody>
<tr>
<th scope="row">{{p.id}}</th>
<td>{{p.name}}</td>
<td>{{p.subcategory}}</td>
<td>{{p.category}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<!-- modal -->
<!-- Button trigger modal -->
<h2><a class="btn btn-success" data-toggle="modal" data-target="#exampleModal">
Add Product
</a></h2>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Product</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<!-- form -->
<form method="POST">{% csrf_token %}
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Product</label>
<div class="col-sm-8">
<input name="name" type="text" id="name" class="form-control mx-sm-2">
</div>
</div>
<div class="form-group row">
<label for="subcategory" class="col-sm-2 col-form-label">SubCategory</label>
<div class="col-sm-8">
<select name="subcategory" class="custom-select mr-sm-2" id="subcategory">
<option>Choose....</option>
{% for p in data %}
<option>{{p.subcategory}}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group row">
<label for="category" class="col-sm-2 col-form-label">Category</label>
<div class="col-sm-8">
<select name="category" class="custom-select mr-sm-2" id="category">
<option>Choose....</option>
{% for p in data %}
<option>{{p.category}}</option>
{% endfor %}
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</body>
</html>
and finally error is :
ValueError at /
Cannot assign "'Electronic'": "Product.category" must be a "Category" instance.
please answer me...
You cannot directly pass category from POST data.
Either it needs to be an instance of Category class
category_id = request.POST['category']
#Get category instance
category = Category.objects.get(pk=category_id)
ins = Product(name=name, subcategory=subcategory, category=category)
or you can use the category pk value.
ins = Product(name=name, subcategory=subcategory, category_id=category_id)

odoo security restrict company from opening general setting

I installed a custom odoo module to add a total and line discount to orders it working well till I added a new company, after adding a new company I must go to invoicing to activate total discount but odoo restrict me form doing that
I tried to add rules but it doesn't work. I don't know what actually rule I shoud add
This is how I defined the setting view
class KSResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
ks_enable_discount = fields.Boolean(string="Activate Total Discount")
ks_sales_discount_account = fields.Many2one('account.account', string="Sales Discount Account")
ks_purchase_discount_account = fields.Many2one('account.account', string="Purchase Discount Account")
ks_accounting_present = fields.Boolean(compute='ks_check_charts_of_accounts')
def get_values(self):
ks_res = super(KSResConfigSettings, self).get_values()
ks_res.update(
ks_enable_discount=self.env['ir.config_parameter'].sudo().get_param('ks_enable_discount'),
ks_sales_discount_account=int(self.env['ir.config_parameter'].sudo().get_param('ks_sales_discount_account')),
ks_purchase_discount_account=int(self.env['ir.config_parameter'].sudo().get_param('ks_purchase_discount_account')),)
return ks_res
def set_values(self):
super(KSResConfigSettings, self).set_values()
self.env['ir.config_parameter'].set_param('ks_enable_discount', self.ks_enable_discount)
if self.ks_enable_discount:
self.env['ir.config_parameter'].set_param('ks_sales_discount_account', self.ks_sales_discount_account.id)
self.env['ir.config_parameter'].set_param('ks_purchase_discount_account',
self.ks_purchase_discount_account.id)
odoo>
<data>
<record id="ks_res_config_settings_view_form" model="ir.ui.view">
<field name="name">ks.res.config.settings.view.form.inherit.account.discount</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="50"/>
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='has_accounting_entries']" position="after">
<h2 attrs="{'invisible': [('has_chart_of_accounts','==',False)]}">Total Discount</h2>
<div class="row mt16 o_settings_container"
attrs="{'invisible': [('has_chart_of_accounts','==',False)]}">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="ks_enable_discount"/>
</div>
<div class="o_setting_right_pane">
<label for ='ks_enable_discount'/>
<div class="text-muted">
Activate Total discount on all modules.
</div>
</div>
</div>
<div class="col-xs-12 col-md-6 o_setting_box" attrs="{'invisible':[('ks_enable_discount','==',False)]}">
<div class="o_setting_left_pane"/>
<div class="o_setting_right_pane">
<span class="o_form_label">Accounts</span>
<div class="text-muted">
Set default Total discount accounts for sale and purchase order.
</div>
<div class="content-group">
<div class="row mt16" >
<label for="ks_sales_discount_account"
class="col-md-3 o_light_label"/>
<field name="ks_sales_discount_account"
attrs="{'required': [('ks_enable_discount','==',True)]}"/>
</div>
<div class="row mt16" >
<label for="ks_purchase_discount_account"
class="col-md-3 o_light_label"/>
<field name="ks_purchase_discount_account"
attrs="{'required': [('ks_enable_discount','==',True)]}"/>
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
</data>
</odoo>
This what appears in log
2019-10-29 12:31:26,410 16582 INFO demo odoo.models: The requested operation cannot be completed due to record rules: Document type: account.account, Operation: read, Records: 31, User: 2
Yes this error is occuring because this module is not multi-company supported
ks_sales_discount_account = fields.Many2one('account.account', string="Sales Discount Account")
ks_purchase_discount_account = fields.Many2one('account.account', string="Purchase Discount
These fields are occuring problem when we set this field in one company and we go to other company we can't access same account and that is occuring problem values are set for those field and user tried to access those accounts but he don't have permission for that.

add html value when creating sharepoint list instance

I have created a Sharepoint list definition, and an instance of that definition. In the instance I need to store some HTML as the value of a field in my list instance. I know I can do this through the UI, but I need this list created on deployment. When I wrap my HTML value in CDATA tags, the item is simply not created. I get a deployment error if I Just have my HTML inline with my XML.
Elements.xml:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance Title="ListName"
OnQuickLaunch="TRUE"
TemplateType="10051"
Url="Lists/ListName"
Description="List Description">
<Data>
<Rows>
<Row>
<Field Name="Title">My Title</Field>
<Field Name="Value">
<p>Some HTML HERE</p>
<table border="1"; cellpadding="10";>
<tr style="font-family:Arial; font-size:10pt;">
<th>header1</th>
<th> ... </th>
</tr>
<tr style="font-family:Arial; font-size:8pt;">
<td>Vaue1</td>
<td> ... </td>
</tr>
</table>
</Field>
</Row>
</Rows>
</Data>
</ListInstance>
</Elements>
Any help would be appreciated.
You need to HTML encode the value:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance Title="ListName"
OnQuickLaunch="TRUE"
TemplateType="10051"
Url="Lists/ListName"
Description="List Description">
<Data>
<Rows>
<Row>
<Field Name="Title">My Title</Field>
<Field Name="Value">
<p>Some HTML HERE</p>
<table border="1"; cellpadding="10";>
<tr style="font-family:Arial; font-size:10pt;">
<th>header1</th>
<th> ... </th>
</tr>
<tr style="font-family:Arial; font-size:8pt;">
<td>Vaue1</td>
<td> ... </td>
</tr>
</table>
</Field>
</Row>
</Rows>
</Data>
</ListInstance>
</Elements>

Resources