auto isBusiness based on customer selected

This commit is contained in:
2026-05-19 12:03:03 +02:00
parent 4e03d52a5d
commit 3f2f55d6c2
2 changed files with 12 additions and 6 deletions

View File

@@ -191,7 +191,6 @@ class OperationFormCubit extends Cubit<OperationFormState> {
// --- GESTIONE DEI CAMPI IN TEMPO REALE --- // --- GESTIONE DEI CAMPI IN TEMPO REALE ---
void updateFields({ void updateFields({
CustomerModel? customer,
String? reference, String? reference,
String? note, String? note,
String? type, String? type,
@@ -224,8 +223,6 @@ class OperationFormCubit extends Cubit<OperationFormState> {
if (quantity != null && quantity > 0) newQuantity = quantity; if (quantity != null && quantity > 0) newQuantity = quantity;
final updated = current.copyWith( final updated = current.copyWith(
customer: customer ?? current.customer,
customerId: customer?.id ?? current.customerId,
reference: reference ?? current.reference, reference: reference ?? current.reference,
note: note ?? current.note, note: note ?? current.note,
providerId: clearProvider ? null : (providerId ?? current.providerId), providerId: clearProvider ? null : (providerId ?? current.providerId),
@@ -254,6 +251,16 @@ class OperationFormCubit extends Cubit<OperationFormState> {
emit(state.copyWith(operation: updated)); emit(state.copyWith(operation: updated));
} }
void updateCustomer(CustomerModel customer) {
final bool isBusiness = customer.isBusiness;
final updatedOperation = state.operation.copyWith(
customer: customer,
customerId: customer.id,
isBusiness: isBusiness,
);
emit(state.copyWith(operation: updatedOperation));
}
// --- UTILS --- // --- UTILS ---
void setTypeWithSmartDefault(String type) { void setTypeWithSmartDefault(String type) {

View File

@@ -387,9 +387,8 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
children: [ children: [
SharedCustomerSection( SharedCustomerSection(
customer: state.operation.customer, customer: state.operation.customer,
onCustomerSelected: (customer) => context onCustomerSelected: (customer) =>
.read<OperationFormCubit>() context.read<OperationFormCubit>().updateCustomer(customer),
.updateFields(customer: customer),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
TextFormField( TextFormField(