Tryton - Issues

 

Issue8495

Title purchase permits selecting de-activated products when using supplier product code/names
Priority feature Status chatting
Superseder Nosy List pokoli, risto3
Type feature request Components purchase, sale_product_customer
Assigned To Keywords
Reviews

Created on 2019-07-16.11:54:47 by risto3, last changed by risto3.

Messages
msg52581 (view) Author: [hidden] (risto3) Date: 2019-10-19.19:51:59
This searcher seems to work better too:
   @classmethod
    def search_active(cls, name, clause):
        domain = ['OR',
            [('template.' + clause[0],) + tuple(clause[1:]),
             ('product', '=', None)],
            [('template.' + clause[0],) + tuple(clause[1:]),
             ('product.' + clause[0],) + tuple(clause[1:])],
            ]
        return domain

So now, the only case that seems to not work correctly is where a product template is deactivated, with a product variant active but no product_supplier attached.
msg52580 (view) Author: [hidden] (risto3) Date: 2019-10-19.19:31:30
This should be better:
    def getter_active(self, name):
        if self.template and self.template.active:
            return self.product.active if self.product else True
        return False

But it appears the searcher is more important 'cause if product variant is not active it still find it.

I'll ask in the forum about the domain clause to not muddy things here.
msg52579 (view) Author: [hidden] (risto3) Date: 2019-10-19.19:11:32
Goes to show, already see a problem in the getter... product variant is optional.
will update...
msg52578 (view) Author: [hidden] (risto3) Date: 2019-10-19.19:09:42
I tried adding the following to product_supplier:

diff -r 89b64c48aa46 product.py
--- a/product.py        Mon May 06 15:09:22 2019 +0200
+++ b/product.py        Sat Oct 19 18:55:47 2019 +0200
@@ -218,6 +218,18 @@
     lead_time = fields.TimeDelta('Lead Time')
     currency = fields.Many2One('currency.currency', 'Currency', required=True,
         ondelete='RESTRICT')
+    active = fields.Function(fields.Boolean('Active'), 'getter_active',
+        searcher='search_active')
+
+    @fields.depends('product', 'template')
+    def getter_active(self, name):
+        if self.template and self.template.active:
+            return self.product and self.product.active
+        return False
+
+    @classmethod
+    def search_active(cls, name, clause):
+        return [('template.' + clause[0],) + tuple(clause[1:])]

I needed to add a searcher to avoid an exception raised indicating that one was missing.
(note, since 5.2 with optional product added to product supplier and mandatory template
there probably still needs a clause to check product.active if product is not None although
this *is* checked in getter_active())

In any event, this seems to get over the supplier product side issues.

BUT, during testing, I notice that there are also product variants (that is, if I enter a code and not name
in the left hand side) that are also displayed if product.active but not product.template.active

That seems a bit more complicated... what should be done there? similar?
msg50673 (view) Author: [hidden] (pokoli) (Tryton committer) (Tryton translator) Date: 2019-07-16.13:39:19
Probably adding an active field (computed using product values) on product supplier should do the trick.
msg50671 (view) Author: [hidden] (risto3) Date: 2019-07-16.11:54:46
There is a difficulty in purchasing whereas using the left hand side product form, only active products are displayed/selectable, but if using the right hand side (supplier product) both active and inactive products are displayed/selectable.

They should work the same and only display active products for selection.

This is easy to reproduce.

The only work-around found so far is to go to Product->Product Suppliers and find the entry pointing to the disactivated product and delete it.
History
Date User Action Args
2019-10-19 19:52:00risto3setmessages: + msg52581
2019-10-19 19:31:31risto3setmessages: + msg52580
2019-10-19 19:11:32risto3setmessages: + msg52579
2019-10-19 19:09:43risto3setmessages: + msg52578
2019-07-16 13:39:19pokolisetstatus: unread -> chatting
nosy: + pokoli
messages: + msg50673
2019-07-16 12:11:08cedsetcomponent: + sale_product_customer
2019-07-16 12:07:15cedsetpriority: bug -> feature
component: + purchase
type: feature request
2019-07-16 11:54:47risto3create

Showing 10 items. Show all history (warning: this could be VERY long)