[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding a sales invoice



One more point:  looks like person__get_my_entity_id() is being called to retrieve the person_id.  The function makes this call:

SELECT entity_id from users where username = SESSION_USER;

If you are running a database tool like PgAdmin, you may be connected as the postgres user, which probably doesn't have a corresponding row in the users table.  As a workaround, I've modified the function to add a default person_id to the defaults table and then select it if the initial select does not return any rows.

-- Function: person__get_my_entity_id()

-- DROP FUNCTION person__get_my_entity_id();

CREATE OR REPLACE FUNCTION person__get_my_entity_id()
  RETURNS integer AS
$BODY$
--insert a default person ID if it does not exist

INSERT INTO defaults (setting_key, value)
SELECT 'default_person_id', 1
WHERE NOT EXISTS (SELECT 1 FROM defaults WHERE setting_key = 'default_person_id');

--select entity ID based on current user or default person_id if null
SELECT entity_id FROM
(
    SELECT entity_id, 1 as seq
    FROM users
    WHERE username = SESSION_USER
    UNION
    SELECT (SELECT value::integer FROM defaults WHERE setting_key = 'default_person_id'), 2 as seq
    ORDER BY seq
    LIMIT 1
) A
$BODY$
  LANGUAGE sql VOLATILE
  COST 100;
ALTER FUNCTION person__get_my_entity_id()
  OWNER TO postgres;
COMMENT ON FUNCTION person__get_my_entity_id() IS ' Returns the entity_id of the current, logged in user.';


Thanks.
Brian

Activus Technologies
Brian Wolf
Phone: 410.367.2958
Email: ..hidden..
  • LedgerSMB Accounting Software Integrated with Amazon Marketplace
  • Integrated Payment Solutions
On 09/03/2013 09:34 AM, Brian Wolf wrote:
When adding a sales invoice, a row is added to the AR table.  One of the columns to set is person_id.
Which person is that referring to?  Should that be set to the current user's ID? 
Or, perhaps the current user's entity ID?
        ar.person_id = user.entity_id

Thanks.
Brian

Activus Technologies
Brian Wolf
Phone: 410.367.2958
Email: ..hidden..
  • LedgerSMB Accounting Software Integrated with Amazon Marketplace
  • Integrated Payment Solutions


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk


_______________________________________________
Ledger-smb-devel mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-devel