[FIX] Various fixes:

- Error with the sequence number.
- Visible texts that should be in uppercases.
- order_id should only be visible if group_stock_request_order
  option is enabled.
- adds more tests
- adds consistency between models company-wise
This commit is contained in:
mreficent
2018-04-11 17:21:15 +02:00
committed by Kitti U
parent 0e8b47cf51
commit d9150b8335
16 changed files with 275 additions and 30 deletions

View File

@@ -43,8 +43,7 @@ class StockRequest(models.Model):
name = fields.Char(
'Name', copy=False, required=True, readonly=True,
states={'draft': [('readonly', False)]},
default=lambda self: self.env['ir.sequence'].next_by_code(
'stock.request'))
default='/')
state = fields.Selection(selection=REQUEST_STATES, string='Status',
copy=False, default='draft', index=True,
readonly=True, track_visibility='onchange',
@@ -102,7 +101,7 @@ class StockRequest(models.Model):
'stock.request'),
)
expected_date = fields.Datetime(
'Expected date', default=fields.Datetime.now, index=True,
'Expected Date', default=fields.Datetime.now, index=True,
required=True, readonly=True,
states={'draft': [('readonly', False)]},
help="Date when you expect to receive the goods.",
@@ -213,6 +212,31 @@ class StockRequest(models.Model):
result |= location
return result
@api.constrains('company_id', 'product_id', 'warehouse_id',
'location_id', 'route_id')
def _check_company_constrains(self):
""" Check if the related models have the same company """
for rec in self:
if rec.product_id.company_id and \
rec.product_id.company_id != rec.company_id:
raise ValidationError(
_('You have entered a product that is assigned '
'to another company.'))
if rec.location_id.company_id and \
rec.location_id.company_id != rec.company_id:
raise ValidationError(
_('You have entered a location that is '
'assigned to another company.'))
if rec.warehouse_id.company_id != rec.company_id:
raise ValidationError(
_('You have entered a warehouse that is '
'assigned to another company.'))
if rec.route_id and rec.route_id.company_id and \
rec.route_id.company_id != rec.company_id:
raise ValidationError(
_('You have entered a route that is '
'assigned to another company.'))
@api.constrains('product_id')
def _check_product_uom(self):
''' Check if the UoM has the same category as the
@@ -439,6 +463,14 @@ class StockRequest(models.Model):
action['res_id'] = pickings.id
return action
@api.model
def create(self, vals):
upd_vals = vals.copy()
if upd_vals.get('name', '/') == '/':
upd_vals['name'] = self.env['ir.sequence'].next_by_code(
'stock.request')
return super().create(upd_vals)
@api.multi
def unlink(self):
if self.filtered(lambda r: r.state != 'draft'):