I am using odoo 15 ; I am trying to customize receipt in point_of_sale module
I have a problem regard access the custom filed in company module as following :
My customized module : custom/models/res_company.py
class rescompany(models.Model):
_name = "res.company"
_inherit = "res.company"
#customized fields
x_industry = fields.Char(string='Compnay Industry', translate=True)
my customized view in xml : custom/static/src/xml/custom_pos.xml
<xpath expr="//t[#t-if='receipt.company.logo']" position="before">
<div>
<span style="font-size: smaller;float: left">
<t t-esc="receipt.company.name" />
</span>
</div>
<div>
<div>
<span style="font-size: smaller;float: left">
<t t-esc="receipt.company.x_industry"/>
</span>
</div>
</div>
</xpath>
</t>
</templates>
manifest.py
...
'assets': {
'web.assets_backend': [
"custom/static/src/js/OrderReceipt.js",
],
'web.assets_qweb': [
'custom/static/src/xml/custom_pos.xml',
],
},
...
Now, I don't know how to access x_industry in OrderReceipt.js ?
I tried to follow this link :
Odoo PoS not showing custom fields in receipts
but it is in odoo 13 and I did not understand the parameters I should add to be modified correctly ;
You cannot access a field in PoS even though it has been added through python code. You need to load the specific field in the javascript files for Point of Sale.
Regarding your question, you need to add a field which is specific for a company. The easiest method is to also add the same field in pos.config model and give a related connection with the new field which you added in res.company.
x_industry = fields.Char(string='Compnay Industry', translate=True, related='company_id.x_industry')
Any field added in the pos.config can be accessed from the PoS and PoS receipt.
<t t-esc="env.pos.config.x_industry"/>
Related
Sounds simple, but I couldn't find a hello-world example of this, despite the richness of the doc. The closest I could find was in https://react-hook-form.com/advanced-usage, in the Working with virtualized lists section, but that relies on another module react-window, which introduces further complexity.
I want to allow the admin user to create-update-delete a list of products, with various properties.
My current code in JSX looks like this, I'd like to take advantage of error handling etc from react-hook-form:
<ol >
{products.map((row, index) => (
<li
className={index === selectedProductIndex ? "selected" : ""}
key={index}
id={index} onClick={handleSelectProduct}>
{row.name}
</li>
))}
</ol>
<form onSubmit={handleSaveProduct}>
<p>Product name: </p>
<input name="productName" type="text" value={selectedProductName}
onChange={handleEdit_name} />
(... more properties to edit here)
</form>
The handlers save the values of selectedProductName, selectedProductIndex, etc in useState, in a database via axios, etc.
I'm handling the values of each field individually in the useState, which I'm aware is laborious and heavy-handed.
Well the answer was quite simple, although it took me a while to figure it out.
In most of the examples, the onChange or onClick handlers don't use the event object, but nothing prevents you from adding it in. Then there's the setValue function to set the other control's value. Here's the code of a hello-world example. It offers one dropdown and one input field, the input field updates to match the selected value of the dropdown.
import React from "react";
import {useForm} from "react-hook-form";
function Test() {
const {register, handleSubmit, errors, setValue} = useForm();
const mySubmit = data => {
console.log(data);
}
return (
<div>
<form onSubmit={handleSubmit(mySubmit)} className="reacthookform">
<select name="dropdown" ref={register}
onChange={(ev) => setValue("productName", ev.target.value)}>
{["AAA", "BBB", "CCC"].map(value => (
<option key={value} value={value}>
{value}
</option>
))}
</select>
<input name="productName" defaultValue="AAA" ref={register({required: true})} className="big"/>
{errors.productName && <p className="errorMessage">This field is required</p>}
<input type="submit" value="Save product"/>
</form>
</div>
);
}
export default Test;
Sorry for my English.
I need to change input value format, for example: from "1000000" to "1 000 000 $".
In my views of rails app, I have this line of code:
<%= ng_text_field('total_price', 'selected.data.total_price', 'Full price', ng_readonly: '!selected.permissions.update') %>
In helper:
def ng_text_field(name, ng_model, placeholder, options = {})
result = <<-HTML
<div class="form-group" ng-class='{"has-error":errors.#{name}}' #{options[:ng_if] && "ng-if=\"#{options[:ng_if]}\""}>
<label for="#{name}" class="col-sm-3 control-label">#{placeholder}</label>
<div class="col-sm-9">
<input id="#{name}"
type="text"
class="form-control"
name="#{name}"
placeholder="#{placeholder}"
ng-model="#{ng_model}"
#{options[:ng_readonly] && "ng-readonly=\"#{options[:ng_readonly]}\""}>
<p class="help-block small" ng-if="errors.#{name}">{{errors.#{name} | join:',' }}</p>
</div>
</div>
HTML
result.html_safe
end
I am know Angular very little, I have tried some ways and all this ways was incorrect. :(
Could anyone give advice of some help?
Thank you in advance
You're going to need to create a new directive that requires ngModel and applies the appropriate $parser/$formatter to it.
https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#$parsers
A good example of how to do this is (displaying as uppercase but always storing data as lowercase):
ngModel Formatters and Parsers
You should be able to then add the ability to include other directives in your 'options' argument so that they get added correctly to the output.
I had a little problem on Prestashop 1.7.2.0, I want to add some field in my contact us form but don't know how to proceed.
I just find tuto for PS 1.6.
If someone could help me.
Thanks a lot
Here a no update resistant solution to add a field Name:
I tried the following thing to add a field (and remember this solution is not update proof and the additional fields are not safed in the backoffice):
Update contact.html + contact.txt in the theme/mails folder:
<span style="color:#333"><strong>Name: {contactname}</strong></span><br /><br />
Add the contactname line to the $var_list array in the file contactform.php located in the modules/contactform folder:
$var_list = [
'{order_name}' => '-',
'{attached_file}' => '-',
'{message}' => Tools::nl2br(stripslashes($message)),
'{email}' => $from,
'{product_name}' => '',
'{contactname}' => Tools::nl2br(stripslashes($contactname)),
];
Add a line to the beginning of the function sendMessage(){ in the same file (contactform.php)
$contactname = trim(Tools::getValue('contactname'));
Add the following lines to the part in the file contactform.tpl located in the theme/modules/contactform/views/template/widget folder:
<div class="form-group row">
<label class="col-md-3 form-control-label">{l s='Name' d='Shop.Forms.Labels'}</label>
<div class="col-md-6">
<input
class="form-control"
name="contactname"
type="text"
value="{$contact.contactname}"
placeholder="{l s='Ihr Name' d='Shop.Forms.Help'}"
>
</div>
</div>
I know it's ugly, but hey, it's a start :) as soon as prestashop 1.7 is not buggy anymore I will start programming with proper overrides/modules
Can I use gr:category and rdf:type from product ontology together?
I see vso:Canoe from automobile ontology...
<div typeof="gr:SomeItems vso:Canoe" about="#product">
<span property="g:name">ACME Foldable Canoe</span>
<div property="gr:category" content="Outdoors/Boats/Canoes"></div>
</div>
However I'm using productontology,is this possible?
<div about="#myObject" typeof="http://www.productontology.org/id/Canoe">
<div rel="rdf:type" resource="http://purl.org/goodrelations/v1#SomeItems"></div>
<div property="gr:description" xml:lang="en">... a longer description ...</div>
<div property="gr:name" xml:lang="en">.. a short name for the object ...</div>
<div property="gr:category" content="Outdoors/Boats/Canoes"></div>
</div>
Yes, that is well possible and increases a client's ability to understand your data.
So
<div about="#myObject" typeof="http://www.productontology.org/id/Canoe">
<div rel="rdf:type" resource="http://purl.org/goodrelations/v1#SomeItems"></div>
<div property="gr:description" xml:lang="en">... a longer description ...</div>
<div property="gr:name" xml:lang="en">.. a short name for the object ...</div>
<div property="gr:category" content="Outdoors/Boats/Canoes"></div>
</div>
is perfectly valid.
There is currently no official statement from major search engines on the ways they honor additional type information, but it is a safe assumption that
it does not harm adn
the more data of this form is out there, the more it will matter for search engines.
Yes, you can use types and properties from any namespace in RDFa (and RDF in general). In the case of your snippet, you could even get rid of the rdf:type line since #typeof accepts multiple types from any number of namespaces, and those types can be in the form of CURIEs or full URIs (same applies to #property). So your snippet would become:
<div about="#myObject" typeof="http://www.productontology.org/id/Canoe gr:SomeItems">
<div property="gr:description" xml:lang="en">... a longer description ...</div>
<div property="gr:name" xml:lang="en">.. a short name for the object ...</div>
<div property="gr:category" content="Outdoors/Boats/Canoes"></div>
</div>
I have an ASP.NET MVC site and I am trying to get knockout-mvc working with it.
I have created a View Model in the C# code called Refund that contains among other things a Voucher called Vouchertype and a List<Country> called Countries. Voucher has a variable of type int called VoucherNumber
This View Model is passed into a strongly defined view Refund\Index
I am trying to get knockout-mvc to bind the values in Refund.Voucher.VoucherNumber to a textbox, and the Values in Refund.Countries to a drop-down list. On the controller I have hardcoded the values of Voucher.Vouchernumber and added two countries to the Country list.
Here is my View Code:
#using Resources
#using PerpetuumSoft.Knockout
#model MVC.Models.RefundViewModel
#{
var ko = Html.CreateKnockoutContext();
}
<div id="refundformcontainer">
<div id="headersection">
<div id="pagetitlecontainer">#Language.RefundVouchers</div>
<div id="helpercontainer">
<label id="lblhelper">To begin enter a voucher number or scan a barcode</label>
</div>
</div>
<div id="vouchercontainer">
<div id="voucherdetailscontainer">
<h5>#Language.VoucherDetails</h5>
<div id="vouchernumbercontainer" class="initialvoucherfield">
#Html.LabelFor(x=>x.Voucher.VoucherNumber)
#ko.Html.TextBox(x=>x.Voucher.VoucherNumber)
</div>
<div id="countrycontainer" class="initialvoucherfield">
#Html.LabelFor(x=>x.Voucher.Country)
<select ko.Bind.Options(x=>x.Countries).OptionsText("Name").OptionsValue("CountryId").Value(x=>x.Voucher.CountryId) ></select>
</div>
</div>
</div>
</div>
#ko.Apply(Model);
When the page loads, neither controls are bound to.
When I look at the generated source the following code is generated
<script type="text/javascript">
var viewModelJs = {"Refund":null,"Voucher":{"VoucherId":0,"VoucherNumber":123456789,"Country":null,"CountryId":0,"Retailer":null,"RetailerId":0,"PurchaseDate":"0001-01-01T00:00:00","CustomsStampDate":null,"InvoiceNumber":"","LineItems":[],"TotalPurchasePrice":0.0},"Countries":[{"CountryId":380,"Name":"Italy"},{"CountryId":724,"Name":"Spain"}]};
var viewModel = ko.mapping.fromJS(viewModelJs);
ko.applyBindings(viewModel);
</script>
knockout-2.2.0.js and knockout.mapping-latest.js are both included in the page
The error I am getting is
0x800a139e - JavaScript runtine error: Unable to parse bindings
Message: [Object Error]
Bindings value: Voucher().VoucherNumber
I then changed the Refund View model so it had a property VoucherNumber and had the textbox reference this instead of the Voucher.VoucherNumber property
#ko.Html.TextBox(x=>x.VoucherNumber)
When I ran this I got the same unable to parse bindings error, but this time for the country
Bindings value: options : Countries, optonsText : Name, optionsValue : CountryId
Does anybody have any idea what is causing this?
i think, this should work.
<select #ko.Bind.Options(x=>x.Countries).OptionsText("'Name'").OptionsValue("'CountryId'").Value(x=>x.Voucher.CountryId) ></select>