Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW : allow stock management by product #30996

Conversation

thomas-Ngr
Copy link
Contributor

NEW : allow stock management by product

When using product stocks, users may want to have some products for which they don't want to manage stocks, for example in case of subcontracting.

This PR:

  • adds a field "Stockable product" on product card (editable on update, not on create)
  • sets this option to 1 by default
  • hides the "stocks" tabs if this option is not set
  • does not manage stock movements for a product if this option is not set.

Discussion started on #26184 and #26200

SQL Part : #26190

follow-up on #30230 (closed) because file expedition.class has been split into two files.

/**
* @var int
*/
public $no_button_copy;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is no more used in develop. Can you remove it?

/**
* @var int
*/
public $no_button_copy;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is no more used in develop. Can you remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eldy I just did it.

@thomas-Ngr thomas-Ngr force-pushed the develop_new-stockableproduct_3 branch from aeda220 to 39d5603 Compare September 23, 2024 09:29
@thomas-Ngr thomas-Ngr force-pushed the develop_new-stockableproduct_3 branch from 39d5603 to 151692f Compare September 23, 2024 09:33
@eldy eldy added the PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do) label Sep 29, 2024
@thomas-Ngr thomas-Ngr force-pushed the develop_new-stockableproduct_3 branch from bc8840d to 151692f Compare October 4, 2024 10:20
@@ -813,6 +816,9 @@
$object->fk_default_bom = 0;
}

// managed_in_stock
$object->stockable_product = GETPOSTISSET('stockable_product');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks strange.
if stockable_product = 0,
you wil get
$object->stockable_product = true.

i think what you want to do is
$object->stockable_product = GETPOSTINT('stockable_product');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, since stockable_product is a checkbox.

  • When not checked, $_POST['stockable_product'] is not set
  • When checked, $_POST['stockable_product'] is equal to string 'on'. As a consequence, GETPOSTINT('stockable_product') == 0.

The exact way to deal with it is $object->stockable_product = (int) GETPOST('stockable_product') == 'on'. But it makes useless operations and it does not harm security to $object->stockable_product = GETPOSTISSET('stockable_product'); .

I will cast it to (int).

*
* @var boolean
*/
public $stockable_product = true;
Copy link
Member

@eldy eldy Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using boolean must be avoid as it can't be used to evolve, fr example when we need a third state.
It is better to always use int (even for boolean) so
/* @var integer */
public $stockable_product = 1;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

$qty .= '_'.$j;
}

if ($p->stockable_product == Product::DISABLED_STOCK) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of code from line 366 to 389 looks strange:
Currently, default is to have all product managed as stockable.
So we should have code added to avoid to do something when product is not stock managed. But here yo add code to do more things when stock is not managed.

I think we should not have this part of code from line 366 to 389 and we should have the code to do or not action depending of stockable status somewhere later.
If we remove this part of code, where does the program hangs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I changed the test in Exepedition::addline() to not test stock remaining if product is not managed in stock. see 2407fe0.

For products with a batch/serial, it makes sense to force stock management. I made some changes in product/card to avoid having batch/lot products not managed in stock.

@eldy eldy added github_note No meaning, for internal use. Discussion Some questions or discussions are opened and wait answers of author or other people to be processed and removed PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do) labels Oct 6, 2024
@thomas-Ngr thomas-Ngr force-pushed the develop_new-stockableproduct_3 branch 8 times, most recently from 5e90c18 to a7e42cc Compare November 13, 2024 15:19
@thomas-Ngr thomas-Ngr force-pushed the develop_new-stockableproduct_3 branch from a7e42cc to 8834529 Compare November 13, 2024 15:27
Comment on lines +1727 to +1732
$line = new ExpeditionLigne($this->db); // always set $line for PHAN analyser. @phan-var-force muse be used after an assignation, and there is no assignation for $line.
while ($i < $num) {
$obj = $this->db->fetch_object($resql);


if ($originline > 0 && $originline == $obj->fk_elementdet) {
'@phan-var-force ExpeditionLigne $line'; // $line from previous loop
// '@phan-var-force ExpeditionLigne $line'; // $line from previous loop
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phan-var-force (l.1732) must be used after an assignation, and we don't have any assignation for $line at the beginning of the loop.

Declaring $line before starting the loop is the solution I found to pass Phan tests.

@thomas-Ngr thomas-Ngr requested a review from eldy December 4, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Some questions or discussions are opened and wait answers of author or other people to be processed github_note No meaning, for internal use.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants