odoo security restrict company from opening general setting - python-3.x

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.

Related

access test data after test area in cypress

I have an html code with contains
<div class="form-card">
<h2 class="fs-title" test-data="area_1">
About DigCompEdu
</h2>
<p></p>
<label for="academic_teaching" class="question" test-data="question_1">
<b>1- </b>
</label>
<small id="academic_teachingHelp" class="form-text text-muted">
</small>
<div class="form-check question-form-check ">
<div class="row">
<div class="col-1">
<input class="radio" type="radio" value="0" id="3" name="2" test-data="answer_1" />
</div>
</div>
So, I have h1 with testdata name after that i have a form, this form contains question with multin check radio .. i want to access this check , not by just call ([test-data="answer_2"])
because i have another tips and don't want to check them as this one ,
i did smth like this but it's not working :
cy.get('[test-data="area_1"]~[test-data="answer_2"]').check({force: true})
Any one have another idea ?
It might be the ~ between the selectors, I haven't seen that before.
Does it work with a space between instead?
cy.get('[test-data="area_1"] [test-data="answer_2"]').check({force: true})
If the heading is followed by the form like this
<h2 class="fs-title" test-data="area_1">
About DigCompEdu
</h2>
<div class="form-check question-form-check ">
...
then you would query like this
cy.get('[test-data="area_1"]')
.next('.form-check') // next element on page
.find('[test-data="answer_2"]') // this looks inside '.form-check'
.check({force: true})

add div tag in invoice configuration in odoo 12

can anyone please help me regarding invoice configuration in odoo 12.
i am trying to add div tag inside invoice configuration page but got no success.
<record id="res_config_inherit_view_form" model="ir.ui.view">
<field name="name">res.config.form.inherit</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[hasclass('app_settings_block')]" position="inside">
<h2>Notification</h2>
<div></div>
</xpath>
</field>
</record>
i have inherited transient model of res.config.settings in my py file.
i just changed reference from base.res_config_settings_view_form to account.res_config_settings_view_form and
in xpath i added data-key which is sat in the div tag of class named app_settings_block in account.res_config_settings_view_form xml,
in account.invoice it adds all the divs of invoice configuration.
<record id="res_config_inherit_view_form" model="ir.ui.view">
<field name="name">res.config.form.inherit</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="account.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[#data-key='account']" position="inside">
<h2>Notification</h2>
<div class="row mt16 o_settings_container" id="notification">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="unpaid_notification"/>
</div>
<div class="o_setting_right_pane">
<label for="unpaid_notification" string="Unpaid invoice reminder"/>
<div class="text-muted">
Auto send unpaid invoice emails to the partners
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>

Manage webservice from odoo

