Skip to content

18.0 practice task agir #688

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

Draft
wants to merge 4 commits into
base: 18.0
Choose a base branch
from

Conversation

agir-odoo
Copy link

@agir-odoo agir-odoo commented Apr 2, 2025

[ADD] dev_zero_stock_blockage: implemented zero stock approval task
Ensure that Sales Orders cannot be confirmed without Zero Stock Approval,
restricting Sales Users from modifying the field while allowing only
Sales Administrators to approve orders.

--> Inherited Model

  • Inherited the main model sale order.
  • Added a new boolean field zero stock approval in the sale order model.
  • Overridden fields get() to make the field read-only for Sales Users
    (sales person)
  • Made action confirm() to restrict order confirmation unless
    zero stock approval is checked.
  • Implemented sale order views xml to display zero stock approval
    after payment term id.

Access Rights

  • Sales Administrator - Can edit the field.
  • Sales User : Read-only access.

Ensures better control over order confirmation based on stock approval.

@robodoo
Copy link

robodoo commented Apr 2, 2025

Pull request status dashboard

@agir-odoo agir-odoo force-pushed the 18.0-practice-task-agir branch 8 times, most recently from 9643f88 to 137fcbf Compare April 9, 2025 08:18
@agir-odoo agir-odoo force-pushed the 18.0-practice-task-agir branch from 662b14a to bcdf892 Compare April 14, 2025 06:17
Ensure that Sales Orders cannot be confirmed without Zero Stock Approval,
restricting Sales Users from modifying the field while allowing only
Sales Administrators to approve orders.

--> Inherited Model
- Inherited the main model  sale order.
- Added a new boolean field zero stock approval in the sale order model.
- Overridden fields get() to make the field  read-only  for Sales Users
(sales person)
- Made action confirm() to restrict order confirmation unless
zero stock approval  is checked.
- Implemented  sale order views xml to display  zero stock approval
after payment term id.

Access Rights
- Sales Administrator -  Can edit the field.
- Sales User : Read-only access.

- Created a boolean field 'zero_stock_approval' to allow admins to approve orders
  with low stock
- Only Sales Manager can edit this field; others see it as readonly
- If any product has demand > available stock and the user is not a manager,
  they must get admin approval
- Blocked order confirmation if quantity is less than available and no approval
  is given
- Skipped stock check for service and combo products (only checked
  consu {goods} type)
- Added a warning message popup when admin gives approval for a product
  with low stock

Ensures better control over order confirmation based on stock approval.
…n POS UI

- Created a new module salesperson button in pos
- Added  salesperson id field in posorder model to track salesperson
- Created a new button Select Salesperson in POS frontend
- Implemented the button in controlbutton xml
- Developed  select salesperson button js as an OWL component
- Patched  ControlButtons to include the Salesperson button in POS
- Registered assets properly in  manifest py for POS UI
- Debugged and tested visibility of the button in POS UI
…sub-product

- Introduced 'Is Kit' field on product templates to define kit-type products
- Added Many2many field to select sub-products for a kit
- Added smart button 'Configure Kit' on sale order line, visible only for
  kit products
- Created a wizard to select sub-product quantity and price per main product
- Sub-products are auto-added as separate sale order lines under the
  main kit line
- Sub-product lines are read-only & priced at 0 (cost included in main product)
- Sub-products support storable/consumable product types for stock tracking
- Main product's unit price remains unchanged;
  subtotal includes sub-product costs
- Sub-product lines are auto-deleted if the main kit line is removed
- Added 'Print in Report' checkbox on Sale Order to control
  sub-product visibility
- Applied conditional display of sub-products in:
  - Sale Order PDF
  - Portal Order Preview
  - Invoice PDF  (QWeb-safe logic using t-set variables)
@agir-odoo agir-odoo force-pushed the 18.0-practice-task-agir branch 5 times, most recently from aaa079f to 0665818 Compare April 15, 2025 13:47
- Added a new field in product form to set a second UoM
- Backend constraint to prevent primary and secondary UoM being the same
- Loaded second UoM info into POS
- Added custom Add Quantity button in POS control panel(before customer button)
- Clicking the button opens a popup to enter quantity in second UoM
- POS converts the quantity based on UoM ratio
- Added validations in popup:
  - Show error if quantity is zero or negative or empty input
- Optimized validation with translatable error message
- UI improvements with conditional visibility and consistent UX
@agir-odoo agir-odoo force-pushed the 18.0-practice-task-agir branch from 0665818 to b103d52 Compare April 15, 2025 18:45
Copy link

@nihp-odoo nihp-odoo left a comment

Choose a reason for hiding this comment

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

Hello @agir-odoo
Some suggestion and changes on your new_product_type_kit.

After adding kit once, if I am again click on 'configure kit' and remove one of the kit lines then price is updated but the it is still present in sale order line.. Check it out!

Thanks!

