On 17/10/10 17:18 +0200, Paul J Stevens wrote:
> Hi all,
> 
> I'm working on building a simple module ('contract') for periodically
> creating invoices (like the subscription module discussed earlier).
> 
> Everything is working beautifully now, except that I notice no taxes are
> added to the invoice lines, even though they are defined correctly on
> the product's categories, and 'use category taxes' are set to 'true'.
> 
> I'm guessing this has to do with the on_change machinery, but I unsure
> how to proceed.
> 
> I'm currently using code along these lines:
> 
>         ## create a new invoice
>         invoice = invoice_obj.create(dict(
>             company=contract.company.id,
>             type='out_invoice',
>             reference=contract.product.code or contract.product.name,
>             description=contract.description or contract.name,
>             state='draft',
>             currency=contract.company.currency.id,
>             journal=contract.journal.id,
>             account=contract.party.account_receivable.id,
>             payment_term=contract.payment_term.id or \
>                          contract.party.payment_term.id,
>             party=contract.party.id,
>             invoice_address=invoice_addr.id
>         ))
>         ## create invoice line
>         account = contract.account or \
>                 contract.product.account_revenue or \
>                 contract.product.category.account_revenue
> 
>         line = line_obj.create(dict(
>             type='line',
>             product=contract.product.id,
>             invoice=invoice,
>             description="%s (%s) %s - %s" % \
>                                         (contract.product.description or
>                                              contract.product.name,
>                                              contract.name,
>                                              last_date, next_date),
>             quantity=Decimal("%f" % \
>                         (contract.interval_quant * contract.quantity)),
>             account=account.id,
>             unit=contract.product.default_uom.id,
>             unit_price=contract.product.list_price,
>             contract=contract.id,
>         ))
> 
> 
> Do I need to really need to iterate over all fields of the invoice and
> invoiceline models to determine the on_change(_with) fields, and call
> those manually?

I don't think you should call all the on_change because on_change are a
typical GUI behavior. But in some cases, it could be easier and prevent
duplicate the code.
In your case, you can call the on_change_product or use the
product.customer_taxes_used and call the tax rule apply.


> If so, is there a specific reason this kind of
> functionality isn't part of the framework proper?

Yes it is because it is GUI behavior. But you can call _default_on_change that
will call all the on_change method.


> Or are there helper functions that support this?

But I see it doesn't call the on_change_with, I don't now if it should.
And we should perhaps make it public.

> I know from working with proteus that currently the client needs to call
> the on_change code, but is that also required for modules?

For proteus it is done because it is a library that behave like the GUI.
And from the modules point of view, it is not good to have these behavior by
default.

-- 
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/

Attachment: pgpMwpCkixON5.pgp
Description: PGP signature

Reply via email to