Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Business Central forum

Copy Unit Cost from Sales Order to Purchase Order

(0) ShareShare
ReportReport
Posted on by 326

Hello, 

Is it possible to have the unit cost for an item on a sales order automatically copy to the unit cost field on a purchase order? When I create a PO the Unit Cost shows up as $0.00 even though I specified a unit cost on the sales order. Our sales team researches cost ahead of time to determine which distributor has the best cost/availability before the order is sent through to our purchasing team. It would be great if purchasing could create a PO and the cost from the SO would automatically get copied over per item.

Thanks!

Categories:
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Copy Unit Cost from Sales Order to Purchase Order

    In this code, SalesLine is not filtered, so the code is wrong. You need to retrive the SalesLine linked to your Purchase Line (Rec), so here it’s missing something like:

    SalesLine.SETRANGE(“Document Type”,SalesLine.”Document Type”::Order);

    SalesLine.SETRANGE(“Purchase Order No”,Rec.”Document No.”);

    SalesLine.SETRANGE(“Purchase Order Line No”,Rec.”Line No.”);

    IF SalesLine.FINDFIRST THEN

     Rec."Unit Cost" := SalesLine."Unit Cost";

    Note that I’m not sure if the fields that link a Sales Line to a Purchase Line in your system are the two fields mentioned above, but it’s just to give you an idea.

  • dkkipfer Profile Picture
    326 on at
    RE: Copy Unit Cost from Sales Order to Purchase Order

    Hi Stefano,

    The part I'm having trouble with now is filtering the values down so I'm grabbing the value from the correct line.

    Here's what I have written so far. I'm trying to get the system to update the unit cost on the purchase line to match the unit cost of the sale line it was created from. 

    [EventSubscriber(ObjectType::Table, Database::"Purchase Line", 'OnAfterInsertEvent', '', false, false)]
        local procedure CopyUnitCostFromSalesOrderAfterInsert(var Rec: Record "Purchase Line")
        var
            SalesLine: Record "Sales Line";
        begin
            Rec."Unit Cost" := SalesLine."Unit Cost";
        end;


  • dkkipfer Profile Picture
    326 on at
    RE: Copy Unit Cost from Sales Order to Purchase Order

    It's not critical, but sure would be great to have to eliminate manual entry. I'm happy to put in the time to learn how to accomplish it, but would need some guidance as to how to pass the values from the sales order to the purchase order via an extension.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Copy Unit Cost from Sales Order to Purchase Order

    Just an idea of a possible solution: create an extension with a codeunit and an eventsubscriber to the OnAfterValidate event of the UNit Cost field in the Sales Line table.

    From this event, you can filter the Purchase Line table (I don't know what are your criteria) and update the Unit Cost of that record accordingly.

    Just few lines of code :)

  • Adam Shilton Profile Picture
    460 on at
    RE: Copy Unit Cost from Sales Order to Purchase Order

    [quote][/quote]

    Sales price and purchase cost are not the same. Because of our ordering process, we list the item's cost AND sales price on a sales order. This lets our purchasing department know what the cost of the item should be when they send the PO to the vendor. The cost changes frequently due to negotiated pricing and promotions or specials that a particular vendor might be running. Ideally, that cost would flow through to the purchase order from the sales order automatically rather than relying on the cost from the item card or from previous purchases of that item. Please let me know if that makes sense.

    For picking the vendor, is it possible to specify this on the sales order line item instead of in the intermediate step?  

    I now understand what you're saying so thanks for that. As standard, you can't add the vendor no. to the order line using the in-app designer, so you wouldn't be able to do it without specialist configuration. Happy to further the discussion on how we could help you do this. I suppose it just depends how much of an issue it is for you?

  • dkkipfer Profile Picture
    326 on at
    RE: Copy Unit Cost from Sales Order to Purchase Order

    Thanks, Stefano! How simple of an extension would this be? Can you provide an example of what this might look like in VS Code?

  • dkkipfer Profile Picture
    326 on at
    RE: Copy Unit Cost from Sales Order to Purchase Order

    Sales price and purchase cost are not the same. Because of our ordering process, we list the item's cost AND sales price on a sales order. This lets our purchasing department know what the cost of the item should be when they send the PO to the vendor. The cost changes frequently due to negotiated pricing and promotions or specials that a particular vendor might be running. Ideally, that cost would flow through to the purchase order from the sales order automatically rather than relying on the cost from the item card or from previous purchases of that item. Please let me know if that makes sense.

    For picking the vendor, is it possible to specify this on the sales order line item instead of in the intermediate step?  

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Copy Unit Cost from Sales Order to Purchase Order

    The Unit Cost in a Purchase Order comes from the Purchase Price table (if exists). This is the cost defined by the vendor. For overriding it from a sales order you can create a simple extension that validates the purchase line unit cost starting from the sales line cost (quite simple).

  • Suggested answer
    Adam Shilton Profile Picture
    460 on at
    RE: Copy Unit Cost from Sales Order to Purchase Order

    Hi, there's a way that you can easily create a purchase document from a Sales order whilst at the same time choosing the supplier that you want to purchase the goods from. I think we need some clarification though as I don't understand why your sales price and your purchase cost would be the same? If this is the case then you won't be making any profit. I've included some screenshots below on how to create a purchase order from a sales order.

    1. Open your sales order
    2. Click on the actions tab and choose 'create purchase document' and create a purchase order
    3. Choose the supplier (Vendor) you want to use for each item and click ok

    [Note - Cost will automatically be pulled through to the purchase order based on the default cost of the item within the item card. The other option is to create Vendor specific pricing per item so that the cost of the goods will be relevant to that Vendor.

    Hope this helps...

    Choose-Vendor.png

    Choose-Vendor.png

    Item-Prices.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans