Skip to content

Commit

Permalink
[REF] point_of_sale: remove stock location from POS config
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
AntoineVDV authored and pimodoo committed Jun 3, 2019
1 parent a681631 commit 8e30349
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 44 deletions.
19 changes: 1 addition & 18 deletions addons/point_of_sale/models/pos_config.py
Expand Up @@ -40,7 +40,7 @@ class PosConfig(models.Model):
_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
return self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1).pos_type_id.id

def _default_sale_journal(self):
journal = self.env.ref('point_of_sale.pos_sale_journal', raise_if_not_found=False)
Expand All @@ -54,9 +54,6 @@ def _default_invoice_journal(self):
def _default_pricelist(self):
return self.env['product.pricelist'].search([('currency_id', '=', self.env.company.currency_id.id)], limit=1)

def _get_default_location(self):
return self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1).lot_stock_id

def _get_group_pos_manager(self):
return self.env.ref('point_of_sale.group_pos_manager')

Expand All @@ -79,9 +76,6 @@ def _compute_default_customer_html(self):
default=_default_picking_type_id,
domain="[('code', '=', 'outgoing'), ('warehouse_id.company_id', '=', company_id)]")
use_existing_lots = fields.Boolean(related='picking_type_id.use_existing_lots', readonly=False)
stock_location_id = fields.Many2one(
'stock.location', string='Stock Location',
domain=[('usage', '=', 'internal')], required=True, default=_get_default_location)
journal_id = fields.Many2one(
'account.journal', string='Sales Journal',
domain=[('type', '=', 'sale')],
Expand Down Expand Up @@ -227,11 +221,6 @@ def _compute_current_session_user(self):
pos_config.pos_session_state = False
pos_config.pos_session_duration = 0

@api.constrains('company_id', 'stock_location_id')
def _check_company_location(self):
if self.stock_location_id.company_id and self.stock_location_id.company_id.id != self.company_id.id:
raise ValidationError(_("The stock location and the point of sale must belong to the same company."))

@api.constrains('company_id', 'journal_id')
def _check_company_journal(self):
if self.journal_id and self.journal_id.company_id.id != self.company_id.id:
Expand Down Expand Up @@ -274,11 +263,6 @@ def _onchange_module_account(self):
if self.module_account:
self.invoice_journal_id = self.env.ref('point_of_sale.pos_sale_journal')

@api.onchange('picking_type_id')
def _onchange_picking_type_id(self):
if self.picking_type_id.default_location_src_id.usage == 'internal' and self.picking_type_id.default_location_dest_id.usage == 'customer':
self.stock_location_id = self.picking_type_id.default_location_src_id.id

@api.onchange('use_pricelist')
def _onchange_use_pricelist(self):
"""
Expand Down Expand Up @@ -448,7 +432,6 @@ def open_session_cb(self):
"""
self.ensure_one()
if not self.current_session_id:
self._check_company_location()
self._check_company_journal()
self._check_company_invoice_journal()
self._check_company_payment()
Expand Down
4 changes: 2 additions & 2 deletions addons/point_of_sale/models/pos_order.py
Expand Up @@ -573,7 +573,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='picking_id.location_id',
string="Location", store=True,
readonly=True,
)
Expand Down Expand Up @@ -793,7 +793,7 @@ def create_picking(self):
order_picking = Picking
return_picking = Picking
moves = Move
location_id = order.location_id.id
location_id = picking_type.default_location_src_id.id
if order.partner_id:
destination_id = order.partner_id.property_stock_customer.id
else:
Expand Down
10 changes: 0 additions & 10 deletions addons/point_of_sale/static/src/js/models.js
Expand Up @@ -51,7 +51,6 @@ exports.PosModel = Backbone.Model.extend({
this.company_logo = null;
this.company_logo_base64 = '';
this.currency = null;
this.shop = null;
this.company = null;
this.user = null;
this.users = [];
Expand Down Expand Up @@ -278,11 +277,6 @@ exports.PosModel = Backbone.Model.extend({
self.pos_session.sequence_number = Math.max(self.pos_session.sequence_number, orders[i].data.sequence_number+1);
}
},
},{
model: 'stock.location',
fields: [],
ids: function(self){ return [self.config.stock_location_id[0]]; },
loaded: function(self, locations){ self.shop = locations[0]; },
},{
model: 'product.pricelist',
fields: ['name', 'display_name', 'discount_policy'],
Expand Down Expand Up @@ -2243,7 +2237,6 @@ exports.Order = Backbone.Model.extend({
var client = this.get('client');
var cashier = this.pos.get_cashier();
var company = this.pos.company;
var shop = this.pos.shop;
var date = new Date();

function is_xml(subreceipt){
Expand Down Expand Up @@ -2305,9 +2298,6 @@ exports.Order = Backbone.Model.extend({
phone: company.phone,
logo: this.pos.company_logo_base64,
},
shop:{
name: shop.name,
},
currency: this.pos.currency,
};

Expand Down
18 changes: 4 additions & 14 deletions addons/point_of_sale/views/pos_config_view.xml
Expand Up @@ -457,24 +457,14 @@
<div class="o_setting_right_pane">
<label for="picking_type_id" string="Operation Type"/>
<div class="text-muted">
Operation type used to record product pickings
Operation type used to record product pickings <br/>
Products will be taken from the default source location of this operation type
</div>
<div class="content-group mt16">
<field name="picking_type_id" required="1"/>
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box" groups="stock.group_stock_multi_locations">
<div class="o_setting_right_pane">
<label for="stock_location_id"/>
<div class="text-muted">
Stock location used for the inventory
</div>
<div>
<field name="stock_location_id" options="{'no_create': True}"/>
</div>
</div>
</div>
</div>
<h2>Accounting</h2>
<div class="row mt16 o_settings_container" id="accounting_section">
Expand Down Expand Up @@ -509,7 +499,7 @@
<field name="arch" type="xml">
<tree string="Point of Sale Configuration">
<field name="name" />
<field name="stock_location_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
<field name="picking_type_id"/>
</tree>
</field>
</record>
Expand All @@ -521,7 +511,7 @@
<search string="Point of Sale Config">
<field name="name"/>
<filter string="Inactive" name="inactive" domain="[('active', '=', False)]" />
<field name="stock_location_id" groups="stock.group_stock_multi_locations" />
<field name="picking_type_id" />
</search>
</field>
</record>
Expand Down

0 comments on commit 8e30349

Please sign in to comment.