The factory putting 1000 grams instead of 1030 grams is a kind of cheating and is haraam. Cheating is a major sin, because the Prophet (blessings and peace of Allah be upon him) said: “Whoever deceives is not of me.” Narrated by Muslim (101).
It is not permissible for the worker to do that even if the owner of the factory instructs him to do it, because there is no obedience to any created being if it involves disobedience towards the Creator, because the Prophet (blessings and peace of Allah be upon him) said: “There is no obedience if it involves disobedience towards Allaah; obedience is only in that which is right and proper.” Narrated by al-Bukhaari (7257) and Muslim (1840). And he said: “There is no obedience to any created being if it involves disobedience towards Allah, may He be glorified and exalted.” Narrated by Ahmad (1089).
What is required is to advise the owner of the factory and remind him that cheating is haraam, as well as reminding him of the seriousness of consuming haraam wealth. If he responds, praise be to Allah, but if he persists it is not permissible for you to take part in that cheating. If you can do your work without being involved in haraam actions directly or helping in them, then it is permissible to stay until you find another job in which you will be free from sin and evil and keeping company with those who do it.
But if you cannot work without being directly involved in cheating, then it is not permissible to you to stay in the factory; rather you should give up the job and look for another job, and you will find one in sha Allah. Allah guarantees to the one who fears Him that He will grant him a way out and goodly provision. Allah, may He be exalted, says (interpretation of the meaning):
“And whosoever fears Allaah and keeps his duty to Him, He will make a way for him to get out (from every difficulty).
3. And He will provide him from (sources) he never could imagine. And whosoever puts his trust in Allaah, then He will suffice him. Verily, Allaah will accomplish his purpose. Indeed Allaah has set a measure for all things”
And the Prophet (blessings and peace of Allah be upon him) said: “You will never give up something, fearing Allah, may He be glorified and exalted, but Allah will give you something better than it.”
Narrated by Ahmad (20739); classed as saheeh by Shu‘ayb al-Arna’oot in Tahqeeq al-Musnad.
And Allah knows best.