Create thirdparty on the fly with institution / contact

This commit is contained in:
Julien Fastré 2021-10-11 14:03:46 +02:00
parent 08764aa0b4
commit d7ae279101
3 changed files with 54 additions and 7 deletions

View File

@ -74,7 +74,12 @@ export default {
case 'thirdparty':
let data = this.$refs.castThirdparty.$data.thirdparty;
data.name = data.text;
data.address = { id: data.address.address_id }
if (data.address !== undefined) {
data.address = { id: data.address.address_id }
} else {
data.address = null;
}
return data;
default:
throw Error('Invalid type of entity')

View File

@ -65,6 +65,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\Column(name="kind", type="string", length="20", options={"default":""})
* @Groups({"write"})
*/
private ?string $kind = "";
@ -133,14 +134,14 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
* @Groups({"read"})
*/
private ?ThirdParty $parent;
private ?ThirdParty $parent = null;
/**
* @var Civility
* @ORM\ManyToOne(targetEntity=Civility::class)
* ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true)
*/
private ?Civility $civility;
private ?Civility $civility = null;
/**
* [fr] Qualité
@ -148,7 +149,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession")
* ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true)
*/
private ?ThirdPartyProfession $profession;
private ?ThirdPartyProfession $profession = null;
/**
* @var string|null
@ -463,10 +464,10 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
}
/**
* @param Address $address
* @param Address|null $address
* @return $this
*/
public function setAddress(Address $address)
public function setAddress(?Address $address = null)
{
$this->address = $address;

View File

@ -20,6 +20,20 @@
</div>
<div v-else-if="action === 'edit' || action === 'create'">
<div class="form-floating mb-3">
<div class="form-check">
<input class="form-check-input mt-0" type="radio" v-model="kind" value="company" id="tpartyKindInstitution">
<label for="tpartyKindInstitution" class="required">
{{ $t('tparty.company')}}
</label>
</div>
<div class="form-check">
<input class="form-check-input mt-0" type="radio" v-model="kind" value="contact" id="tpartyKindContact">
<label for="tpartyKindContact" class="required">
{{ $t('tparty.contact')}}
</label>
</div>
</div>
<div class="form-floating mb-3">
<input class="form-control form-control-lg" id="name" v-model="thirdparty.text" v-bind:placeholder="$t('thirdparty.name')" />
<label for="name">{{ $t('thirdparty.name') }}</label>
@ -59,6 +73,17 @@ import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue';
import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress';
import { getThirdparty } from '../../_api/OnTheFly';
const i18n = {
messages: {
fr: {
tparty: {
contact: "Contact",
company: "Institution"
}
}
}
};
export default {
name: "OnTheFlyThirdParty",
props: ['id', 'type', 'action'],
@ -66,11 +91,12 @@ export default {
ThirdPartyRenderBox,
AddAddress
},
i18n,
data() {
return {
//context: {}, <--
thirdparty: {
type: 'thirdparty'
type: 'thirdparty',
},
addAddress: {
options: {
@ -88,6 +114,19 @@ export default {
}
},
computed: {
kind: {
get() {
// note: there are also default to 'institution' set in the "mounted" method
if (this.$data.thirdparty.kind !== undefined) {
return this.$data.thirdparty.kind;
} else {
return 'company';
}
},
set(v) {
this.$data.thirdparty.kind = v;
}
},
context() {
let context = {
target: {
@ -133,6 +172,8 @@ export default {
mounted() {
if (this.action !== 'create') {
this.loadData();
} else {
this.thirdparty.kind = 'company';
}
},
}