Openerp add fields in invoice - odoo

![openerp invoice][1]
[1]: http://i.stack.imgur.com/h6zY0.pngemphasized text
I would like to add discount ammount to my invoice template not in percents but in real ammount
Example: item value 100$, discout 10%, discount is 10$
i need to put it in a template like in the picture above

The account_invoice_line class in OpenERP is designed in such way to consider the discount field as percent. If you need discounts in absolute value you need to customize the account module and modify the account.invoice.line object. Maybe the easiest is to add another filed - let say abs_discount, and to take it with priority, if present.
You should look at least at the methods _ammount_line(), _price_unit_default(), move_line_get() and compute() of the account_invoice_line class.
You should also modify the Invoice view to allow the editing of the new field.

Related

Prestashop add custom radio button on shipping carriers on front end checkout

I have created one custom module in Prestashop 1.7.8.7 which will add multiple shipping methods (Carrier) and will show shipping cost based on product dimensions and delivery address. So shipping carrier will look something like this on front-end checkout page. https://prnt.sc/E1avDASyJYYW
Now if someone select SameDay Courier Shipping then i need to show two radio button to select which service they want.
It will have two radio options like
Delivery pickup (by default this option will be selected)
Locker pickup
So if someone select Delivery pickup then it will have different shipping cost and if someone select Locker pickup then it will have different shipping cost.
Can anybody help me how can i achieve this functionality.
While digging, i found that we have file called DeliveryOptionsFinder.php and in that file we have one public function called getDeliveryOptions() where we have this line of code
if ($moduleId = Module::getModuleIdByName($carrier['external_module_name'])) {
$carrier['extraContent'] = Hook::exec('displayCarrierExtraContent', ['carrier' => $carrier], $moduleId);
}
}
So if i set is_module to 1 to all my carriers directly from DB then on frontend checkout page, no carriers is being displayed.
Thanks in advance.
I've already done something like this in the last 2 year as prestashop developer.
The truth is that you can't achieve what you want by "respecting" prestashop processes.
Maybe you can hook using a module the hookDisplayCarrierExtraContent($data) and then return the 2 radios if carrier is certain one (use $data).
But you can't handle a form submit or something else, or include it to prestashop checkout data.
But what you can do as workaround, for example, is the following.
In your module, as I said, hook the extra content, render a template with the 2 radios. Hook displayHeader too and use $this->context->controller->addJS() to add your own js if the current controller is the checkout one.
Then in this JS code you can handle the "change" event of the radios and send an ajax request to your module.
You can create inside {your_module}/controllers/front/ a controller called, for example, radio-choose and handle the js ajax request by saving inside your own table the choosen one.
Obviously you can disable the "next" button in checkout untill one of the two radios are selected, or maybe you can just set a radio button as default one to simplify.
For example your table "ps_cart_choosen_radio" could look like this |id_cart|choosen_radio|.
Then you have all the data you needed. When a cart is converted into an order you will have inside Order object (and ps_orders table as well) the id_cart.
Just select / join choosen radio from your own table by using order's id_cart.
"SELECT choosen_radio FROM ps_cart_choosen_radio WHERE id_cart = {$order.id_cart}"
If you need to show data depending on choosen_radio in frontend you can hook everywhere an order is present and select these data. Or maybe you can edit carrier name in ps_orders table by adding a piece of string. Let' say carrier is "express" and customer choosed "24h". You can update that column with carrier name by changing it to "express-24h" so around the whole prestashop ecosystem everybody will see that's a 24h choice.
Remember that the carrier name related to an order is not the carrier name inside the carriers table. So you can edit it without having trouble.
All these problems comes from the "need" to show some nested choices instead of listing all these in the main selections. In that case it would be easy (just create carrier in the prestashop backoffice)

Odoo Add Tax on invoice by Code but Total on Invoice not change

I am trying to add tax into invoice line by doing
discount_l.write({'tax_ids': tax_ids})
which did add tax into 'account_move_line' but the total of invoice did not change. I try debug and notice that onchange method did not trigger. I read some document and onchange only triggers on FORM. What should I do? I dont know how many onchange methods I need to call manually
The total will be automatically computed if you update the invoice lines using the invoice reference.
In the following example, we will use the new commands link function to update a specific invoice line tax_ids field:
Example:
invoice_id.write({'invoice_line_ids': [Command.update(invoice_line_id, {'tax_ids': tax_ids})]})

