Odoo 9.0c: How to get the current user in qweb report? - odoo-9

when i duplicate a sale order or account invoice qweb report from the report created by other user, the information about saleperson is the same with the orginal report. Could we get the current user in the copy one. Please help me to point out step by step the right way to get the purpose. Thank for your time. Sory because my low level of English.

There are 3 different way we can add and print the user detail into the Qweb Report
1. Directly access the 'user' global object in qweb Part
<span t-esc="user.name" />
2. Get the current user detail from the report parser class
parser report class method:-
def get_cur_user(self):
return self.pool.get('res.users').browse(self.cr,self.uid,self.uid).name
Call parser class method into qweb View Part :-
<t t-if="get_cur_user()">
<spane t-esc="get_cur_user()" />
</t>
3. Set the custom user_id (many2one) field on that particular report and set as default attribute as env user record set
Add into your report model :-
user_id = fields.Many2one('res.users', string='Print By User', default=lambda self: self.env.user)
Access that field into the Qweb View part:-
<t t-if="o.user_id">
<spane t-field="o.user_id.name" />
</t>

Related

ADF_FACES-60097

I am creating a school management application using Oracle ADF. I have one Student Result page where we can add the result for each student. Here is the image of the same:
Student's Result Page
When I change say the Result Year, I get an exception like:
<oracle.adf.view> <_logUnhandledException> <ADF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase UPDATE_MODEL_VALUES 4>
oracle.jbo.domain.DataCreationException: JBO-25009: Cannot create an object of type:java.lang.Integer from type:java.lang.String with value:Pass
Don't Understand this only the student id is number, all other 3 attributes are string only.
Can anyone help?
Below is the Jsff Code:
<af:column sortProperty="#{bindings.ResultStudentResultView.hints.ResultYear.name}"
filterable="true" sortable="true"
headerText="#{bindings.ResultStudentResultView.hints.ResultYear.label}"
id="c7">
<af:selectOneChoice value="#{row.bindings.ResultYear.inputValue}"
label="#{row.bindings.ResultYear.label}"
required="#{bindings.ResultStudentResultView.hints.ResultYear.mandatory}"
shortDesc="#{bindings.ResultStudentResultView.hints.ResultYear.tooltip}"
id="soc2">
<f:selectItems value="#{row.bindings.ResultYear.items}" id="si2"/>
<f:validator binding="#{row.bindings.ResultYear.validator}"/>
</af:selectOneChoice>
</af:column>
This error is with the column Result, check what is the attribute type in view object and if corresponding default value is given as literal.

