mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Allow override of values from calling function
This commit is contained in:
parent
5230a5a41b
commit
cf0feffe26
@ -70,6 +70,7 @@ class CompanySerializer(InvenTreeModelSerializer):
|
||||
'phone',
|
||||
'address',
|
||||
'email',
|
||||
'currency',
|
||||
'contact',
|
||||
'link',
|
||||
'image',
|
||||
|
@ -16,10 +16,7 @@
|
||||
{% if pagetype == 'manufacturers' and roles.purchase_order.add or pagetype == 'suppliers' and roles.purchase_order.add or pagetype == 'customers' and roles.sales_order.add %}
|
||||
<div id='button-toolbar'>
|
||||
<button type='button' class="btn btn-success" id='new-company'>
|
||||
<span class='fas fa-plus-circle'></span> {{ button_text }} (Server Side)
|
||||
</button>
|
||||
<button type='button' class="btn btn-success" id='new-company-2'>
|
||||
<span class='fas fa-plus-circle'></span> {{ button_text }} (Client Side)
|
||||
<span class='fas fa-plus-circle'></span> {{ button_text }}
|
||||
</button>
|
||||
<div class='btn-group'>
|
||||
</div>
|
||||
@ -32,60 +29,49 @@
|
||||
{% endblock %}
|
||||
{% block js_ready %}
|
||||
{{ block.super }}
|
||||
|
||||
$('#new-company').click(function() {
|
||||
launchModalForm("{{ create_url }}", {
|
||||
follow: true
|
||||
});
|
||||
|
||||
createCompany({
|
||||
fields: {
|
||||
is_supplier: {
|
||||
value: {% if pagetype == 'suppliers' %}true{% else %}false{% endif %},
|
||||
},
|
||||
is_manufacturer: {
|
||||
value: {% if pagetype == 'manufacturers' %}true{% else %}false{% endif %},
|
||||
},
|
||||
is_customer: {
|
||||
value: {% if pagetype == 'customers' %}true{% else %}false{% endif %},
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
$('#new-company-2').click(function() {
|
||||
return;
|
||||
|
||||
constructForm(
|
||||
'{% url "api-build-list" %}',
|
||||
'{% url "api-company-list" %}',
|
||||
{
|
||||
method: 'POST',
|
||||
title: '{% trans "Edit Part Details" %}',
|
||||
title: '{% trans "Create new Company" %}',
|
||||
follow: true,
|
||||
fields: {
|
||||
title: {
|
||||
prefix: `<span class='fas fa-user'></span>`
|
||||
},
|
||||
reference: {},
|
||||
part: {
|
||||
filters: {
|
||||
}
|
||||
},
|
||||
quantity: {},
|
||||
/*
|
||||
name: {
|
||||
onEdit: function() {
|
||||
console.log('Edited name field');
|
||||
}
|
||||
},
|
||||
name: {},
|
||||
description: {},
|
||||
category: {
|
||||
filters: {
|
||||
parent: 1,
|
||||
website: {},
|
||||
address: {},
|
||||
currency: {},
|
||||
phone: {},
|
||||
email: {},
|
||||
contact: {},
|
||||
is_supplier: {
|
||||
value: {% if pagetype == 'suppliers' %}true{% else %}false{% endif %},
|
||||
},
|
||||
secondary: {
|
||||
label: '{% trans "New Category" %}',
|
||||
is_manufacturer: {
|
||||
value: {% if pagetype == 'manufacturers' %}true{% else %}false{% endif %},
|
||||
},
|
||||
is_customer: {
|
||||
value: {% if pagetype == 'customers' %}true{% else %}false{% endif %},
|
||||
},
|
||||
active: {
|
||||
onEdit: function() {
|
||||
console.log('edited active field');
|
||||
}
|
||||
},
|
||||
purchaseable: {},
|
||||
salable: {},
|
||||
component: {},
|
||||
'website',
|
||||
'address',
|
||||
'phone',
|
||||
'email',
|
||||
'contact',
|
||||
'is_supplier',
|
||||
'is_manufacturer',
|
||||
'is_customer',
|
||||
*/
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -188,21 +188,6 @@ class CompanyViewTest(CompanyViewTestBase):
|
||||
response = self.client.get(reverse('company-index'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_company_create(self):
|
||||
"""
|
||||
Test the view for creating a company
|
||||
"""
|
||||
|
||||
# Check that different company types return different form titles
|
||||
response = self.client.get(reverse('supplier-create'), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertContains(response, 'Create new Supplier')
|
||||
|
||||
response = self.client.get(reverse('manufacturer-create'), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertContains(response, 'Create new Manufacturer')
|
||||
|
||||
response = self.client.get(reverse('customer-create'), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertContains(response, 'Create new Customer')
|
||||
|
||||
|
||||
class ManufacturerPartViewTests(CompanyViewTestBase):
|
||||
"""
|
||||
|
@ -63,21 +63,18 @@ class CompanyIndex(InvenTreeRoleMixin, ListView):
|
||||
'title': _('Suppliers'),
|
||||
'button_text': _('New Supplier'),
|
||||
'filters': {'is_supplier': 'true'},
|
||||
'create_url': reverse('supplier-create'),
|
||||
'pagetype': 'suppliers',
|
||||
},
|
||||
reverse('manufacturer-index'): {
|
||||
'title': _('Manufacturers'),
|
||||
'button_text': _('New Manufacturer'),
|
||||
'filters': {'is_manufacturer': 'true'},
|
||||
'create_url': reverse('manufacturer-create'),
|
||||
'pagetype': 'manufacturers',
|
||||
},
|
||||
reverse('customer-index'): {
|
||||
'title': _('Customers'),
|
||||
'button_text': _('New Customer'),
|
||||
'filters': {'is_customer': 'true'},
|
||||
'create_url': reverse('customer-create'),
|
||||
'pagetype': 'customers',
|
||||
}
|
||||
}
|
||||
@ -86,7 +83,6 @@ class CompanyIndex(InvenTreeRoleMixin, ListView):
|
||||
'title': _('Companies'),
|
||||
'button_text': _('New Company'),
|
||||
'filters': {},
|
||||
'create_url': reverse('company-create'),
|
||||
'pagetype': 'companies'
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,75 @@
|
||||
{% load i18n %}
|
||||
|
||||
/*
|
||||
* Launches a form to create a new company.
|
||||
* As this can be called from many different contexts,
|
||||
* we abstract it here!
|
||||
*/
|
||||
function createCompany(options={}) {
|
||||
|
||||
// Default field set
|
||||
var fields = {
|
||||
name: {},
|
||||
description: {},
|
||||
website: {},
|
||||
address: {},
|
||||
currency: {},
|
||||
phone: {},
|
||||
email: {},
|
||||
contact: {},
|
||||
is_supplier: {},
|
||||
is_manufacturer: {},
|
||||
is_customer: {}
|
||||
};
|
||||
|
||||
// Override / update default fields as required
|
||||
fields = Object.assign(fields, options.fields || {});
|
||||
|
||||
constructForm(
|
||||
'{% url "api-company-list" %}',
|
||||
{
|
||||
method: 'POST',
|
||||
fields: fields,
|
||||
follow: true,
|
||||
title: '{% trans "Add new Company" %}',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Launch form to create a new manufacturer part
|
||||
function createManufacturerPart(options={}) {
|
||||
|
||||
var fields = {
|
||||
'part': {
|
||||
secondary: {
|
||||
label: '{% trans "New Part" %}',
|
||||
}
|
||||
},
|
||||
'manufacturer': {
|
||||
secondary: {
|
||||
label: '{% trans "New Manufacturer" %}',
|
||||
}
|
||||
},
|
||||
'MPN': {},
|
||||
'description': {},
|
||||
'link': {},
|
||||
};
|
||||
|
||||
fields = Object.assign(fields, options.fields || {});
|
||||
|
||||
constructForm(
|
||||
'{% url "api-manufacturer-part-list" %}',
|
||||
{
|
||||
fields: fields,
|
||||
method: 'POST',
|
||||
follow: true,
|
||||
title: '{% trans "Add new Manufacturer Part" %}',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function loadCompanyTable(table, url, options={}) {
|
||||
/*
|
||||
* Load company listing data into specified table.
|
||||
|
@ -115,10 +115,20 @@ function constructCreateForm(fields, options) {
|
||||
|
||||
var field = fields[name];
|
||||
|
||||
if (field.default != null) {
|
||||
var field_options = options.fields[name] || {};
|
||||
|
||||
// If a 'value' is not provided for the field,
|
||||
if (field.value == null) {
|
||||
|
||||
if ('value' in field_options) {
|
||||
// Client has specified the default value for the field
|
||||
field.value = field_options.value;
|
||||
} else if (field.default != null) {
|
||||
// OPTIONS endpoint provided default value for this field
|
||||
field.value = field.default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We should have enough information to create the form!
|
||||
constructFormBody(fields, options);
|
||||
@ -278,6 +288,11 @@ function constructFormBody(fields, options) {
|
||||
|
||||
// Field prefix
|
||||
fields[field].prefix = field_options.prefix;
|
||||
|
||||
// // Field value?
|
||||
// if (fields[field].value == null) {
|
||||
// fields[field].value = field_options.value;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user