ODOO Pricelist | How to set the base price PUBLIC PRICE to not get modified based on the discount applied.? - list

I'm using the ODOO pricelist for sales.order and invoice. The issue i'm facing is : I create a PRICELIST, and add PRODUCT-X with a rule of NEW PRICE = BASE PRICE(PUBLIC PRICE) x (23%) where the Product's Sale Price in Warehouse is set to let's say 770 and the discount is 23 percent - The discount gets applied to 770 the first time = 592.9- then once the product is added for a second time the 770 is no longer used as a base price, but the 592.9 is used and a 23 percent discount is applied and so forth...
So we have non-stable PRODUCT_X Public Price.
Please view the image below to get a clear picture of what goes on, i want the PUBLIC PRICE to not change automatically... If someone could give me advice, or if there's any module out there on the Odoo apps..
**NOTE IN THE IMAGE BELOW: the PRIX PUBLIC field is French for LIST PRICE
& the REMISE field is DISCOUNT
Now at the end we will have a look at the Product's PUBLIC PRICE and it will be 351.53 instead of 770 (we set at the beginning).
Thanks alot,

PROBLEM SOLVED
I removed this code in my sale_order.py
product_obj = self.pool.get('product.product')
if 'price_unit' in vals:
for this in self.browse(cr,uid,ids,context):
if this.product_id:
price_unit = vals.get('price_unit',0.0)
if this.product_id.lst_price != price_unit:
product_obj.write(cr,uid,[this.product_id.id],{'lst_price':price_unit})
It was making the PUBLIC PRICE updated from the order line for every addition.
Thanks #CZoellner for your valuable help - a reminder that the process wasn't running normally.

Related

Regarding the product price that goes into the cart along with the product

In backend admin panel following these steps: Catalog -> Products -> (I select the product I need) -> Edit -> Special. I insert the special price I want and it displays in Frond End in the product page. The Price which is in Data appears as CUT and the price I inserted in Special appears uncut. For example: [strike] 100.00[/strike] 90.00. My main question is: When I click Add to cart in the product page I want the the main price to go in the cart not the Special one. The client wants to see the special price but the price that goes into the cart to be the main price.
Many thanks
Special Price is actually the discounted price of a product. So, if a product is of 100 then we can sell it for 90 on some festival seasons. That's when you should use special price. Regarding your specific requirement, you should either flip the values entered in special and base price (But the special price will now have strikethrough) OR you need to alter the code.

Inventory design management - FIFO / Weighted Average design which also needs historical inventory value

I have a database with the following details:
Product
Name
SKU
UOM (There is a UOM master, so all purchase and sales are converted to base uom and stored in the db)
Some other details
has_attribute
has_batch
Attributes
Name
Details/Remarks
Product-Attribute
Product (FK)
Attribute(FK)
Value of attribute
Inventory Details
#This is added for every product lot bought & quantity available is updated after every sale
Product (FK)
Warehouse (FK to warehoue model)
Purchase Date
Purchase Price
MRP
Tentative sales price
Quantity_bought
Quantity_available
Other batch details if applicable(batch id, manufactured_date, expiry_date)
Inventory Ledger
#This table records all in & out movement of inventory
Product
Warehouse (FK to warehoue model)
Transaction Type (Purchase/Sales)
Quantity_transacted(i.e. quantity purchased/sold)
Inventory_Purchase_cost(So as to calculate inventory valuation)
Now, my problem is:
I need to find out the historical inventory cost. For example, let's say I need to find out the value of inventory on 10th Feb 2017, what I'll be doing with the current table is not very efficient: I'll find out current inventory and go back through the ledger for all 1000-1500 SKU and about 100 transactions daily (for each sku) for more than 120 days and come to a value. taht's about 1500*100*120. It's Huge. Is there a better DB design to handle this case?
Firstly, have you tested it? 1500*100*120 is not that huge. It may be acceptable performance and there is no problem to be solved!
I'm not 100% clear how you compute the value. Do you sum up the InventoryLedger rows for each Product in each Warehouse? Is so, it's easy to put a value on the purchases, but how do you value the sales? I'm going to assume that you value the sales using the Inventory_Purchase_Cost (so it should maybe be called TransactionValue instead).
If you must optimise it, I suggest you could populate a record each day for the valuation of the product in each warehouse. I suggest the following StockValution table could be populated daily and this would allow quick computation of the valuations for any historical day.
Diagram made using QuickDBD, where I work.

Unable to display exact price in opencart

I am new to opencart. I am trying to set the price in admin part but It is not showing as I set in dashboard. It is showing something less than(5% less) the what I entered in admin.
I have set the price of two products in dashboard :
But when I see the product as follow on the front end :
I have set display price tax in opencart setting as follow
Check your currencies are correct in System - Localisation - Currencies
you currency should be set as default and with a value of 1.0000

How to create custom shipping costs - Spree

What I have is a website which has multiple different user roles. Normally there is just admin and user. I have multiple for different users (retail, trade etc).
What the client is wanting, is that each product has a seperate shipping cost. The actual costs differ for users (so trade shipping might be $8 where retail would be $10). If multiple products are selected, there will be 100% shipping on the first product, and 50% for each additional product. This price differs based on the customers shipping location. It also differs based on what category the item is (eg. They have a seats category and a fish box category. The seats category might be $15 and the fish box might be $17.
The way I'm thinking is that each category has its own shipping category and then the shipping methods are just the locations. This would work fine but the tricky part is how to adjust this based on what user is logged in. The prices I have been given are consistent with the difference between retail shipping and trade shipping (Trade shipping is always 80% of retail shipping).
Basically, what would be great is if I could find out where the shipping calculation is done. That way I can test if the user is a trade customer and change the value to actually be value * .80, else the value is normal.
If any of you could spare the time to help me out with this I would be most appreciative.
Basically, what would be great is if I could find out where the
shipping calculation is done.
Calculations are done in Spree::Calculator::Shipping classes (FlatRate, 'PerItem`, etc.) - check the source.
You probably want custom calculator (or decorate existing method), so add file in models/spree/calculator/shipping/my_custom_method.rb:
module Spree
module Calculator::Shipping
class MyCustomMethod < ShippingCalculator
preference :amount, :decimal, default: 0
preference :something_i_need, :string, default: :foo #and so on, those preferences will be ready to set/change in admin panel
def self.description
Spree.t(:my_custom_method) # just a label
end
# here is where magic happens
def compute_package(package)
package.order.shipment_total
end
end
end
end
As you can see method compute_package is being called on package object which has several useful methods (source) but you can call directly package.order to get all line_items, shipments, order's user and all things you need to calculate valid amount.
If you want to create new method don't forget to register it so it will appear in admin panel so you can change settings - of course you can do that programatically if you want:
initializers/shipping_methods.rb:
Rails.application.config.spree.calculators.shipping_methods << Spree::Calculator::Shipping::MyCustomMethod
Ok this is what I have so far.
In app/models/spree/calculator/shipping/per_item.rb
(Spree standard model which I copied from \vendor\bundle\ruby\1.9.1\gems\spree_core-2.4.7\app\models\spree\calculator\shipping\per_item.rb)
require_dependency spree/shipping_calculator
module Spree
module Calculator::Shipping
class PerItem < ShippingCalculator
preference :amount, :decimal, default: 0
preference :currency, :string, default: ->{ Spree::Config[:currency] }
def self.description
Spree.t(:shipping_flat_rate_per_item)
end
def compute_package(package)
if package.contents.sum(&:quantity) > 1
compute_from_multiple(package.contents.sum(&:quantity))
else
compute_from_single(package.contents.sum(&:quantity))
end
end
def compute_from_multiple(quantity)
(self.preferred_amount / 2) + ((self.preferred_amount * quantity) / 2
end
def compute_from_single(quantity)
self.preferred_amount * quantity
end
end
This will test the number of items in the cart and if there are more than 1, it will give one item 100% shipping and the rest 50%.
What I now can't figure out is how to access the current user.
eg.
if current_spree_user.has_spree_role?("admin")
(self.preferred_amount / 2) + ((self.preferred_amount * quantity) / 2)
else
((self.preferred_amount / 2) + ((self.preferred_amount * quantity) / 2)) * 0.87
end
This gives an error:
undefined local variable or method `spree_current_user'
Does anyone know how to check for the current user in a model???

Query for a ManytoMany Field with Through in Django

I have a models in Django that are something like this:
class Classification(models.Model):
name = models.CharField(choices=class_choices)
...
class Activity(models.Model):
name = models.CharField(max_length=300)
fee = models.ManyToManyField(Classification, through='Fee')
...
class Fee(models.Model):
activity = models.ForeignKey(Activity)
class = models.ForeignKey(Classification)
early_fee = models.IntegerField(decimal_places=2, max_digits=10)
regular_fee = models.IntegerField(decimal_places=2, max_digits=10)
The idea being that there will be a set of fees associated with each Activity and Classification pair. Classification is like Student, Staff, etc.
I know that part works right.
Then in my application, I query for a set of Activities with:
activities = Activity.objects.filter(...)
Which returns a list of activities. I need to display in my template that list of Activities with their Fees. Something like this:
Activity Name
Student Early Price - $4
Student Regular Price - $5
Staff Early Price - $6
Staff Regular Price - $8
But I don't know of an easy way to get this info without a specific get query of the Fees object for each activity/class pair.
I hoped this would work:
activity.fee.all()
But that just returns the Classification Object. Is there a way to get the Fee Object Data for the Pair via the Activities I already queried?
Or am I doing this completely wrong?
Considering michuk's tip to rename "fee" to "classification":
Default name for Fee objects on Activity model will be fee_set. So in order to get your prices, do this:
for a in Activity.objects.all():
a.fee_set.all() #gets you all fees for activity
There's one thing though, as you can see you'll end up doing 1 SELECT on each activity object for fees, there are some apps that can help with that, for example, django-batch-select does only 2 queries in this case.
First of all I think you named your field wrong. This:
fee = models.ManyToManyField(Classification, through='Fee')
should be rather that:
classifications = models.ManyToManyField(Classification, through='Fee')
as ManyToManyField refers to a list of related objects.
In general ManyToManyField, AFAIK, is only a django shortcut to enable easy fetching of all related objects (Classification in your case), with the association table being transparent to the model. What you want is the association table (Fee in your case) not being transparent.
So what I would do is to remove the ManyToManyField field from Activity and simply get all the fees related with the activity. And thenm if you need a Classification for each fee, get the Classification separately.