Odoo 9.0C: How can i access the value of a many2one field (that has been created in sale.order.line module on the invoice qweb report?

I have installed module Sale Sourced by Line
by Camptocamp, Eficent, SerpentCS, Odoo Community Association (OCA) for Odoo 9.0.
The module creates a new many2one field as the code bellow:
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
warehouse_id = fields.Many2one(
'stock.warehouse',
'Source Warehouse',
readonly=True,
states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
help="If a source warehouse is selected, "
"it will be used to define the route. "
"Otherwise, it will get the warehouse of "
"the sale order")
Now i would like to access the value warehouse_id on account_invoice_report qweb. Please tell me what are posible solutions for my purpose? Thank for your time,
In account.invoice.line one field available sale_line_ids, based on that you can search warehouse_id from sale.order.line.
invoice.invoice_line_ids.mapped('sale_line_ids').mapped('warehouse_id')
This may help you.

Odoo 8/9/10 API, how to create an invoice from a sale order via XMLRPC

I'm developing a ruby application which sends some commands to Odoo via XMLRCP API.
I've been able to create a sale order in this whay
def execute_odoo_command(odoo_model, odoo_command, values)
#models.execute_kw(ODOO_DB, #uid, ODOO_PASSWORD, odoo_model, odoo_command, values)
end
def create_order_sale
order_reference = "SO #{#reference_code}_#{#customer_odoo_id}"
values = {
currency_id: 1,
date_order: Date.today.to_s,
name: order_reference,
payment_term: 1,
partner_id: #customer_odoo_id
}
order_id = execute_odoo_command('sale.order', 'create', [values])
create_sale_order_lines(order_id)
execute_odoo_command('sale.order', 'action_confirm', [order_id])
end
Now, I would launch the invoice creation. I have found a way to do it like this
execute_odoo_command('account.invoice', 'create', [invoice_values(order_reference)])
But, even if the invoice is created, the sale order is stil "open" and I can create another invoice from the Odoo interface clicking on "Create Invoice" button (which is obviously wrong). Is there any way to simulate that action via API?
The debug mode does not show any method in the tooltip.
Any suggestion is appreciated, thank you!
For future googlers. The solution is that I'm using an old API version. the right command call is this one
def create_invoice_from_sale_order(sale_order_id)
sale_order_to_invoice_data = [sale_order_id, {context: {active_ids: sale_order_id}}]
#odoo_rpc_client.execute_odoo_command('sale.order', 'action_invoice_create', sale_order_to_invoice_data)
end

Code architecture - Flask - Where to put form validation from database?

I'm wondering where should I put a validation form which accessing database.
Basically I will need user to enter item_type and I want to check first i the item_type has exist in database.
There are 3 options:
In the database model, I have ItemType class and I put function add() which will check if existing item has exist or not
In view, so in the route of the page, from wtforms form.validate_on_submit(), I do a check to get data from database, and if exist I will put error in here
In wtforms validate(), adding extra validation after default validation of the Form class
I've seen people using number 2 and 3, but not sure which one is the best. The error message that I want will also need to display it on the specific field of the form (this is achieveable by method 2 and 3 since they have reference to the form field) but then again since it is related to accessing database, maybe it is better to put everything regarding database access to model functions?
In my opinion, if it comes from a form then it should be validated on that form and then raise an error for that specific field when invalid. See the example bellow:
class SigninForm(Form):
"""Form for signin"""
email = StringField('Email',
validators=[
DataRequired("Email shouldn't be empty."),
Email('Email format is not correct.')
])
password = PasswordField('Password',
validators=[DataRequired("Password shouldn't be empty.")])
def validate_email(self, field):
"""
verify if account exists and if not raise an error in
that field.
"""
user = User.query.filter(User.email == self.email.data).first()
if not user:
raise ValueError("Account doesn't exist.")
def validate_password(self, field):
"""
Verify if password is valid and if not raise an error in
that field.
"""
if self.email.data:
user = User.query.filter(User.email == self.email.data).first()
if not user or not user.check_password(self.password.data):
raise ValueError('Password is not correct.')
else:
self.user = user
The view function for this example:
#app.route('/signin', methods=['GET', 'POST'])
def signin():
"""Signin"""
form = SigninForm()
if form.validate_on_submit():
# sign in function to register user into a session
signin_user(form.user)
return redirect(url_for('site.index'))
return render_template('account/signin/signin.html', form=form)

Magento: Display custom product attribute in admin Items ordered block

I am trying to display my custom attribute value on admin order - Items Ordered block. It will show points earned for each product just like as it shows SKU and other information. The attribute value is saved in sales_flat_quote_item and sales_flat_order_item tables.
Namespace/Modulename/Block/Adminhtml/Sales/Order/View/Items/Renderer/Default.phtml
<?php
class Namespace_Modulename_Block_Adminhtml_Sales_Order_View_Items_Renderer_Default extends Mage_Adminhtml_Block_Sales_Order_View_Items_Renderer_Default
{
}
?>
app/design/adminhtml/design/design/layout/namespace/modulename.xml
<adminhtml_sales_order_view>
<reference name="order_items">
<action method="addItemRender"><type>default</type>
<block>sales/order_item_renderer_default</block>
<template>namespace/modulename/sales/order/items/renderer/default.phtml</template>
</action>
</reference>
</adminhtml_sales_order_view>
app/design/adminhtml/default/default/template/namespace/modulename/sales/order/view/items/rederer/default.phtml
<?php $finalPointsEarned = ($_item->getCustomerProductPoints() * $_item->getQtyOrdered()); ?>
<div class="product-cart-sku">
<span style="color: #d4af37; font-weight: bold;"><?php echo $this->__('Points Earned:'); ?>
<?php echo $finalPointsEarned ?>
</span>
</div>
Executing above code gives below exception
Invalid method Mage_Sales_Block_Order_Item_Renderer_Default::addColumnRender(Array
(
[0] => qty
[1] => adminhtml/sales_items_column_qty
[2] => sales/items/column/qty.phtml
)
)
Changing <adminhtml_sales_order_view> to <sales_order_view> does not give any output and custom prod attribute is not displayed.
Attempt Two:
<adminhtml_sales_order_view>
<reference name="order_items">
<action method="addColumnRender">
<column>NORTH FACE</column>
<block>adminhtml/sales_items_column_name</block>
<template>modulename/sales/items/column/name.phtml</template>
</action>
</reference>
</adminhtml_sales_order_view>
added my custom code in name.phtml, still no output.
How do I display the value of custom product attribute on Items
ordered block ?
How do I display the same value of admin Invoice order details page ?
Is above, the best practice/method to display custom attribute on admin order/invoice/refund pages just like it displays SKU, Size and other values ?
The easiest and most efficient way is to create a custom theme for a store admin, copy-paste the requested template in there and rewrite the output the way you want to have it.
Thus you will be able to fully customize it. Also, this approach will lower the risk of getting errors and provide you with the ability to customize any templates (including invoices, credit memos, etc.)
Have a look:
Set a custom theme: (can be done in app/etc/local xml or in your extension config settings):
Copy the template you need:
Adjust it as you need:
And get the result you want:
Note that the custom attribute is usually entered via get method. If you are having any trouble with that, just check if it exists for the chosen item in the database. In the sales_flat_order_item table
find all the items related to the chosen order and make sure that it has the value, different from null. This is how it worked in my case:

Resources