@@ -0,0 +1,22 @@
{
'name': 'Dev Zero Stock Blockage',

Choose a reason for hiding this comment

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

Name?

Comment on lines +5 to +7
'description': """
Add kit-type products with configurable sub-products and conditional report visibility
""",

Choose a reason for hiding this comment

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

Check indentation in codebase!

Add kit-type products with configurable sub-products and conditional report visibility
""",
'author': 'Raghav Agiwal',
'depends': ['sale_management', 'stock', 'product'],

Choose a reason for hiding this comment

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

Do we need stock here? Also only sale_management will work fine.

'report/report_invoice_templates.xml',
],
'installable': True,
'application': True,

Choose a reason for hiding this comment

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

We don't need this module as an application!


print_in_report = fields.Boolean(
string="Print in report?",
default=False

Choose a reason for hiding this comment

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

It'll be False by default. This is used if we are going other way.

}
}

def unlink(self):

Choose a reason for hiding this comment

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

This function is letting user delete sub products. Check functional flow.

Choose a reason for hiding this comment

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

It should be inside wizard folder.

<field name="product_id" readonly="1"/>
</group>

<group string="Sub Products">

Choose a reason for hiding this comment

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

Use <sheet> instead of <group> here.

_name = 'kit.wizard'
_description = 'Kit Wizard'

product_id = fields.Many2one('product.product', string='Product', required=True)

Choose a reason for hiding this comment

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

Are we using this field?

order_id = self.env.context.get("active_id")
sale_order_line_id = self.env.context.get("default_sale_order_line_id")
order = self.env["sale.order"].browse(order_id)
parent_line = order.order_line.filtered(lambda l: l.id == sale_order_line_id)

Choose a reason for hiding this comment

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

We should avoid such variable names.

Copy link

@nihp-odoo nihp-odoo left a comment

Choose a reason for hiding this comment

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

Hello @agir-odoo
Some comments on your salesperson_button_in_pos task.
Thanks!

Comment on lines +5 to +7
'description': """
Adding salesperson button in pos
""",

Choose a reason for hiding this comment

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

Suggested change
'description': """
Adding salesperson button in pos
""",
'description': """
Adding salesperson button in pos
""",

Check codebase for more examples.

],
'assets': {
'point_of_sale._assets_pos': [
'salesperson_button_in_pos/static/src/app/**/*',

Choose a reason for hiding this comment

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

We can directly work in static/src no need to create separate folder inside.

],
},
'installable': True,
'application': True,

Choose a reason for hiding this comment

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

No need to make this an application.

@@ -0,0 +1,3 @@
from . import pos_order
from . import pos_session
from . import hr_employee

Choose a reason for hiding this comment

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

Why are we making this hr_employee file?

Comment on lines +11 to +12


Choose a reason for hiding this comment

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

Suggested change

selectedSalesPerson: null
});
useHotkey("enter", () => this.onEnter());
this.loadSalespeople();

Choose a reason for hiding this comment

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

Why not call this.getSalespersons() directly from here.

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_pos_order_form" model="ir.ui.view">

Choose a reason for hiding this comment

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

<td class="salesperson-line-email">
</td>
<td>
<t t-if="this.props.currentSelectedSalesperson?.id === salesperson?.id">

Choose a reason for hiding this comment

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

It works on the whole salesperson! If I again click on the selected salesperson it gets deselected. We should allow this when we only click in the 'cross'

Comment on lines +50 to +52
<div t-if="state.query" class="search-more-button d-flex justify-content-center my-2">
<button class="btn btn-lg btn-primary" t-on-click="onEnter">Search more</button>
</div>

Choose a reason for hiding this comment

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

Why are we adding this button, it just triggers the notification!

this.state = useState({ selectedSalesPerson: null });
}

async selectSalesperson() {

Choose a reason for hiding this comment

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

Why are we doing same thing twice? Here and in salesperson_list?

Copy link

@nihp-odoo nihp-odoo left a comment

Choose a reason for hiding this comment

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

Hello @agir-odoo
Some comments on your dev_zero_stock_bloackage task.
Thanks...

Comment on lines +5 to +9
'description': """
This module stops Sales Orders from being confirmed if any product is out of stock, unless a Sales Manager gives approval.
Sales users can see the Zero Stock Approval field but cannot edit it.
It only checks stock for physical products, not services or combos.
""",
Copy link

@nihp-odoo nihp-odoo Apr 17, 2025

Choose a reason for hiding this comment

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

Indentation is not proper.. checkout codebase.
Also, do we need stock in depends?

'views/sale_order_views.xml',
],
'installable': True,
'application': True,

Choose a reason for hiding this comment

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

No need to make it an application.

Comment on lines +19 to +25
'warning': {
'title': "Heads Up!",
'message': (
f"Just a quick reminder..!! You are approving this order where product '{line.product_id.display_name}' "
f"has demand {line.product_uom_qty} > available {line.product_id.qty_available}."
)
}

Choose a reason for hiding this comment

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

What if there are 2 sale_order_line where product_uom_qty is greater than qty_available? Warning will display only the first one it found.

</xpath>
</field>
</record>

Choose a reason for hiding this comment

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

Suggested change

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_sale_order_form" model="ir.ui.view">

Choose a reason for hiding this comment

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

Name ID according to the coding guideline!

Comment on lines +55 to +60
raise UserError(
f"Cannot confirm this Sale Order.\n"
f"Product '{line.product_id.display_name}' has only {available_qty} in stock, "
f"but {demand_qty} is requested.\n"
f"Approval is required to proceed."
)

Choose a reason for hiding this comment

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

Here too! same issue as warning.

Comment on lines +42 to +47
# if demand_qty <= 0:
# raise UserError(
# f"You cannot confirm this Sale Order.\n"
# f"Product '{line.product_id.display_name}' has a quantity of {demand_qty}.\n"
# f"Quantity must be greater than zero."
# )

Choose a reason for hiding this comment

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

!

Comment on lines +55 to +60
raise UserError(
f"Cannot confirm this Sale Order.\n"
f"Product '{line.product_id.display_name}' has only {available_qty} in stock, "
f"but {demand_qty} is requested.\n"
f"Approval is required to proceed."
)

Choose a reason for hiding this comment

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

Here too! same issue as warning.

def _onchange_zero_stock_approval(self):
if self.zero_stock_approval and self.env.user.has_group('sales_team.group_sale_manager'):
for line in self.order_line:
if line.product_id.type in ['consu', 'product'] and line.product_uom_qty > line.product_id.qty_available:

Choose a reason for hiding this comment

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

I think there is no product_type called product.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants