Force an account on a product in a configuration form

29 views
Skip to first unread message

Vincent Bastos

unread,
Feb 17, 2017, 11:37:04 PM2/17/17
to tryton-dev
Hi,

I would like to create a Configuration form for a module that has a mandatory field for a product and I would like this form to force the user to create a product with accounts being setup.

Is this possible? How would I do this?

Cédric Krier

unread,
Feb 18, 2017, 7:15:10 AM2/18/17
to tryton-dev
This is a strange idea because product is referential data so it is
created prior to operations.
So with this in mind, the product should be created with the required
accounts depending of its configuration. This is like that sale (and
purchase) does, it adds a check box defining if the product can be used
for a sale and if checked the revenue account is required.
But this is not enough because we have this feature to inherit from the
accounting category. So we still have to check and raise an error when
we need an account from a product.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Vincent Bastos

unread,
Feb 18, 2017, 3:00:58 PM2/18/17
to tryto...@googlegroups.com
On Sat, Feb 18, 2017 at 10:13 PM, Cédric Krier <cedric...@b2ck.com> wrote:
On 2017-02-17 20:37, Vincent Bastos wrote:
> Hi,
>
> I would like to create a Configuration form for a module that has a
> mandatory field for a product and I would like this form to force the user
> to create a product with accounts being setup.
>
> Is this possible? How would I do this?

This is a strange idea because product is referential data so it is
created prior to operations.
So with this in mind, the product should be created with the required
accounts depending of its configuration. This is like that sale (and
purchase) does, it adds a check box defining if the product can be used
for a sale and if checked the revenue account is required.
But this is not enough because we have this feature to inherit from the
accounting category. So we still have to check and raise an error when
we need an account from a product.

Thanks for your comment. It has made me rethink my design.

For this module there is a function which automatically applies a charge based on certain conditions. So I guess the right way of implementing this is actually to create a product record in XML in the module already. 

--
Vincent Bastos
Lava Lab Software

Cédric Krier

unread,
Feb 18, 2017, 6:45:06 PM2/18/17
to tryto...@googlegroups.com
On 2017-02-19 06:00, Vincent Bastos wrote:
> For this module there is a function which automatically applies a charge
> based on certain conditions. So I guess the right way of implementing this
> is actually to create a product record in XML in the module already.

I do not recommend to create product (or any non standardized data) via
XML because this removes the possibility to the user to customize it.

I guess you have a model that defines the condition to apply the charge
so on this model you can link to a product. There you could have any
sort of validation to ensure the product is correctly configured.

I suggest you to look at the module sale_shipment_cost which does
probably something similar to yours.

Vincent Bastos

unread,
Mar 2, 2017, 10:56:38 PM3/2/17
to tryto...@googlegroups.com

On Sun, Feb 19, 2017 at 9:40 AM, Cédric Krier <cedric...@b2ck.com> wrote:
On 2017-02-19 06:00, Vincent Bastos wrote:
> For this module there is a function which automatically applies a charge
> based on certain conditions. So I guess the right way of implementing this
> is actually to create a product record in XML in the module already.

I do not recommend to create product (or any non standardized data) via
XML because this removes the possibility to the user to customize it.

I guess you have a model that defines the condition to apply the charge
so on this model you can link to a product. There you could have any
sort of validation to ensure the product is correctly configured.

I suggest you to look at the module sale_shipment_cost which does
probably something similar to yours.

I tried this module, but it's not what I am trying to achieve. In my module I have a function which automatically sends parties invoices by email or/and post depending on what the party has selected. The module is setup to automatically charge a party a fee if they have selected to receive an invoice by post.

At the moment the way I am solving this is by using a couple of fields on the configuration of the module:

    lease_postage_notice_fee_amount = fields.Numeric(
        'Postage Notice Fee Amount',
        digits=(16, Eval('currency_digits', 2)),
        depends=['currency_digits']
    )
    lease_postage_notice_fee_account = fields.Many2One(
            'account.account', 'Postage Notice Fee Account',
            required=False
    )

When the module creates the invoice it checks on the party if they have selected to receive by post and adds an invoice line to reflect this.

PS I tested the module sale_shipment_cost and the field "Sale Shipment Cost Method" on the sale configuration is set to "On Order", but I noticed in the code that the function default_sale_shipment_cost returns 'shipment'. Can you explain why this is?

Cédric Krier

unread,
Mar 3, 2017, 9:20:06 AM3/3/17
to tryto...@googlegroups.com
On 2017-03-03 13:56, Vincent Bastos wrote:
> On Sun, Feb 19, 2017 at 9:40 AM, Cédric Krier <cedric...@b2ck.com> wrote:
> I tried this module, but it's not what I am trying to achieve. In my module
> I have a function which automatically sends parties invoices by email
> or/and post depending on what the party has selected. The module is setup
> to automatically charge a party a fee if they have selected to receive an
> invoice by post.
>
> At the moment the way I am solving this is by using a couple of fields on
> the configuration of the module:
>
> lease_postage_notice_fee_amount = fields.Numeric(
> 'Postage Notice Fee Amount',
> digits=(16, Eval('currency_digits', 2)),
> depends=['currency_digits']
> )
> lease_postage_notice_fee_account = fields.Many2One(
> 'account.account', 'Postage Notice Fee Account',
> required=False
> )
>
> When the module creates the invoice it checks on the party if they have
> selected to receive by post and adds an invoice line to reflect this.

This sounds good. You could also use a link to a service product and
store use the revenue account and the list price. This will replace the
two fields by a single one.

> PS I tested the module sale_shipment_cost and the field "Sale Shipment Cost
> Method" on the sale configuration is set to "On Order", but I noticed in
> the code that the function default_sale_shipment_cost returns 'shipment'.
> Can you explain why this is?

The default method is for the configuration but the sale default method
use the configured value.
Reply all
Reply to author
Forward
0 new messages