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
[IMP] PoS usability improvements #32870
Conversation
f067842
to
a0d0651
Compare
a0d0651
to
994d9ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments, nothing major besides the read_group
to count pos order for better perf
@@ -111,6 +112,11 @@ def _confirm_orders(self): | |||
|
|||
_sql_constraints = [('uniq_name', 'unique(name)', "The name of this POS Session must be unique !")] | |||
|
|||
@api.multi | |||
def _compute_order_count(self): | |||
for pos in self: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaaah, classic badly-performing count field :D
use read_group
instead
@api.multi | ||
def action_view_order(self): | ||
action = { | ||
'name': 'Orders', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be translatable
action = {
'name': _('Orders'),
# .....
@@ -345,6 +351,20 @@ def open_cashbox(self): | |||
|
|||
return action | |||
|
|||
@api.multi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@api.multi
is the default mode, no need to specify it (same for the method above as well)
class Warehouse(models.Model): | ||
_inherit = "stock.warehouse" | ||
|
||
pos_type_id = fields.Many2one('stock.picking.type', string="PoS type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shitty label is shitty (I know, you took example on stock - I prefer the example in mrp though)
let's use "Point of Sale Operation Type" instead
@@ -62,6 +62,13 @@ | |||
type="object" context="{'balance': 'end'}"> | |||
<span class="o_stat_text">Set Closing Balance</span> | |||
</button> | |||
<button name="action_view_order" | |||
class="oe_stat_button" | |||
attrs="{'invisible': [('order_count', '=', 0)]}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't make the button invisible in case of 0 orders, we can expect all sessions to always have at least one order anyway (and users might get confused if the field is not always visible)
unless it was a specific request from the PO? didn't see it in the spec
'type': 'ir.actions.act_window', | ||
'domain': [('session_id', 'in', self.ids)], | ||
} | ||
if len(self.order_ids) == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't handle that case; if you have only one order in your session it doesn't shock me to have the list view open anyway...
this makes sense when it's frequent for an o2m field to lead to a single record (e.g. link between SO and invoice: you expect only one invoice per SO most of the time); less so when you expect the normal case to be 'more than one'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved
addons/point_of_sale/__init__.py
Outdated
|
||
It is necessary if the point_of_sale module is installed after some warehouses were already created. | ||
""" | ||
env = api.Environment(cr, SUPERUSER_ID, {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you have multiple functions in the same parent call (both functions get called), it's better to use an environment manager here to avoid instantiating twice the same env by using the env manager:
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
# do stuff
same for _assign_picking_types
the first environment you will instantiate will be stored in memory and reused in the second function
addons/point_of_sale/__init__.py
Outdated
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
pos_configs = env['pos.config'].search([('picking_type_id', '=', False)]) | ||
for pos_config in pos_configs: | ||
default_picking_type_id = env['stock.warehouse'].search([('company_id', '=', pos_config.company_id.id)], limit=1).pos_type_id.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it make more sense to get the picking type from the warehouse linked to the pos_config via the stock_location_id m2o instead? that way we're sure that we take the picking type from the same location...
not entirely trivial, since there is no direct link between the location and the warehouse AFAICT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved as of part 4 of task #1970513
994d9ee
to
61677a5
Compare
404b90b
to
6c47521
Compare
6c47521
to
d7850bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multi-company changes needed
@pimodoo can review as well if he so wishes
@@ -39,6 +39,9 @@ class PosConfig(models.Model): | |||
_name = 'pos.config' | |||
_description = 'Point of Sale Configuration' | |||
|
|||
def _default_picking_type_id(self): | |||
return self.env['stock.warehouse'].search([('company_id', '=', self.env.user.company_id.id)], limit=1).pos_type_id.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multi-company revamp has been merged before you, so a few changes:
[('company_id', '=', self.env.company_id.id)]
should do the trick (self.env.company_id
is the main company in the context, self.env.company_ids
contains all visible companies in the context - the context is stored client side, so different browser tabs can have completely different contexts)
related='picking_type_id.default_location_src_id', | ||
string='Stock Location', | ||
readonly=True, | ||
default=_get_default_location, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for default on a related readonly - it might break stuff in fact (readonly is only enforced in client; if your default is called after the picking_type_id default and does not match the value, you've just updated the default location of the picking!)
@@ -572,7 +572,7 @@ def _default_pricelist(self): | |||
picking_type_id = fields.Many2one('stock.picking.type', related='session_id.config_id.picking_type_id', string="Operation Type", readonly=False) | |||
location_id = fields.Many2one( | |||
comodel_name='stock.location', | |||
related='session_id.config_id.stock_location_id', | |||
related='session_id.config_id.picking_type_id.default_location_src_id', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should've seen it the first time, but this is not correct; if the picking type's location gets changed it will retroactively change the location of old orders... it's actually not your code that causes this (it was here before) but this is clearly a bug waiting to happen. Same for picking_type_id - changing the picking type of the config should certainly not change the picking type of all existing orders for that config... I'm actually pretty surprised this did not happen before 🤔
@pimodoo probably an override of default_get
, a good task for a newbie - do you want it or do we do it here?
edit: never mind my comment for picking_type_id, it's not stored. Just need a default for location_id then
d7850bc
to
dadb85b
Compare
dadb85b
to
b1d9013
Compare
b1d9013
to
bc9269d
Compare
f61a20d
to
cf87518
Compare
74ecd9e
to
544e2ef
Compare
As session, is a more global object, we want to put its menu item before the one for orders. TASK-ID: 1970513
When you are looking at a point of sale session, the detail of what is sales have been done during this session is stored in the POS Orders linked to it. So we've added button on the session form that will show all related sales done during this session. TASK-ID: 1970513
We are handeling if the default sales team for pos has been deleted by raising and catching an Access error instead of a ValueError TASK-ID: 1970513
When you are selling goods through point of sale, pinkings are created to remove what have been sold from the stock. This picking is created by using the picking_type set on pos_config. For now, the there is only one picking type POS Order existing by default, which is located on the first warehouse in data. It means that if you create another warehouse and/or company, you will have to manually create picking type if you want to be able to link pos config to the new warehouse. So now, each warehouse will have its own picking_type for POS, which will ease the link between the pos config and the warehouse. We've also set a default value on pos config to take the first picking type, and added a domain that will show only the outgoing types. TASK-ID: 1970513
544e2ef
to
5d517f8
Compare
There is currently a stock location that is set on the pos config which is by default the the default source of the picking type. This field is not really usefull and we prefer that the configuration of the source location where the POS will take products come from a dedicated picking type that will have the correct default source location. So we have removed the stock_location_id from the pos_config and changed the related set on orders, by the location of the picking set on the pos order, as it was not really consistent that if the pos_config was changed the location of all existing orders was changed too. TASK-ID: 1970513
5d517f8
to
ea26512
Compare
robodoo r+ rebase-ff |
Merge method set to rebase and fast-forward |
There is currently a stock location that is set on the pos config which is by default the the default source of the picking type. This field is not really usefull and we prefer that the configuration of the source location where the POS will take products come from a dedicated picking type that will have the correct default source location. So we have removed the stock_location_id from the pos_config and changed the related set on orders, by the location of the picking set on the pos order, as it was not really consistent that if the pos_config was changed the location of all existing orders was changed too. TASK-ID: 1970513 closes #32870 Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Merged, thanks! |
Description of the issue/feature this PR addresses
Task ID : 1970513
--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr