get purchase order field value automatically from sale order - odoo

I am new to openerp v7, I want to automatically get the value of a field (a field which I have created) in a purchase order. Considering:
in both sale order and purchase order form I have created the field and displayed it
All my products have Procurement Method - make to order and I use run schedulers to convert sale orders to purchase orders automatically
How do I get the value of the custom field in the purchase order directly from the sale order?
Any kind of help would be much appreciated.

Related

How to add constraints to make sure a customer can only purchase a certain number of product - Postgresql

I am trying to write a Check to make sure that a customer can only buy 10 of a certain product type (smartphone) and 4 of another product type(tv), and buy another product only during morning(before 12:30). The table is
invoice(PK invoice_no, FK product, amount, customer_name,time, FK opening_time )
Check (amount >10) would check the amount but I want to limit only a few types of products. Also product type isn't in my invoice table, should I add that to the table or can I join another table (Product) in check?
I guess this kind of validation / restriction is better fit to your application's business level rather then your data / database level

Creating inventory database when product unit price change frequently

I am working on this project that involve sales management. I have the schema below. I have a situation where unit price change frequently. I want to prevent product duplicate in the PRODUCT MASTER table.Also, there I will be finding monthly profit by subtracting unit price from sales price. Please I need assistance on how to update prices and make sure old unit price is associated with old products purchased and new unit price is associated with new products. Thanks.
Offhand, I can think of two ways to do this:
If old prices are important only to know the profit in a given time period:
Product master should contains the current price
Add another field to Purchase order details for the unit price at the time of the order.
When you add a record to Purchase order details, copy the current price from Produce master to Purchase order details.
Update the price in Product master whenever you need to.
If you want to track old prices, even if no items were ordered with that price:
Remove the price fields from Product master
Add a new table, for price updates. This will have three fields:
product ID
date/time on which the price was changed
the new price
When you want to calculate price for a given Purchase order details, look in this new table. Find the latest record that is earlier (has a smaller date/time for the price change) than the [Purchase order].[order date].
When you want to update the price, add a record to this new table.

Identify product in invoice with unique id - Xero API

I'm trying to import invoices from xero account using the Xero API in c#. LineItems collection in invoice object represents the invoice items which are part of invoice. I want to identify products in invoice with unique Id e.g.
Invoice1 has 2 line items say P1 and P2. Sameway, Invoice2 has 2 line items again say P1 and P2. While I iterate through the collection of invoices, I want to identify product P1 and P2 with unique Id and store them in my database. Then during the iteration loop, whenever I encounter P1/P2 item, I should know that these product has already been stored to database with unique id and no need to save these products again as it has already been stored.
I thought LineItemId and ItemCode might help but LineItemId is new Id generated every time and I noticed that Itemcode is null many times. So is there any way to assign unique product id to line items?
Thanks for help,
LineItemId is a unique ID per line item per invoice, nothing to do with the product so that's not what you want.
If ItemCode is missing or null, this means that the product is not saved in the Xero product database and has just been added as a "once off", and in theory it will never be seen again. So there is just no way to identify a product that doesn't exist. If these items really aren't just "once off" then they should be added to the database and given an ItemCode. So the problem is the way Xero is being used.
Once it is added as an Item, you can use the Items endpoint (/api.xro/2.0/Items) to also grab the ItemID which is a GUID and should be used to store in your database with the ItemCode.

Creating a Scalar Function in SQL-Server To get Stock Preview

So I'm having trouble creating a function to get a Preview of the stock of a product.
Simplified Model explanation:
My database has a table of Products, Sales and Orders, and I need to create a function that receives as parameter the Product's NumberID and a date, and return the preview stock on that specific date.
Basically if I have in store 5 bottles, and have an order for tomorrow of 3 bottles, given the 'day after tomorrow' date, then the Stock Preview will be 2.
My problem is, given a date before the current one, I think I'll need to go and see the sales between that date and now and add them to the preview right? and only after that I'll check the orders table.
I've been using many if's and cursors and it's driving me crazy

Database design for a shop issue: storing changeable price

I am new to database design.
I have an assignment to design a relational database for a company that has 3 shops that fulfills these requirements:
1) A product has an ID, quantity, price and new product can be added.
2) Each shop has a name, and an ID
3) Do NOT create tables that store products of each shop, but only a "History" table that has a "status" attribute that keeps track of transaction history only (IN: add new product, OUT: check out product). Each transaction has a productID, "status", quantity check (in/out), history (timestamp), shopID. Manager only needs to make query to see each shop's current stocks of the products. Datasets should be like this:
(barcode is just replaced with productID)
4) Price: design a table structure for the price such that:
a) Price can be changed. When a price changes, there should be a method to keep track with the history and the old value of the price changes. Manager can make query to see when the price was changed and how much the old price was.
b) Discount: a discount of a particular product in a particular shop can have a discount value. For example in that week the new shop is open, its product A has a discount B% during that week.
c) Manager should be able to make a query to retrieve data of the total revenue.
I was given the first 3 tasks to design last week, and this week the fourth requirement came up and I need to change the design accordingly. How can I change my design to cope with the last requirement? Thank you.
My current design for the first 3 requirements: