Odoo Hilfe


9 Answers

Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 8 9 10
Ahmedabad, Indien
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




ERP Harbor Consulting Services

Website: http://www.erpharbor.com
Sudhir Arya (ERP Harbor Consulting Services)
26.12.18, 06:50

Hi Donald,

You would need to create a custom module for that, override the "_prepare_invoice_line" method and pass the value of the Purchase Date field of Sales Order Line.

Add following code in your custom module:

class SaleOrderLine(models.Model)
_inherit = 'sale.order.line'

def _prepare_invoice_line(self):
inv_line_vals = super(SaleOrderLine, self)._prepare_invoice_line()
inv_line_vals.update({'pur_date': self.pur_date})
return inv_line_vals

Let me know if you need any guidance in custom module.

Sudhir Arya
ERP Harbor Consulting Services
Website: http://www.erpharbor.com

Donald Leaman
26.12.18, 12:01

Thanks for the advice Sidhir. I will research how to do it and give it a try. But I was also thinking about adding the field to the corresponding models for invoices and purchases and using the PGADMIN app to add triggers to my new field in the sale.order.line table so that when it is updated the new field in the invoice and purchase line models would also be updated with the same value. I'm not thinking of defining any constraint though. What do you think? Could this work?

Donald Leaman
26.12.18, 20:30

Sorry, I meant put triggers in the corresponding new fields in purchase order line and invoice line.

Sudhir Arya (ERP Harbor Consulting Services)
27.12.18, 00:40

Yes that would be fine if you can make it work like that. But if you create a custom module, you can use that feature in any database. You just need to install the module.

Donald Leaman
27.12.18, 10:52

Let me see if I got this right. You're saying I can modify an existing module by adding the code you specify? Which module (and where would I find it in my Ubuntu 16.04)? Then I create a new class in that module called SaleOrderLine and a new method called _prepare_invoice_line with the code you specified and the field you listed named 'pur_date' is actually the fields I created in sale.order.line and account.invoice.line? How do I "override" the "_prepare_invoice_line" method? Are you saying I simply rename the original module and give my edited module the original module name? If you could give me a step-by-step for what to do I'd really appreciate it. Thanks.

Sudhir Arya (ERP Harbor Consulting Services)
28.12.18, 01:58

Actually you would need to create your own custom module and add the code I have posted in the answer. You should not change the code in the base modules.

You can find many blogs / documents on how to create a custom module.

Donald Leaman
28.12.18, 10:24

And have you any suggestions for how to code trigger elements?

Donald Leaman
29.12.18, 21:35

Sudhir, I chose the trigger method.  Here's what I learned:  At first I put the trigger on the account_invoice_line table.  My initial logic was to use the sale_order_line_invoice_rel table to relate sale order line to invoice line.  I got the function and trigger coded successfully, but it did not copy the date.  I figured out why:  the row is not inserted into the sale_order_line_invoice_rel table until AFTER the account_invoice_line row is successfully inserted.  So I changed my function and trigger to operate on the sale_order_line_invoice_rel table.  Here's my code:

-- DROP FUNCTION public.set_invoice_line_date_of_service();

CREATE OR REPLACE FUNCTION public.set_invoice_line_date_of_service()
  RETURNS trigger AS
  xdateofservice date;
  xdateofservice := x_date_of_service from sale_order_line where id = NEW.order_line_id;
  update account_invoice_line
    SET x_date_of_service = xdateofservice WHERE id = NEW.invoice_line_id;
LANGUAGE plpgsql;

CREATE TRIGGER set_invoice_line_date_of_service
  ON public.sale_order_line_invoice_rel
  EXECUTE PROCEDURE set_invoice_line_date_of_service();

I suppose I didn't need the "RETURN NEW" statement.  Am i right?  In any event, our company is a service company and we wanted a field in the table to keep track of when the service was provided and we could put that info on the invoice line.  As you see my trigger does indeed do that.  I added the x_date_of_service field to sale_order_line and account_invoice_line models, and I added the field to sale.order.form and account.invoice.form.  When we verify with the vendor that the service is complete we enter the date.  Then when we invoice the customer at month end, each invoice line has the date when service was complete.

Next we want to do this same logic with vendors, since each service is provided by a sub-contractor.  It is a one-for-one relation between sales and purchases.  So each time we send a sub-contractor to a job we generate a purchase order.  At week end we generate the vendor bills, and each bill has line items for each job that vendor worked, and so we want to put the date of service on each line.  Odoo business model doesn't exactly fit our business model, so we are making it fit.

1 Kommentar
Donald Leaman
07.01.19, 09:03

PS: We've done it now for vendors, too. Now we need to figure out how to get it to show up on the PDFs that we either print/mail or email.

Fragen Sie
Keep Informed
1 Verfolger
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now