Odoo How Can I update my value from another module's value - odoo

I have a question...
As you know in odoo we have sales and purchase apps. I am building a module which will be
provide update product prices in the sales module from the vendor price in the purchase app.
I created a wizard and linked to purchase app.
Okay here is my question...
I want to do this simply.
product.supplierinfo.["price"] = product.product_template["list_price"]
I tried:
for rec self.env["product.supplierinfo"]:
self.env[product.product_template["list_price"]] = rec.["price"]
But as you know it's not working ^^
Any advice for this?

i think you mean to do like this
new_price= self.env[product.product_template].write({
"list_price" : rec.price,
})

Related

How to programatically create a paid invoice from sale order [duplicate]

I am trying to make a single action on a sales order in Odoo v15 CE that creates an invoice for the sales order and immediately posts it and registers a payment for it. The way I'm doing so is through a wizard method that looks like this:
def create_invoices(self):
sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', []))
for order in sale_orders:
order._create_invoices()
for inv in order.invoice_ids:
# make invoice:
inv.action_post()
# register payment
# ????
Currently, it creates the invoice and posts it. I would like to add something like inv.register_payment() to the final line in order to register the payment.
I've fount the action_register_payment method of the account.move model and also looked into using the account.payment.register wizard but neither worked. I've also found this question, which is trying to do something similar, but through an XML-RPC call (from what I can tell).
Can anyone please explain how to do this? Thanks!
You have to post the invoices using action_post then register payment by creating a payment like in
https://github.com/odoo/odoo/blob/15.0/addons/account/wizard/account_payment_register.py#L496
account.payment.register is a wizard, that's why you need to create values for it, otherwise you can action_register_payment which is a window action that will trigger the wizard and then it's for the user to register the payment (which is the standard behavior of Odoo)
You can create an account.payment.register record and pass the model and invoice ids in context then call action_create_payments to create the payment with the default values.
Example:
payment_register.with_context(
{'active_model': 'account.move',
'active_ids': inv.ids}
).create({}).action_create_payments()

Minimum purchase in the checkout page by address ( City for example )

Hello to all the community,
Thank you in advance to whoever will take the time to answer me šŸ˜†!
In fact, I want to find a solution to make the minimum purchase on the checkout page ( not on the cart page ) and it depends on the address city.
I already did it in Prestashop 1.6 but now I use Prestashop 1.7.7.1 I am obliged to override the cart Presenter but I didn't rich a convenient solution.
Even I purchased a module of minimum purchase by country and modified it to be by the city but the module itself is not stable and it didn't work properly and the support of the module cannot find a solution because it requires an override of the core of Prestashop in the Symfony code and it will affect all the order tunnel which is typically impossible.
This topic will be a real challenge for developers that they don't know the impossible šŸ˜†!
Thanks in advance.
Assuming you are creating a module, in CartPresenter class you have hook overrideMinimalPurchasePrice. You can hook your module to this hook and modify the $minimalPurchase value in your module according to your logic.
You said that price depends on the address's city. Well, in your hook you can get the address, because in Prestashop front-office you always have access to cart and cart might have delivery address id:
public function hookOverrideMinimalPurchasePrice($params)
{
$cart = $this->context->cart;
$id_address = $cart->id_address_delivery;
// If customer did not enter the address yet, the address id is 0.
if($id_address != 0)
{
$address = new Address($id_address);
$city = $address->city;
if($city == 'New York')
$params['minimalPurchase'] = 100;
}
}
}
You do not have to return anything in the hook, because in CartPresenter.php the hook is called with parameter being passed by reference:
Hook::exec('overrideMinimalPurchasePrice', [
'minimalPurchase' => &$minimalPurchase,
]);

Create an invoice from a sales order using XML-RPC (Python)

I'm following the external APIs documentation : https://www.odoo.com/documentation/13.0/webservices/odoo.html
to implement our companies requirements. I'm required to create a sales order and automatically create an invoice after that. The sales order part is done but I cant seem to be able to attach the Invoice to the Sales order
I've tried linking it via the 'invoice_ids' field but the documentation does not mention how to provide a many2many field in it. here is the code:
many2manyInvoice = [(4, invoice_id)]
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
#Admin user Id
uid = common.authenticate(db, username, password, {})
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
models.execute_kw(db, uid, password, 'sale.order', 'write', [[sales_order_id], {'invoice_ids':many2manyInvoice}])
The response returned is 200 , but nothing is happening on the sales order level. I think its the way that I defined the field that might be incorrect.
Can someone help with this issue ? Thanks in advance
Nothing is happening on the sales order level because you are not creating a sales record, writing to it without doing anything. Not sure if this would work in your specific case but here is what I would do.
Use the Pro-forma invoice https://www.odoo.com/documentation/user/13.0/sales/invoicing/proforma.html
Then when a sales record is created run the "Send pro-forma invoice" method using the web api. This takes care of the db linking, as it can get very complicated.

SAP Hybris - current selected category or product in storefront

is possible get the currently selected product category or product in any mvc controller/service?
Thanks.
Yes, possible.
In ProductPageController.java, you will find ProductData as below.
final ProductData productData = productFacade.getProductForCodeAndOptions(productCode, extraOptions);
You will get Categories from,
productData.getCategories()
and similarly you will get product as well.

Magento Import of tier prices with SOAP API V2 doesnt work

hope to get some help here.
I try to create tier prices in Magento for groups using soap api v2.
Currently using version 1.9.0.0 of Magento
Am developing with delphi, using the WSDL.
What i do is the following, looping through the tier prices of my ERP system:
mycatalogProductTierPriceEntity := catalogProductTierPriceEntity.Create;
mycatalogProductTierPriceEntity.customer_group_id := group_price_mage_group_id;
mycatalogProductTierPriceEntity.website := IntToStr(Website_ID);
mycatalogProductTierPriceEntity.qty := Round(WINLineArtikelStaffelMenge);
mycatalogProductTierPriceEntity.price := 2.85;//WINLineArtikelStaffelKundenPreis;
mycatalogProductTierPriceEntityArray[j] := mycatalogProductTierPriceEntity;
inc(j);
mycatalogProductTierPriceEntity := nil;
Finally I assign my Price Array to the Product Entity:
mycatalogProductCreateEntity.tier_price := mycatalogProductTierPriceEntityArray;
But the prices wont show in Magento Admin, no error listedā€¦ either on creating a product or updating it.
All other fields are updated / created correctly.
I made a test and entered 2 group tier prices in the backend
Both for group ā€œRetailerā€
Then i tried to get the product info via soap call ā€œcatalogProductInfoā€.
On debugging i looked inside the result set and could see my 2 tier prices, but without group specified and without quantity specified,
although i can see that in the backendā€¦
Anybody an idea of what is wrong ?
best regards
Holger
OK, I found the solution on my own...
All the API calls are totally correct.
But there is a setting in the Magento Administration
(System->Configuration->Catalog)
where you can define the price range. Default setting is "global" which has to be switched to "website".
Only with this setting, customer group tier prices can be written.