I am new to Odoo 11, I have created a module called 'coupon', for this module I have created a security group and a default user that is added to this group:
<record id="default_coupon_user" model="res.users">
<field name="login">couponuser</field>
<field name="password">couponuser</field>
<field name="password_crypt">couponuser</field>
<field name="name">Default User Coupon</field>
<field name="display_name">Default Coupon User</field>
<field name="customer">False</field>
</record>
<record id="coupon_managers_group" model="res.groups" >
<field name="name">Coupon Managers Group</field>
<field name="comment">Coupon Managers Group that will be used in the Coupon microservice.</field>
<field name="category_id" ref="base.module_category_coupon"/>
<field name="users" eval="[(4, ref('coupon.default_coupon_user'))]"/>
</record>
My module depends on website because I need to create a website, for that site I created an index page:
<!-- === Coupon Page === -->
<template id="index_template">
<t t-call="website.layout">
<div id="wrap">
<div class="container">
<h1>Coupons</h1>
<a href="/payum_coupon/create" class="btn btn-primary btn-lg">
Add
</a>
<p>paginas:
<t t-esc="coupons['pg']"/>
</p>
<p>total:
<t t-esc="coupons['total']"/>
</p>
<ul class="clientes">
<t t-foreach="coupons['items']" t-as="i">
<li>
<a t-attf-href="/payum_coupon/{{i['email']}}">
<t t-esc="i['firstName']"/>
<t t-esc="i['lastName']"/>
-
<t t-esc="i['email']"/>
</a>
</li>
</t>
</ul>
</div>
</div>
</t>
</template>
<record id="coupon_page" model="website.page">
<field name="name">Index Coupon page</field>
<field name="website_published">True</field>
<field name="url">/coupon</field>
<field name="view_id" ref="index_template"/>
<field name="groups">coupon.coupon_managers_group</field>
</record>
and website.menu with the following code:
<record id="coupon_page_link" model="website.menu">
<field name="name">Coupon</field>
<field name="page_id" ref="coupon_page"/>
<field name="parent_id" ref="website.main_menu"/>
</record>
the python code in the controller that will be executed by said menu is this:
#http.route('/coupon', auth='user', website=True)
def index(self, **kw):
#<<my code here>>
I need several things:
when the 'index' page is displayed if the user in session is not in the 'coupon.coupon_managers_group' group then the menu is not shown
And that when the controller method '/coupon' is executed it is verified that the user in session is in the group 'coupon.coupon_managers_group'
This site has a particularity and that my module does not have models, since it is to manage the data of an api rest application, that is, in odoo I have to create the views of list, create, etc., but the data is written and they are read from a remote web service.
I have searched many sites on the internet but I have not found anything, as they always refer to local cases in odoo.
To hide the website menu based on the user group you could do something like this:
from odoo import api, models
class Menu(models.Model):
_inherit = "website.menu"
#api.one
def _compute_visible(self):
if self.clean_url() == '/coupon' and not self.env.user.has_group('coupon.coupon_managers_group'):
return False
return super(Menu, self)._compute_visible()
In the controller of the route /coupon you could check the user group like:
request.env.user.has_group('coupon.coupon_managers_group')

Odoo 11 Qweb Report empty page

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">

How to show a message if there are no products inside a category with exp:resso store plugin?

I'm using the latest version of EE2 and a plugin called Exp:resso store.
I have products assigned to a category and for the most part all of this is working fine. Below is my code:
<div class="col-md-7">
{exp:channel:categories channel="products" style="linear"}
<section class="section accordion repeater">
<h3>
{category_name}
<div class="icon">
<img src="/assets/local/img/plus-icon.jpg" alt="">
</div>
</h3>
<div class="accordion-content">
{exp:store:search orderby="title" sort="asc" category="{category_id}"}
{exp:store:product entry_id="{entry_id}"}
<p class="accordion-download">
{title} - {price}
<span><img src="/assets/local/img/add-to-cart.jpg" alt="">Add to cart</span>
</p>
{/exp:store:product}
{/exp:store:search}
</div>
</section>
{/exp:channel:categories}
</div>
I'm trying to find a way to show a No products exist message if the category doesn't have anything inside of it. I've tried using {count}, {total_results} & {total_rows} to check if there aren't any products. Problem is everything I try is obviously wrong because nothing gets output :/
Thanks in advance
The store search tag is a wrapper for the channel entries tag pair so you would need to use the {if no_results} tag pair.
<div class="col-md-7">
{exp:channel:categories channel="products" style="linear"}
<section class="section accordion repeater">
<h3>
{category_name}
<div class="icon">
<img src="/assets/local/img/plus-icon.jpg" alt="">
</div>
</h3>
<div class="accordion-content">
{exp:store:search orderby="title" sort="asc" category="{category_id}"}
{exp:store:product entry_id="{entry_id}"}
<p class="accordion-download">
{title} - {price}
<span><img src="/assets/local/img/add-to-cart.jpg" alt="">Add to cart</span>
</p>
{/exp:store:product}
{if no_results}
There are no products
{/if}
{/exp:store:search}
</div>
</section>
{/exp:channel:categories}
</div>
Should also be mentioned if you are not creating a form for the to add the products to the cart you could use the {store_field_short_name:price} variable to reduce the number of queries on your page. Most store things such as sku, weight, measurements can all be access by using the field short name followed by :variable

Resources