[FIX] pos_sale: fix warehouse group by in sales report

Current behavior:
When grouping by warehouse in the sales report, the pos orders appeared
under the "None" warehouse group.

Steps to reproduce:
- Create a PoS order
- Validate the PoS order, and close the session
- Go to sale reporting, group by warehouse
- A group "None" appears, with the PoS order inside

opw-3540797

closes odoo/odoo#147100

X-original-commit: 132dd31e7e7a941ad375ada0be35dde05d0b3a43
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: Robin Engels (roen) <roen@odoo.com>
This commit is contained in:
roen-odoo
2023-12-21 17:24:58 +00:00
parent c66551ff8a
commit 47ff920f57
2 changed files with 29 additions and 2 deletions
+14 -2
View File
@@ -86,13 +86,23 @@ class SaleReport(models.Model):
select_ += template % (value, fname)
return select_
def _available_additional_pos_fields(self):
"""Hook to replace the additional fields from sale with the one from pos_sale."""
return {
'warehouse_id': 'picking.warehouse_id',
}
def _fill_pos_fields(self, additional_fields):
"""Hook to fill additional fields for the pos_sale.
:param values: dictionary of values to fill
:type values: dict
"""
return {x: 'NULL' for x in additional_fields}
filled_fields = {x: 'NULL' for x in additional_fields}
for fname, value in self._available_additional_pos_fields().items():
if fname in additional_fields:
filled_fields[fname] = value
return filled_fields
def _from_pos(self):
return """
@@ -104,6 +114,7 @@ class SaleReport(models.Model):
LEFT JOIN uom_uom u ON u.id=t.uom_id
LEFT JOIN pos_session session ON session.id = pos.session_id
LEFT JOIN pos_config config ON config.id = session.config_id
LEFT JOIN stock_picking_type picking ON picking.id = config.picking_type_id
JOIN {currency_table} ON currency_table.company_id = pos.company_id
""".format(
currency_table=self.env['res.currency']._get_query_currency_table(self.env.companies.ids, fields.Date.today())
@@ -138,7 +149,8 @@ class SaleReport(models.Model):
partner.zip,
u.factor,
pos.crm_team_id,
currency_table.rate"""
currency_table.rate,
picking.warehouse_id"""
def _query(self):
res = super()._query()
@@ -100,3 +100,18 @@ class TestPoSSaleReport(TestPoSCommon):
move_id = self.env['account.move'].browse(order_ids[0]['account_move'])
self.assertEqual(move_id.partner_id.id, self.customer.id)
self.assertEqual(move_id.partner_shipping_id.id, self.other_customer.id)
def test_warehouse(self):
self.open_new_session()
session = self.pos_session
orders = []
# Process two orders
orders.append(self.create_ui_order_data([(self.product0, 3)]))
self.env['pos.order'].create_from_ui(orders)
session.action_pos_session_closing_control()
reports = self.env['sale.report'].sudo().search([('product_id', '=', self.product0.id)], order='id', limit=2)
self.assertEqual(reports[0].warehouse_id.id, self.config.picking_type_id.warehouse_id.id)