How to modify sale order line when an invoice is created?

I do some modification on sale.order.line I add some fields, one of those fields is a checkbox.
my request is when I want to create an invoice only checked line are invoiced, how can I do this Please?
There is two solution for your problem either override create invoice line function or remove sale_order_line(hide) from sales and make new model which has same fields like sale_order_line add all your field there (product, realize all these fields). Gave functionality so that if checkbox is enabled(realize in your case) that automatically will added in sale order line and which checkbox is disable will remove from sale_order_line (You have to override create, write and unlink function of that model). By this way the lines which is enabled will be added in sale_order_line and everything will be done in odoo way

Showing different price on category page and single product page in variable product in bigcommerce

Showing different price on category page and single product page in variable product in bigcommerce. I just want to show the lowest price on category page.
This is the category page: https://hilineelectronics.com/portable-audio/. In the first product price is showing $112.99 and after checking it quick view and single product page it is showing $83.99. I want $83.99 (varibale amount) amount there.
How can we do this? Any variable or code for this?
Thanks in advance.
Go to your CategoryProductsItem.html check the code
<em class="p-price">%%GLOBAL_ProductPrice%%</em>
Is there %%GLOBAL_ProductPrice%% call same or different with product details page.
ProductDetails.html
<span class="ProductPrice VariationProductPrice">%%GLOBAL_ProductPrice%%</span>
Compare both files global varriable.
The second way makes the backup and of the files and then revert it to the original.

Prestashop Custom / Calculated Product Price

I have canvas banner printing website. I want customer to enter width and height and using my own custom table I am calculating and showing price. Now I want to move calculated price to Cart and from there to Order generation. I have checked prestashop tables for cart but it is storing Product Ids and joining to Products tables to get prices. Is there anyway to achieve my requirements?
This feature is not available by default in prestashop and i dont know any module for now which can do it without overloading core functionality. I am providing you only the theory and some files references for you. Please try it.
Lets consider the following general assumptions:
a) Measuring Unit is inch.
b) Per inch price is 5 usd
c) You will also need a price calculation formula, and for this example lets it is
finalPrice = width x height x 5 //width and height are formula variables
Now for prestashop you can perform the following steps:
1) Update cart table and add three fields, width, height and final_price. (The number of fields may vary according to your formula variables.)
2) Overload cart class and add properties for width, height and final_price. Also you will need to override the method which fetch all products from the cart and check if a cart product has custom price or width and height. Also all taxes, shipping costs can be applied there.
3) If you are using ajax add to cart feature, then you will need to modify blockcart module a little. You may need to modify ajax-cart.js to get width, height and final price values to post to the cart controller. Also blockcart-json.tpl may need some modifications as this file is used to populate the cart block contents. Also you may need to modify blockcart.tpl file where you can show width and height etc in the blockcart. This way you will be able to show the variables in blockcart.
4) Now next step is actually adding product to cart. Data is posted to CartController, so you will need to override it, and receive width, height and final price from the posted data. You will need to place appropriate checks if width, height and final price are available or not to detect the custom price product.
5) You will need to override OrderController to populate the shopping cart page products list with width, height and final price.
6) In all above theory, we have added product to cart and populated blockcart and shopping cart page with width, height and final price data. Now next step is completing the order. For this you will need to work with Order class, order controller and cart class. and order_product table. In order product table add same fields as cart_products table for width, height and final_price. Then modify order class and add these properties to order class.
7) You will need to override PaymentModule class and make changes in the validateOrder method. This method handles your final step in ordering steps, saves order, sends email to customer and, if enabled, site administrator(s). So here you will need add width, height and final price info in the order products db insertion code. Also you will need to supply these variables to the email templates so the customer can get the width, height and final price of the product in the email also.
8) You will also need to modify the order history section so customers can see all those details in his/her order history also.
9) You will need to make changes in Admin Order controller to show those data in the order view section for the admin.
10) And finally (not actually final :P ), you will need to make changes in the pdf invoice generation so that width, height and final price are shown in pdf invoice also.
Note : Above theory is from my experience with a similar feature in prestashop and may work or not work for you according to your requirements.
Try this, and i hope you will make it work :) ..
Good Luck...