Error occurred during price list product assignments build - orocommerce

I'm attempting to create a price list within oro community. I'm not totally familiar with symfony however have managed to write a product assignment rule product.id in product.product_class == "Class_Name" then a calculate as pricelist[15].prices.value * 0.25 where pricelist[15] = Recommended Retail Price.
The system starts to calculate and then returns an error:
Error occurred during price list product assignments build
I'm not sure what I'm doing wrong? Any help would be greatly appreciated.

You don't need to be familiar with Symfony to write expressions in the OroCommerce management console. There is documentation and many examples of expressions in OroCommerce:
https://doc.oroinc.com/user/back-office/sales/price-lists/auto/.
The expression product.id in product.product_class == "Class_Name" doesn't make much sense as the right expression of in operator must be an array, but in your case it's boolean.

Related

Global / Line Discount for Sale/Purchase/Account

[Odoo 14 Community Edition]
I need to customize Global and Line Discounts (amount & percentage) into Sale / Purchase / Account.
I have done the Sale and Purchase parts. It is just adding fields and a few logics here and there and send the data to Account (account.move) by prepare_invoice methods.
Now here's the issue I am facing -- The Account. I am having a tremendous confusion of where I should modify. After I tried to understand and tracked the flow of the standard invoicing/billing, I am at lost. There are too many functions/variables for me, who do not understand accounting, to try to get the whole idea out of it.
I did add the discount fields that I need. However, the standard calculation of price / taxes / credit / debit are messed up when I try to inherit some methods that I think I should modify. I ended up having incorrect taxes, unbalanced credit/debit, and incorrect total amount.
I tried editing here and there (by inheriting of course. I can still rollback everything I did).
The point is that I need precise suggestions and/or directions of what functions/methods I should inherit just enough to make discount possible. I have 2 Line Discount fields (amount and percent) and 2 Global Discount (also amount and percent). The calculation between them is not the point of interest here. The only problem at this point is to integrate these fields (from SO, PO, and manually created) into the calculation of everything in Invoicing/Billing.
Here are the fields:
account.move
global_discount_amount = fields.Float(string='Global Discount Amount', compute=compute_global_discount_amount, store=True)
global_discount_percent = fields.Float(string='Global Discount Percent', compute=compute_global_discount_percent, store=True)
account.move.line
discount_line_amount = fields.Float(string='Disc. Line Amount', compute=compute_discount_line_amount, store=True)
discount_line_percent = fields.Float(string='Disc. Line %', compute=compute_discount_line_percent, store=True)
Right now, I am messing with some methods such as: (a few examples)
account.move
_recompute_tax_lines
account.move.line
create
_get_fields_onchange_balance_model
_get_price_total_and_subtotal_model
_onchange_price_subtotal
Most of the modifications are written by copying the whole method from standard into my new model (inherit that standard model) and edit some codes here -- Override the standard code from my understanding.
Function computation/execution either depends on other fields value change or compute every time form/listview load.
Check in your case what is depends on the function compute_global_discount_amount and compute_global_discount_percentage
For better developing/troubleshooting, remove any #depends() fields declaration on the functions. Additionally, remove the store=True attribute temporarily. It will help you to narrow down the issue. And make sure you get the correct numbers.
Once you get it, add back fields depending.
Here is a sample example of a method (Odoo 14 CE) override which will be executed during compute amount.
#api.depends(
'line_ids.matched_debit_ids.debit_move_id.move_id.payment_id.is_matched',
'line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual',
'line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual_currency',
'line_ids.matched_credit_ids.credit_move_id.move_id.payment_id.is_matched',
'line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual',
'line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual_currency',
'line_ids.debit',
'line_ids.credit',
'line_ids.currency_id',
'line_ids.amount_currency',
'line_ids.amount_residual',
'line_ids.amount_residual_currency',
'line_ids.payment_id.state',
'line_ids.full_reconcile_id')
def _compute_amount(self):
super()._compute_amount()
for record in self:
record.compute_global_discount_amount()
record.compute_global_discount_percent()
def compute_global_discount_amount(self):
for record in self:
# Execute your logic for compute global_discount_amount
record.global_discount_amount = $$$$
have a look at apply_discount function in an inherited class of sale.order
def apply_discount(self, cr, uid, ids, discount_rate):
cur_obj = self.pool.get('res.currency')
res = {}
line_obj = self.pool.get('sale.order.line')
for order in self.browse(cr, uid, ids, context=None):
for line in order.order_line:
line_obj.write(cr, uid, [line.id], {'discount': discount_rate}, context=None)
return res
A new column was added to the new inherited subclass of sale order
'discount_rate' : fields.float('Discount rate'),
Then in the sale order view (an inherited one) placed the new field discount on the sale.order.view and fired an event on the on_change of the value passing the self value of the field to the on_change event
In this way you can apply discount sequentially to the rows of the order without altering the normal process.
Firstful, please pardon my English. Then let's get into the core, I guess that this is exactly the task that I was assigned. Luckily that I was not alone, I was guided by my so-called senior which showed me the way in order to achieve the Global Discount for Invoice and Bill.
By looking at your methods listing, you were already on the right path!
So now, let me help you further...as much as I can
As in my case, I didn't put any new field regarding the Global Discount in Account Move Line model, even though in Sale Order Line and Purchase Order Line Global Discount fields do exist.
All and all, here are the methods that need to be customized:
_onchange_invoice_line_ids
_compute_amount
_recompute_payment_terms_lines
_recompute_tax_lines
I heavily modified the 3rd and 4th methods. However, I think that I still have some bugs, don't hesitate to tell me.

MuleSoft: Sum line items and group by ID

I am new to integration and MuleSoft so I need your help. I have a flat file with different invoice line items per salesID, like this:
SalesOrderID OrderQty UnitPrice
43659 70 2024.994
43659 70 2024.994
43660 1 419.4589
43660 1 874.794
43661 1 809.76
I want to insert total invoice amount and quantity in another CSV file using Mule, something like this:
SalesOrderID OrderQty UnitPrice
43659 140 4049.988
43660 2 1294.4589
43661 1 809.76
I know how to do this in informatica,but im trying to figure out a way to do this in MuleSoft. How can I sum up all the line items and group them by SalesOrderID? Any help/clue will be really appreciated.
Thanks.
There are a number of ways to do this, let me explain my personal favourite assuming you are using Mule community edition.
Use the superb library: SuperCSV, it will allow you not only to parse the data (including those dot numbers) but also validate it and give back an exact report on why the file is broken in case it is.
This could be done in a transformer that transform the inbound stream and return either a map of maps (or even better a iterator that handles the whole thing but this is more difficult) or a custom exception with the error report.
Given that this requirement is one that faces Mule developers even today, it's useful to see a solution based on the Mule 4.x runtime and Dataweave 2.x.
If the data came from a file or is otherwise a monolithic stream of text, use the splitBy() function to get an array of text lines.
payload splitBy '\n'
remove the first line as the headers should not be calculated
payload[1 to -1] // this is my favorite way to do it
Now use the reduce() function to iterate over each of the lines in turn, updating the accumulator each time to account for quantity and price.
Hopefully that helps

eBay API aspectFilter with MaxPrice parameter returns 0 results

I am using the following URL to fetch car listing. But when I add the MaxPrice parameter It shows 0 items. But on the site there are 12 items that have price below my value.
http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.12.0&SERVICE-NAME=FindingService&SECURITY-APPNAME=prosoftda-d112-4c99-9bec-8a09c902a7a&RESPONSE-DATA-FORMAT=JSON&paginationInput.entriesPerPage=50&categoryId=6001&outputSelector=PictureURLSuperSize&REST-PAYLOAD=true
&aspectFilter(0).aspectName=Make&aspectFilter(0).aspectValueName=Audi
&aspectFilter(1).aspectName=Model&aspectFilter(1).aspectValueName=Q7
&aspectFilter(2).aspectName=Model+Year&aspectFilter(2).aspectValueName=2013
&aspectFilter(3).aspectName=MaxPrice&aspectFilter(3).aspectValueName=50000.00
When I remove MaxPrice parameter the URL works perfectly.
Btw, I got the solution for this question:
To pass the price value need to pass as ItemFilter. not with the AspectFilter.
I replace the string :
&aspectFilter(3).aspectName=MaxPrice&aspectFilter(3).aspectValueName=50000.00
By the string :
&itemFilter(0).name=MaxPrice&itemFilter(0).value=500000.00
So It works now. As Price parameter is related to attribute so need to pass with the ItemFilter.
So final URL Is:
http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.12.0&SERVICE-NAME=FindingService&SECURITY-APPNAME=prosoftda-d112-4c99-9bec-8a09c902a7a&RESPONSE-DATA-FORMAT=JSON&paginationInput.entriesPerPage=50&categoryId=6001&outputSelector=PictureURLSuperSize&REST-PAYLOAD=true
&aspectFilter(0).aspectName=Make&aspectFilter(0).aspectValueName=Audi
&aspectFilter(1).aspectName=Model&aspectFilter(1).aspectValueName=Q7
&aspectFilter(2).aspectName=Model+Year&aspectFilter(2).aspectValueName=2013
&itemFilter(0).name=MaxPrice&itemFilter(0).value=500000.00
Thanks. may be this can help someone who is finding the same question.
I have no experience with this API so this is just a shot in the dark. But I found this link:
http://developer.ebay.com/DevZone/finding/CallRef/findItemsAdvanced.html
From what Ive read within that MaxPrice is more of an "itemFilter" (things such as maxPrice, bestOfferOnly, featuredSeller) than an "aspectFilter" (things such as Make, Model, Optical Zoom).
Further down it also states that some itemFilters need a paramName, such as maxPrice
For example, if you use the MaxPrice itemFilter, you will need to specify
a parameter Name of Currency with a parameter Value that specifies the type
of currency desired.
Again never used this API but seems relevant to me.

Endeca UrlENEQuery java API search

I'm currently trying to create an Endeca query using the Java API for a URLENEQuery. The current query is:
collection()/record[CONTACT_ID = "xxxxx" and SALES_OFFICE = "yyyy"]
I need it to be:
collection()/record[(CONTACT_ID = "xxxxx" or CONTACT_ID = "zzzzz") and
SALES_OFFICE = "yyyy"]
Currently this is being done with an ERecSearchList with CONTACT_ID and the string I'm trying to match in an ERecSearch object, but I'm having difficulty figuring out how to get the UrlENEQuery to generate the or in the correct fashion as I have above. Does anyone know how I can do this?
One of us is confused on multiple levels:
Let me try to explain why I am confused:
If Contact_ID and Sales_Office are different dimensions, where Contact_ID is a multi-or dimension, then you don't need to use EQL (the xpath like language) to do anything. Just select the appropriate dimension values and your navigation state will reflect the query you are trying to build with XPATH. IE CONTACT_IDs "ORed together" with SALES_OFFICE "ANDed".
If you do have to use EQL, then the only way to modify it (provided that you have to modify it from the returned results) is via string manipulation.
ERecSearchList gives you ability to use "Search Within" functionality which functions completely different from the EQL filtering, though you can achieve similar results by using tricks like searching only specified field (which would be separate from the generic search interface") I am still not sure what's the connection between ERecSearchList and the EQL expression above?
Having expressed my confusion, I think what you need to do is to use String manipulation to dynamically build the EQL expression and add it to the Query.
A code example of what you are doing would be extremely helpful as well.

Magento Bulk update attributes

I am missing the SQL out of this to Bulk update attributes by SKU/UPC.
Running EE1.10 FYI
I have all the rest of the code working but I"m not sure the who/what/why of
actually updating our attributes, and haven't been able to find them, my logic
is
Open a CSV and grab all skus and associated attrib into a 2d array
Parse the SKU into an entity_id
Take the entity_id and the attribute and run updates until finished
Take the rest of the day of since its Friday
Here's my (almost finished) code, I would GREATLY appreciate some help.
/**
* FUNCTION: updateAttrib
*
* REQS: $db_magento
* Session resource
*
* REQS: entity_id
* Product entity value
*
* REQS: $attrib
* Attribute to alter
*
*/
See my response for working production code. Hope this helps someone in the Magento community.
While this may technically work, the code you have written is just about the last way you should do this.
In Magento, you really should be using the models provided by the code and not write database queries on your own.
In your case, if you need to update attributes for 1 or many products, there is a way for you to do that very quickly (and pretty safely).
If you look in: /app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php you will find that this controller is dedicated to updating multiple products quickly.
If you look in the saveAction() function you will find the following line of code:
Mage::getSingleton('catalog/product_action')
->updateAttributes($this->_getHelper()->getProductIds(), $attributesData, $storeId);
This code is responsible for updating all the product IDs you want, only the changed attributes for any single store at a time.
The first parameter is basically an array of Product IDs. If you only want to update a single product, just put it in an array.
The second parameter is an array that contains the attributes you want to update for the given products. For example if you wanted to update price to $10 and weight to 5, you would pass the following array:
array('price' => 10.00, 'weight' => 5)
Then finally, the third and final attribute is the store ID you want these updates to happen to. Most likely this number will either be 1 or 0.
I would play around with this function call and use this instead of writing and maintaining your own database queries.
General Update Query will be like:
UPDATE
catalog_product_entity_[backend_type] cpex
SET
cpex.value = ?
WHERE cpex.attribute_id = ?
AND cpex.entity_id = ?
In order to find the [backend_type] associated with the attribute:
SELECT
  backend_type
FROM
  eav_attribute
WHERE entity_type_id =
  (SELECT
    entity_type_id
  FROM
    eav_entity_type
  WHERE entity_type_code = 'catalog_product')
AND attribute_id = ?
You can get more info from the following blog article:
http://www.blog.magepsycho.com/magento-eav-structure-role-of-eav_attributes-backend_type-field/
Hope this helps you.