I've noticed that the product revenue shows incorrect values.
Example:
The user buys
3000 HUF item (qty: 2)
The total is 6000 HUF
The user refunds one item
So -3000 HUF
The revenue should be 3000 now, but it is still 6000... what do I do wrong?
You see, the Product Refund Amount is correct, but the Product Revenue is not:
My refund code:
gtag('event', 'refund', {
'transaction_id': 'ID',
'value': "3000",
'currency': 'HUF',
'items': [{
'id': '01',
'name': 'PRINGLES',
'quantity': 1,
'price': '3000',
}]
});
This is also the same case as when I refund a whole order.
I believe in financial terms 'revenue' (or 'total revenue') is the total of sales, including the amount that was refunded. What you're looking for is the 'net revenue', which is not directly available in GA sales performance report.
You'll need to create a calculated metric where you subtract the refund amount from product revenue. Here is the documentation: https://support.google.com/analytics/answer/6121409?hl=en
Related
I'm trying to return rows that meet the criteria of either a HAVING clause, or a secondary condition outside of it. I'm not sure how to work this logic into the same SELECT statement. I'm using Microsoft SQL Server 2008.
Let's say I have one table that has information about some products, and a second table that has information about the sales figures for these products. I want to select all blue-colored products that have either sold 500+ units OR were first launched in 2020, regardless of the sales numbers.
The former is captured by a HAVING clause that sums up some values that represent sales figures. If, however, this clause returns false, I want the product to still be included in the returned rows if the product launch year is "2020".
By this logic, I would expect all of the following products to be included in the results, because they meet at least 1 of the conditions:
{"name" => "toaster", "total_sales" => 525, "launch_year" => 2010} # meets the "500+ units sold" condition
{"name" => "oven", "total_sales" => 100, "launch_year" => 2020} # meets the "product was launched in 2020" condition
{"name" => "fridge", "total_sales" => 600, "launch_year" => 2020} # meets both conditions
but I would not expect the following products to be included in the results, because they meet neither of the conditions:
{"name" => "couch","total_sales" => 50, "launch_year" => 1990} # does not meet either condition (<500 units sold, and product not launched in 2020)
{"name" => "chair", "total_sales" => 499, "launch_year" => 2019} # does not meet either condition (<500 units sold, and product not launched in 2020)
This is the query itself, although it won't execute successfully:
SELECT product.name, product.launch_year, (SUM(sales.units_sold)) as total_sales
FROM product_info as product
LEFT JOIN price_data as sales on product.id = sales.id
WHERE product.color = 'blue'
GROUP BY product.name, product.launch_year
HAVING (SUM(sales.units_sold)) >= 500 OR product.launch_year = '2020'
The OR condition at the very end returns an invalid column name '2020' error, as it is syntactically incorrect. However, it represents the logic I am trying to achieve. Is it possible to incorporate this kind of conditional situation into the HAVING clause? Or must they exist in two separate SELECT statements? Or is there a completely different way to go about doing this?
I've checked for other answers on here, but I've only seen instances where a comparison of the same type was made within a HAVING clause, as opposed to a comparison between the HAVING clause and a completely separate condition.
Use case: on this site, users will be able to go on and select rental property for a specific amount of days. Users will be often be selling the same type of rental property.
Problem: Because multiple "sellers" will be renting out the same exact item, the "property detail page" will have many listings created by many different sellers (or in some case, a seller will have multiple properties available falling into the same "property detail page"). Each of these "listings" objects will have many pricing objects which contain a date, a price, and an availability boolean.
Current models are broken down below:
property.rb
has_many :listings
has_many :prices, :through => :listings
listing.rb
belongs_to :user
belongs_to :property
has_many :prices
price.rb
belongs_to :listing
What I have tried:
If for example, I wanted to obtain the MINIMUM sum of pricing for a specific property, I had jotted down this:
# property.rb
# minimum price for a pricing set out of all of the price objects
def minimum_price(start_date, end_date)
# this would sum up each days pricing to give the rental period a final price
prices = self.prices.where("day <= ?", end_date).where("day >= ?", start_date).sum(:price)
end
When I do it like this however, it simply combines every single users prices giving nothing of use.
Any help would be greatly appreciated! Of course I could loop through a properties listings until I found a minimum price set for a given date range, but that seems as though it would take an unnecessary amount of time and be largely inefficient.
EDIT
An example of data that should be outputted is a set of price objects that are the cheapest ones in a specific date range from ONE particular listing. It can not just combine all of the best priced dates from all of the users and add them as the buyer will be renting from ONE seller.
This is an actual example of desired output, as you can see these prices are ALL from the same listing ID.
[#<Price id: 156, day: "2020-12-01", listing_id: 7, price: 5.0, available: true, created_at: "2020-12-17 14:22:46", updated_at: "2020-12-17 14:22:46">, #<Price id: 157, day: "2020-12-02", listing_id: 7, price: 5.0, available: true, created_at: "2020-12-17 14:22:46", updated_at: "2020-12-17 14:22:46">, #<Price id: 158, day: "2020-12-03", listing_id: 7, price: 5.0, available: true, created_at: "2020-12-17 14:22:46", updated_at: "2020-12-17 14:22:46">, #<Price id: 159, day: "2020-12-04", listing_id: 7, price: 5.0, available: true, created_at: "2020-12-17 14:22:46", updated_at: "2020-12-17 14:22:46">]
So it sounds like you are calling this on a property so:
prices = self.prices.where("prices.day >= ? AND prices.day <= ?", start_date, end_date).sum(:price).group_by {|price| price.listing_id}
There is probably a SQL based way that you can use AR relations to do this. But this will give you a hash with a key for each listing_id and the value of that key should be the sum. I say "should" because this is a bit abstract for me to do without a system to test it on.
I am trying to get a freight total to show on the bottom of my invoices. I created a new field in the Accounting Module called "Freight Total" (x_studio_freight_total). I want to get the sum of the "Subtotal" (price_subtotal) for any instance where the "Product" (product_id) = "FREIGHT".
For the field, x_studio_freight_total, I set the Dependencies as: "invoice_line_ids.price_subtotal, invoice_line_ids.product_id"
I set the Compute property as:
for record in self:
if(record.invoice_line_ids.product_id == "FREIGHT):
record['x_studio_freight_total'] = sum(record.invoice_line_ids.price_subtotal)
If an invoice shows a line with a 'Product' named "FREIGHT", and a 'Subtotal' of "12.75" I expect my 'Freight Total' field to display "12.75".
If an invoice has two lines with 'Product' named "FREIGHT, one with a 'Subtotal' of "12.75" and the other with a 'Subtotal' of "7.50", I expect the 'Freight Total' field to display "20.25".
But it currently is not displaying anything just "0.00"
Try using this code
for record in self:
record['x_studio_freight_total'] = 0
for line in record.invoice_line_ids:
if(line.product_id.name == "FREIGHT): #product_id.name to search product name
record['x_studio_freight_total'] += line.price_subtotal`
I would like to do a promotion in Virto Commerce on the cart. In my example i would like to discount the cart with 200 SEK if the customer buys for at least 800 SEK, the VAT/GST in my example is 25%.
This is the effect I'm looking for:
Cart
subTotal: 640
subTotalWithTax: 800
discountAmount: 160
discountTotalWithTax: 200
total: 480
totalWithTax: 600
As far as i can tell the Marketing Module only supports promotions where the discount is applied before taxes. Se comment in storefront code:
ShoppingCart.cs#L390
foreach (var reward in cartRewards)
{
//When a discount is applied to the cart subtotal, the tax calculation has already been applied, and is reflected in the tax subtotal.
//Therefore, a discount applying to the cart subtotal will occur after tax.
//For instance, if the cart subtotal is $100, and $15 is the tax subtotal, a cart - wide discount of 10 % will yield a total of $105($100 subtotal – $10 discount + $15 tax on the original $100).
if (reward.IsValid)
{
var discount = reward.ToDiscountModel(ExtendedPriceTotal);
Discounts.Add(discount);
DiscountAmount = discount.Amount;
}
}
I guess this is a common practice in some markets. But as this is for a B2C solution in Sweden. An advertised discount of 200 SEK on a 800 SEK cart should render a customer facing total price of 600 SEK including taxes.
This is an img of my promotion in the Marketing Module
This gives me the following on the Cart JSON
Cart
subTotal: 640
subTotalWithTax: 800
discountAmount: 160
discountTotal: 160
discountTotalWithTax: 160
subTotalDiscount: 0
subTotalDiscountWithTax:0
discountTotalWithTax: 160
taxTotal: 160
total: 640
totalWithTax: 800 (Calculated. Not in standard JSON response)
So either I've miss configured the promotion or my implementation of the storefront code for promotions is lacking in some way.
Currently, VC implement only the one discount to the order subtotal policy:
When a discount is applied to the cart subtotal, the tax calculation
has already been applied, and is reflected in the tax subtotal.
Therefore, a discount applying to the cart subtotal will occur after
tax. For instance, if the cart subtotal is $100, and $15 is the tax
subtotal, a cart-wide discount of 10% will yield a total of $105 ($100
subtotal – $10 discount + $15 tax on the original $100).
But we are working on change the totals calculation to make this process more flexible and extensible for supporting any calculation policies.
You can achieve what you want by a little customization within your extension module:
Extend ShopingCart class with following code
public class ShopingCart2: ShoppingCart
{
public decimal DiscountAmountWithTax
{
get
{
return DiscountAmount + DiscountAmount * TaxPercentRate;
}
}
public override decimal TaxTotal
{
get
{
var result = base.TaxTotal;
result -= DiscountAmountWithTax - DiscountAmount;
return result;
}
}
public override decimal DiscountTotalWithTax
{
get
{
var result = base.DiscountTotalWithTax;
result += DiscountAmountWithTax - DiscountAmount;
return result;
}
}
}
Extend domain CustomerOrder type with the same code as for ShoppingCart above
Register your ShoopingCart2 and CustomerOrder2 in AbstractTypeFactory
AbstractTypeFactory<ShoppingCart>.OverrideType<ShoppingCart, ShoppingCart2>();
AbstractTypeFactory<CustomerOrder>.OverrideType<CustomerOrder, CustomerOrder2>();
Update your storefront to latest version from dev (this commit required for normal work https://github.com/VirtoCommerce/vc-storefront/commit/2464548c171c811a9d63edba0bdf6af93e8c902b)
Modify ShopingCart class in your storefront - add same changes as you made in your new ShoppingCart2 type earlier.
Get the desired behavior
I have created a custom entity that lets us select a sales order. The desire is that when a sales order is selected, it should show a list of manufacturing orders linked to that sales order.
How to go about getting this in place? And what should be in the mode? fields.related or fields.one2many?
Thanks
code:
class my_custom(osv.osv):
_name = 'mrp.mycustom'
_columns={
'name': fields.char('Name',size=64),
'salesorder_id': fields.many2one('sale.order','Sales Order')
}
my_custom()
There is no direct link between sale order and manufacturing order. You need to add a link first.then you you can use a one2many to show your manufacturing order