Customizing Odoo POS receipt. I was able to insert client's name but no change in the unit price. What is wrong with my code? - receipt

I was able to add the customer's name on the receipt but I can't replace the unit price.
My goal is to display the unit price in its non-rounded form (in this case 5.60 and not 6).
Currently, the POS shows the correct form:
product 1
11pk at 5.60/pk = 62
but after validating the payment, the receipt would round off all the unit prices and would print this:
product 1
11pkx6 = 62
This is my code in my custom pos receipt xml file:
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="OrderReceipt" t-inherit="point_of_sale.OrderReceipt" t-inherit-mode="extension" owl="1">
<xpath expr="//div[#class='pos-receipt-contact']" position="inside">
<t t-if='receipt.client'>
<div>Client:
<t t-esc='receipt.client.name' />
</div>
</t>
</xpath>
</t>
<t t-name="OrderLinesReceipt" t-inherit="point_of_sale.OrderLinesReceipt" t-inherit-mode="extension" owl="1">
<xpath expr="//div[#class='pos-receipt-left-padding']" position="replace">
<t t-esc="Math.round(line.quantity * Math.pow(10, env.pos.dp['Product Unit of Measure']))/ Math.pow(10, env.pos.dp['Product Unit of Measure'])"/>
<t t-if="!line.is_in_unit" t-esc="line.unit_name" />
x
<t t-esc="line.price_display_one" />
<span class="price_display pos-receipt-right-align">
<t t-esc="env.pos.format_currency_no_symbol(line.price_display)" />
</span>
</xpath>
</t>
</templates>
The code to insert customer name worked but no indication that the code to replace the unit price worked.

Related

Two reports in one with a if odoo15 qweb-pdf

I'm trying to extend a report with another one. If an if is true, the part should be loaded from another template and filled with the appropriate data. Maybe someone can give me a tip how I can implement this. Unfortunately I'm not getting any results at the moment. Only the initial report is printed.
<template id="a_report_order`your text`">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="doc">
<t t-call="web.internal_layout">
<div class="page">
....
</div>
<t t-if="checkuppaper_bool">
<t t-call="a.b_report_checkup">
<t t-foreach="self.env['a.checkup'].search([('partner_id', '=', 'partner_id')])"
t-as="doc"/>
</t>
</t>
</t>
</t>
</t>

I am having trouble creating and updating a dictionary by using the below code

For creating a dict, i used the following code:
<t t-set="count" t-value="dict()"/>
<t t-foreach="count_obj" t-as="ob">
<t t-set="count" t-esc="count.update({ob.id: ob.name})"/>
</t>
But i am getting a none value.Why?
Can anyone help me?Thanks in advance..
shahinsha ummer
You have to specify the value in dict form when you try setting the value
[<t t-set="variable" t-value=""/>].
In your example, there is no need to set the variable before the loop with dictionary form it will do nothing.
<t t-foreach="count_obj" t-as="ob">
<t t-set="count" t-value="{ob.id: ob.name}"/> <!-- Set the Value in form of dictionar -->
<span t-esc="count"/>
</t>

How to print invoice reference in each invoice page for only invoices report?

I need the show invoice reference on invoice report in header. which is just like that "Draft Invoice: ~ AR-2018/0303". It is on the first page only and i need to display on every page.
I try to that: ~
<template id="external_layout_header_inherited" inherit_id="report.external_layout_header">
<xpath expr="//div[#class='header']" position="inside">
<div t-if="o.number">Ref.: <span t-field="o.number"/></div>
</xpath>
</template>
But when I print the other Report Just like Sale or Purchase It effect all the report.
So, My Question is that how to print invoice reference on Invoice report starting of Second page also?
You are in the right way, but in your invoice report, you need call a custom external_layout that call a custom header like this
<t t-call="report.external_layout_custom">
<t t-call="report.external_layout_header_custom" />
<t t-raw="0" />
<t t-call="report.external_layout_footer_custom" />
</t>
</t>

Generate Odoo11 Custom Reports with Wizard. Format error: Not a PDF or corrupted

i'm trying to print an Odoo custom report based on a wizard.
it takes inputs from a wizard view. The wizard lets the user select a project with start_date and end_date. and click print button. so the list of activities that match the wizard form fields filter should be printed in a PDF. but i got a PDF file with 0 KB and when i try to open i get Format error: Not a PDF or corrupted. and there is no errors in console
Here is some key files
reports/__init__.py
# -*- coding: utf-8 -*-
from odoo import models, api
class ReportWorkPlan(models.AbstractModel):
_name = 'ewonga_pta.report_model_work_plan'
#api.model
def render_html(self, docids, data=None):
docs = self.env['ew.pta.line'].browse(docids)
docargs = {
"doc_ids": docs.ids,
"doc_model": "ew.pta.line",
"docs": docs,
}
return docargs
reports/print_work_plan_template.xml
<?xml version="1.0" ?>
<odoo>
<template id="report_work_plan_template">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="web.external_layout">
<div class="page">
<h2>Report title</h2>
</div>
</t>
</t>
</t>
</template>
</odoo>
reports/work_plan_report.xml
<?xml version="1.0" ?>
<odoo>
<report
id="action_work_plan_print_report"
string="Print Report"
model="ewonga_pta.report_model_work_plan"
report_type="qweb-pdf"
name="ewonga_pta.report_work_plan_template"
file="print_work_plan_template"
/>
</odoo>
wizards/workplan.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class WorkPlanWizard(models.TransientModel):
_name = "ewonga_pta.work_plan_wizard"
# attendee_ids = fields.Many2many('res.partner', string="Attendees")
project_id = fields.Many2one("account.analytic.account", domain=[("type_interne", "=", "projet" )])
start_date = fields.Date("Date de début")
end_date = fields.Date("Date de fin")
#api.multi
def check_report(self):
data = {}
data["form"] = self.read(
[
"project_id",
"start_date",
"end_date"
]
)[0]
return self.env.ref("ewonga_pta.action_work_plan_print_report").report_action(self, data=data)
wizards/wizard_work_plan.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="action_work_plan_wizard_action" model="ir.actions.act_window">
<field name="name">Generate Workplan Report</field>
<field name="res_model">ewonga_pta.work_plan_wizard</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="work_plan_wizard_form_view"/>
<field name="target">new</field>
</record>
<record model="ir.ui.view" id="work_plan_wizard_form_view">
<field name="name">work_plan_wizard.form</field>
<field name="model">ewonga_pta.work_plan_wizard</field>
<field name="arch" type="xml">
<form string="Add Attendees">
<group col="4" colspan="4">
<field name="project_id"/>
<field name="start_date"/>
<field name="end_date"/>
</group>
<group col="4" colspan="4">
<footer>
<button name="check_report" string="Imprimer" type="object" default_focus="1" class="oe_highlight"/>
or
<button string="Annuler" class="oe_link" special="cancel"/>
</footer>
</group>
</form>
</field>
</record>
</odoo>
os: Window 10 x64
python: version 3.6.5
wkhtmltopdf: version 0.12.3.2 (with patched qt)
please help me to solve this issues. Thanks
Try to remove your "data" parameters pass thru "report_action" call. Self already contain datas.
Thanks

How Can I parse and convert Dates & Times?

I met Odoo for first time a little less than a month ago, and, a DOS Systems Analyst from the 90's, am helping to implement it for a small but fast growing local manufacturer. Largely out of the industry the last 15 years, I'm not pro, but fast learning Python, HTML (some past exper) and Java...
I've been through the Developer Docs, as well as the Developer's Cookbook & Essentials, and a variety of online tutorials (just about everything Google could come up with from several search word combinations).
I read the closed post asking about this and get that there's apparently no actual Odoo reference...
Can someone please tell me where I might find 'date/time' parse and conversion functions that I can access from a report that is using the 'canned' 'hr.employee' model?
<?xml version="1.0"?>
<t t-name="hr_attendance.report_attendancelog">
<t t-call="report.html_container">
<t t-call="report.external_layout">
<div class="page">
<div class="oe_structure"/>
<div class="row">
<div class="col-xs-6">
<h2><br/>Attendance Log: </h2>
</div>
</div>
<table class="table table-condensed mt32">
<thead>
<th><strong>Date / Time</strong></th>
<th><strong> Operation</strong></th>
</thead>
<tbody>
<t t-foreach="docs" t-as="o">
<t t-set="DspDate" t-value="o.name"/>
<t t-set="DspTime" t-value="o.name"/>
<!-- I want to parse 'o.name', which is 'date time' format (from
Attendance record) to separate 'Date' and 'Time' fields... -->
<!-- t t-set="DspDate" t-value="FUNC?(o.name)"/ -->
<!-- t t-set="DspTime" t-value="FUNC?(o.name)"/ -->
<!-- and do calcs with date & time...) -->
<!-- t t-set="ClcDt1" t-value="FUNC?('PrvDt')"/ -->
<!-- t t-set="ClcDt2" t-value="FUNC?(DspDate)"/ -->
<!-- t t-set="ClcTm1" t-value="FUNC?('PrvTm')"/ -->
<!-- t t-set="ClcTm2" t-value="FUNC?(DspTime)"/ -->
<tr>
<t t-if="ClcDt1 == ClcDt2">
<td><span t-esc="DspDate"/></td>
<td><span t-esc="DspTime"/></td>
<td><span t-esc="o.action"/></td>
</t
</tr>
</t>
<tr class="border-black">
<td colspan="3"><strong>Total period</strong></td>
<td><strong t-esc="o.worked_hours"/></td -->
</tr>
</tbody>
</table>
</div>
</t>
</t>
</t>
I prefixed 'br/' to H2 to keep the it properly positioned (only shows on the first page), but subsequent pages obscure the col headers behind the layout header... this is probably obvious and I'm oblivious, but how can I adjust the 'H2' position to be below the 'header' setup by 'report.external_layout'??
On QWeb rendering you can use the python libs time, datetime and relativedelta. They are included in the so called QWeb context which is used for the evaluation (python eval) of the code in reports. You can see this in Odoo code here.
That means you do something like this:
<t t-set="DspDate" t-value="datetime.datetime.strptime(o.name, '%Y-%m-%d %H:%M:%S').strftime('%d/%m/%Y')" />
I prefer parser classes for reports to define some common functions. For example: you can define the function getDate doing your parsing or transforming stuff. The report code will be much better with parser functions:
<t t-set="DspDate" t-value="getDate(o.name)" />

Resources