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

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})]})

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)

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

Recalculate taxes on programatically created invoice in Odoo 12

In odoo I have created an invoice with correct invoice line items ( including tax ). I am using a node module for this which calls the /web/dataset/call_kw endpoint in odoo.
My problem is, that the tax on the invoice is not updated after adding the line items. It remains 0. Can I force the recalculation of the invoice or must I calculate the total tax and set it on the invoice programatically?
I have tried to call the method button_reset_taxes() on the account.invoice object via the web api, but failed.
Error:
account.invoice has no attribute button_reset_taxes.

Value error expected singleton in Odoo

I have a module named uniform request, which contains a field named select product, which contains inherited data from another module named product. Product, when I select the product I want to purchase a button shows named send request to purchase, after selection a confirmation button shows and after confirming the request I have the option to make new quotation, but when I try to make the new quotation an error message shows:
ValueError: Expected singleton : product. Uom()
It seems you need to assign UoM (Unit of Measure) to the selected product, make sure that you insert a valid value of this field uom_id.

Openerp add fields in invoice

![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.